Tools and cTools¶
A set of helper classes that provide the framework with additional tools that otherwise would require writing repetitive code. Some functions have been ported to C++ to exploit faster multi-threading operations, these will be separately highlighted.
- class Tools¶
- lsFiles(str directory, extension = None) list[str]¶
A method which returns the file structure of a given path.
- Parameters:
directory (str) – The absolute/relative path to search in.
extension (str, None) – Only return files in the specified directory if it matches the given file extension.
- ls(str directory) list[str]¶
A method which only returns the specified directory structure (does not search recursively or care about file extensions).
- Parameters:
directory (str) – The absolute/relative path to search in.
- IsPath(str directory) bool¶
Checks whether the given directory is a path or if it exists.
- Parameters:
directory (str) – The absolute/relative path to check.
- IsFile(str directory, bool quiet) bool¶
Checks whether the given directory is a file or if it exists.
- Parameters:
directory (str) – The absolute/relative path to check.
quiet (bool) – Disables/Enables any alerting of running the method.
- ListFilesInDir(str directory, str extension) list[str]¶
Recursively checks the given path for files with the given extension.
- Parameters:
directory (str) – The absolute/relative path to check.
extension (str) – The file extension to search the path for.
- pwd() str¶
Returns current working directory.
- abs(str directory) str¶
Converts a relative directory string to an absolute path.
- Parameters:
directory (str) – A relative directory path string.
- path(str directory) str¶
Converts the input to a path string.
- Parameters:
directory (str) – The absolute/relative path to convert into a path string.
- filename(str directory) str¶
Extracts the filename of the input string.
- Parameters:
directory (str) – The directory/input to convert.
- mkdir(str directory)¶
Creates the given path in the file-system. If the output is a nested directory structure, the entire path structure if will be created.
- Parameters:
directory (str) – The directory path to create on the file-system.
- rm(str directory)¶
Deletes the the specified directory, regardless of the contents!
- Parameters:
directory (str) – The directory path to delete from the file-system.
- cd(str directory) str¶
The directory that the Python interpreter should change to.
- Parameters:
directory (str) – The directory path string.
- MergeListsInDict(dict inpt) list¶
Recursively merges lists within the input dictionary, without preserving the keys or dictionary path.
- Parameters:
inpt (dict) – A dictionary with lists values.
- DictToList(dict inpt) list¶
Aims to recrusively merge dictionary content but saves the keys string path, if the input dictionary is nested.
- Parameters:
inpt (dict) – The dictionary to merge into a list.
- Quantize(list inpt, int size) list[list]¶
Splits the input list into a nested list, with the nested lists being of specified size.
- Parameters:
inpt (list) – A list of values to split.
size (int) – The size of each element within the nested list.
- MergeNestedList(list[list] inpt) list¶
Does the opposite of Quantize. Given a nested list, the method will attempt to rebuild a continuous single dimensional list.
- Parameters:
inpt (list[list]) – A nested list of list to convert.
- MergeData(ob1, ob2) type of ob1 or ob2¶
A more abstract merging method. It aims to merge two input data types (list, dict, int, float), into a single entity. A simple example would be, if two inputs are dictionaries and each contains different keys, the method will merge the two dictionaries into a single dictionary. For a more complex case, consider two dictionaries with mutual keys, but nested lists as values. In such cases, the method will output a single dictionary but the list structure will be preserved, and the contents merged.
- Parameters:
ob1 (list, dict, int, float) – The first type to merge.
ob2 (list, dict, int, float) – The second type to merge.
- class cTools(import via AnalysisG._cmodules.ctools import CTools)¶
- csplit(str val, str delimiter) list¶
Splits a given string by the given delimiter. This method is interfaced with C++ using Cython.
- Parameters:
val (str) – The string to split.
delimiter (str) – A sub-string key to split the input by.
- chash(str inpt) str¶
Returns a hash of the input string.
- Parameters:
inpt (str) – The string to compute the hash for.
- cQuantize(list v, int size) list[list]¶
Does the same as Quantize, but much faster.
- Parameters:
v (list) – The target list to split.
size (int) – The size of each element within the nested output list.
- cCheckDifference(list inpt1, list inpt2, int threads) list¶
Returns a list of differernces between inpt1 and inpt2, using n-CPU threads.
- Parameters:
inpt1 (list) – The first list to scan relative to the second list.
inpt2 (list) – The source list to scan against.
threads (int) – The number of threads to utilize during the scanning (particularly helpful for large string lists).