Source code for aiida_amber.utils.node_utils

"""Methods for dealing with various types of files and
directories that are used in processes and add them to aiida nodes"""

import os
import re

from aiida.orm import FolderData






[docs] def check_filepath(input_files: list): """Check if an input is a file or a path. :param input_files: The list of inputs to check :returns: List of files and list of subdirs """ subdirs = [] files = [] # Iterate all found files and check if they are in subdirs. for i in input_files: # paths containing dirs will have slashes in them, # otherwise they will be files if "/" in i: subdirs.append(i) else: files.append(i) return subdirs, files
[docs] def add_subdir_to_node(dict_info, subdir): """Add a subdir to a node.""" # Create a folder that is empty. if subdir.split("/")[0] not in dict_info.keys(): dict_info[subdir.split("/")[0]] = FolderData() # Now fill it with subdir and file. dict_info[subdir.split("/")[0]].put_object_from_file( os.path.join(os.getcwd(), subdir), path=subdir.split("/")[-1] ) return dict_info