materials_commons.cli.file_functions module¶
- materials_commons.cli.file_functions.check_file_selection(path, file_selection)[source]¶
Check if a file or directory is selected in a dataset file selection, and why.
Notes
A file is selected in a dataset’s file selection if it is listed explicitly in “include_files”. It is not selected if it is listed in “exclude_files”. If it is neither explicitly included or excluded, its parent directories are searched up to the project root directory to see if they are included or excluded. If the first parent directory listed is in “include_dirs”, then the file is also selected. If the first parent directory listed is in “exclude_dirs”, or if no parent directory is listed at all, the file is not selected.
- Parameters
path (str) – Materials Commons path of file or directory to check
file_selection (dict) –
A file selection dict. Expected format:
{ "include_files": [... list of file paths ...], "exclude_files": [... list of file paths ...], "include_dirs": [... list of directory paths ...], "exclude_dirs": [... list of directory paths ...] }
- Returns
(selected, selected_by) – selected (bool): True if selected, False if not selected
selected_by (str or None): One of “(self)” if included/excluded explicitly; Else, “<path>”, the path of the first parent directory that is included or excluded; Otherwise, None, to indicate that it is not selected, but neither included nor excluded.
- materials_commons.cli.file_functions.get_by_path_if_exists(client, project_id, file_path)[source]¶
Get file (or directory) by path in project, if it exists. :param int project_id: The id of the project containing the file or directory :param file_path: The Materials Commons path to the file or directory :return: The file or None :rtype File or None
- materials_commons.cli.file_functions.get_parent_id(file_or_dir)[source]¶
Get file_or_dir.directory_id, else raise
- materials_commons.cli.file_functions.make_mcpath(proj_local_path, local_abspath)[source]¶
- Parameters
proj_local_path (str) – Path to project, i.e. “/path/to/project”
local_abspath (str) – Path to file in project, i.e. “/path/to/project/ path/to/file”
- Returns
mcpath (str) –
- Returns a Materials Commons style path, i.e. “/path/to/
file”
- Raises
MCCLIException, if any path in clipaths is not within the local project –
directory. –
- materials_commons.cli.file_functions.path_in_project(proj_local_path, local_abspath)[source]¶
Check if local path is within the local project directory
- Parameters
proj_local_path (str) – Path to project, i.e. “/path/to/project”
local_abspath (str) – Path to file in project, i.e. “/path/to/project/ path/to/file”
Returns: True, if local_abspath is within the local project directory.