tools package¶
Submodules¶
tools.file_utils module¶
Tools to work with files
-
tools.file_utils.
check_argument
(path: pathlib.Path, argument: str, optional: bool, module_name: str, input_output: str = None, output_files_created: bool = False, extension_list: List[str] = None, raise_exception: bool = True, check_extensions: bool = True, out_log: logging.Logger = None) → None[source]¶
-
tools.file_utils.
check_properties
(obj: object, properties: dict, reserved_properties: dict = None)[source]¶
-
tools.file_utils.
copy_to_container
(container_path: str, container_volume_path: str, io_dict: Mapping[KT, VT_co], out_log: logging.Logger = None) → dict[source]¶
-
tools.file_utils.
create_cmd_line
(cmd: Iterable[str], container_path: str = '', host_volume: str = None, container_volume: str = None, container_working_dir: str = None, container_user_uid: str = None, container_shell_path: str = None, container_image: str = None, out_log: logging.Logger = None, global_log: logging.Logger = None) → List[str][source]¶
-
tools.file_utils.
create_dir
(dir_path: str) → str[source]¶ Returns the directory dir_path and create it if path does not exist.
Parameters: dir_path (str) – Path to the directory that will be created. Returns: Directory dir path. Return type: str
-
tools.file_utils.
create_name
(path: str = None, prefix: str = None, step: str = None, name: str = None) → str[source]¶ Return file name.
Parameters: - path (str) – Path to the file directory.
- prefix (str) – Prefix added to the name of the file.
- step (str) – String added between the prefix arg and the name arg of the file.
- name (str) – Name of the file.
Returns: Composed file name.
Return type: str
-
tools.file_utils.
create_unique_dir
(path: str = '', prefix: str = '', number_attempts: int = 10, out_log: logging.Logger = None) → str[source]¶ Create a directory with a prefix + computed unique name. If the computed name collides with an existing file name it attemps number_attempts times to create another unique id and create the directory with the new name.
Parameters: - path (str) – (‘’) Parent path of the new directory.
- prefix (str) – (‘’) String to be added before the computed unique dir name.
- number_attempts (int) –
- number of times creating the directory if there’s a name conflict.
- out_log (logger) – (None) Python logger object.
Returns: Directory dir path.
Return type: str
-
tools.file_utils.
create_unique_file_path
(parent_dir: str = None, extension: str = None) → str[source]¶
-
tools.file_utils.
get_logs
(path: str = None, prefix: str = None, step: str = None, can_write_console: bool = True, level: str = 'INFO', light_format: bool = False) → Tuple[logging.Logger, logging.Logger][source]¶ Get the error and and out Python Logger objects.
Parameters: - path (str) – (current working directory) Path to the log file directory.
- prefix (str) – Prefix added to the name of the log file.
- step (str) – String added between the prefix arg and the name of the log file.
- can_write_console (bool) – (False) If True, show log in the execution terminal.
- level (str) – (‘INFO’) Set Logging level. [‘CRITICAL’,’ERROR’,’WARNING’,’INFO’,’DEBUG’,’NOTSET’]
- light_format (bool) – (False) Minimalist log format.
Returns: Out and err Logger objects.
Return type: tuple
oflogging.Logger
andlogging.Logger
-
tools.file_utils.
get_working_dir_path
(working_dir_path: str = None, restart: bool = False) → str[source]¶ Return the directory working_dir_path and create it if working_dir_path does not exist. If working_dir_path exists a consecutive numerical suffix is added to the end of the working_dir_path and is returned.
Parameters: - working_dir_path (str) – Path to the workflow results.
- restart (bool) – If step result exists do not execute the step again.
Returns: Path to the workflow results directory.
Return type: str
-
tools.file_utils.
human_readable_time
(time_ps: int) → str[source]¶ Transform time_ps to a human readable string.
Parameters: time_ps (int) – Time in pico seconds. Returns: Human readable time. Return type: str
-
tools.file_utils.
log
(string: str, local_log: logging.Logger = None, global_log: logging.Logger = None)[source]¶ Checks if log exists
Parameters: - string (str) – Message to log.
- local_log (
logging.Logger
) – local log object. - global_log (
logging.Logger
) – global log object.
-
tools.file_utils.
rm_file_list
(file_list: Iterable[str], out_log: logging.Logger = None) → List[str][source]¶
-
tools.file_utils.
search_topology_files
(top_file: str, out_log: logging.Logger = None) → List[str][source]¶ Search the top and itp files to create a list of the topology files
Parameters: - top_file (str) – Topology GROMACS top file.
- out_log (
logging.Logger
) – Input log object.
Returns: List of paths of the extracted files.
Return type: list
ofstr
-
tools.file_utils.
unzip_list
(zip_file: str, dest_dir: str = None, out_log: logging.Logger = None) → List[str][source]¶ - Extract all files in the zipball file and return a list containing the
- absolute path of the extracted files.
Parameters: - zip_file (str) – Input compressed zip file.
- dest_dir (str) – Path to directory where the files will be extracted.
- out_log (
logging.Logger
) – Input log object.
Returns: List of paths of the extracted files.
Return type: list
ofstr
-
tools.file_utils.
unzip_top
(zip_file: str, out_log: logging.Logger = None, unique_dir: Union[pathlib.Path, str] = None) → str[source]¶ Extract all files in the zip_file and copy the file extracted “.top” file to top_file.
Parameters: - zip_file (str) – Input topology zipball file path.
- out_log (
logging.Logger
) – Input log object. - unique_dir (str) – Directory where the topology will be extracted.
Returns: Path to the extracted “.top” file.
Return type: str
-
tools.file_utils.
zip_list
(zip_file: str, file_list: Iterable[str], out_log: logging.Logger = None)[source]¶ Compress all files listed in file_list into zip_file zip file.
Parameters: - zip_file (str) – Output compressed zip file.
- file_list (
list
ofstr
) – Input list of files to be compressed. - out_log (
logging.Logger
) – Input log object.
-
tools.file_utils.
zip_top
(zip_file: str, top_file: str, out_log: logging.Logger = None, remove_original_files: bool = True) → List[str][source]¶ Compress all .itp and *.top files in the cwd into **zip_file* zip file.
Parameters: - zip_file (str) – Output compressed zip file.
- top_file (str) – Topology TOP GROMACS file.
- out_log (
logging.Logger
) – Input log object.
Returns: List of compressed paths.
Return type: list
ofstr
tools.test_fixtures module¶
Boiler plate functions for testsys
-
tools.test_fixtures.
compare_hash
(file_a: str, file_b: str) → bool[source]¶ Compute and compare the hashes of two files
-
tools.test_fixtures.
compare_ignore_first
(file_a: str, file_b: str) → bool[source]¶ Compare two files ignoring the first line
-
tools.test_fixtures.
compare_line_by_line
(file_a: str, file_b: str, ignore_list: List[Union[str, int]]) → bool[source]¶
-
tools.test_fixtures.
compare_pdb
(pdb_a: str, pdb_b: str, rmsd_cutoff: int = 1, remove_hetatm: bool = True, remove_hydrogen: bool = True, **kwargs)[source]¶ Compare pdb files
-
tools.test_fixtures.
equal
(file_a: str, file_b: str, ignore_list: List[Union[str, int]] = None, **kwargs) → bool[source]¶ Check if two files are equal
-
tools.test_fixtures.
equal_txt
(file_a: str, file_b: str) → bool[source]¶ Check if two text files are equal
-
tools.test_fixtures.
exe_success
(return_code: int) → bool[source]¶ Check if return_code is 0
Parameters: return_code (int) – Return code of a process. Returns: True if return code is equal to 0 Return type: bool
-
tools.test_fixtures.
not_empty
(file_path: str) → bool[source]¶ Check if file exists and is not empty.
Parameters: file_path (str) – Path to the file. Returns: True if file_path exists and is not empty. Return type: bool
-
tools.test_fixtures.
test_setup
(test_object: object, dict_key: str = None, config: str = None)[source]¶ Add the unitest_dir, test_dir, conf_file_path, system, properties and path as attributes to the test_object and create a directory to launch the unitest.
Parameters: - test_object (
test
) – The test object. - dict_key (str) – Key of the test parameters in the yaml config file.
- config (str) – Path to the configuration file.
- test_object (