cgl.core.utils package¶
Submodules¶
cgl.core.utils.amc_batch_extract_wav module¶
cgl.core.utils.batch_folder_renamer module¶
cgl.core.utils.build module¶
cgl.core.utils.folder_renamer module¶
CLI for renaming folders
cgl.core.utils.general module¶
- exception cgl.core.utils.general.CglExecuteError(message, command=None, returncode=None, stdout=None, stderr=None)[source]¶
Bases:
RuntimeErrorRaised when cgl_execute is misused or the child process fails.
- class cgl.core.utils.general.DateTimeEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶
Bases:
JSONEncoder- default(obj)[source]¶
Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- class cgl.core.utils.general.Logger(name=None, log_file=None, log_level=10)[source]¶
Bases:
object- set_log_level(level)[source]¶
The function sets the log level of a logger object.
- Parameters:
level – The “level” parameter is used to set the logging level for the logger object. The
logging level determines the severity of the messages that will be logged. The available logging levels are:
DEBUG, INFO, WARN, ERROR
- cgl.core.utils.general.app_name(str_=None, human=False)[source]¶
return the name of the application used in settings files :param str_: the name to map from defaults sys.argv[0] :param human: a human-readable string
- Returns:
name of application
- Return type:
str
- cgl.core.utils.general.cgl_clean_dir(dir_path)[source]¶
Removes everything in a directory, including recursively removing all the contents of any subdirectories. :param dir_path:
Returns:
- cgl.core.utils.general.cgl_copy(source, destination, methodology: str = 'local', verbose: bool = False, dest_is_folder: bool = False, test: bool = False, job_name: str = '', wait_to_finish: bool = False)[source]¶
Catch-all for copy operations.
- Behavior:
If source is a sequence (get_file_type(source) == “sequence”), use the existing sequence path (robocopy on win / copy_file_list otherwise).
If source is a list of paths, use copy_file_list.
Otherwise, defer to cgl_copy_single() which already supports both file and directory sources. We ensure dest_is_folder is set whenever either source is a directory or destination is/should be a directory.
- Returns:
run_dict (same shape as before)
- cgl.core.utils.general.cgl_copy_single(source, destination, test=False, verbose=False, dest_is_folder=False, command_name='cgl_copy_single')[source]¶
Lumbermill Copy Function. Built to handle any kind of copy interaction.
- cgl.core.utils.general.cgl_execute(command: Sequence[str] | str, *, return_output: bool = True, print_output: bool = True, verbose: bool = True, command_name: str = 'cgl_execute', new_window: bool = False, detach: bool = False, env: Mapping[str, str] | None = None, timeout: float | None = None, working_directory: str | Path | None = None) dict[str, Any][source]¶
Runs a local process with smart shell detection. Replaces the old _run_blocking/_run_nonblocking pattern.
- cgl.core.utils.general.cgl_move(source, destination, verbose=False)[source]¶
Catch All Move Function. handles files and folders on all platforms
- cgl.core.utils.general.cgl_sync(source_dir: str, dest_dir: str)[source]¶
Sync files from source to destination using robocopy. Only updates files if the source version is newer. Skips identical files.
- cgl.core.utils.general.cgl_sync_file(source_file: str, dest_dir: str)[source]¶
Sync a single file from source to destination folder. Only updates the file if the source version is newer or if it does not exist in the destination.
- cgl.core.utils.general.clean_file_list(file_list)[source]¶
removes items we don’t want to display in the GUI based off what’s listed in the globals.
- Parameters:
file_list
- Returns:
list of files with items removed
- Return type:
clean_list
- cgl.core.utils.general.clean_file_string(file_name)[source]¶
Removes characters we don’t want from a file name
- cgl.core.utils.general.copy_file_list(source_list, destination, methodology, verbose, dest_is_folder)[source]¶
- cgl.core.utils.general.create_file_dirs(file_path)[source]¶
given file_path checks to see if directories exist and creates them if they don’t.
- Parameters:
file_path – path to file you’re about to create.
- cgl.core.utils.general.current_user()[source]¶
find the currently logged-in user :returns: username :rtype: str
- cgl.core.utils.general.ext_exists(folder_path, ext, as_posix=True) list[Path][source]¶
- Parameters:
folder_path – directory to search
ext – extention you’re looking for. expecting a “.ext” but “ext” will likely work too.
- Returns:
list of Path objects that match the extension in the folder_path
- cgl.core.utils.general.fix_json(filepath)[source]¶
Function to fix json file if there’s no newlines
- Parameters:
filepath – Path to json file
- cgl.core.utils.general.get_file_type(filepath) str[source]¶
Returns the file type of the given filepath
- Parameters:
filepath
- Returns:
The file type of the given filepath
- Raises:
KeyError – If the file type is not found in the config file
- cgl.core.utils.general.get_print_list(list_array)[source]¶
Returns a string of a list with commas and an “and” before the last item. :param list_array:
Returns:
- cgl.core.utils.general.get_resource_path(relative_path)[source]¶
Get absolute path to resource, works for PyInstaller and development.
- cgl.core.utils.general.ignore_name(name, ignore_matches, ignore_contains, ignore_endswith, ignore_startswith)[source]¶
Check if a file should be ignored based on the ignore rules
- cgl.core.utils.general.normpath(filepath)[source]¶
returns path with all ‘’ replaced with ‘/’
- Parameters:
filepath
Returns:
- cgl.core.utils.general.pretty(obj)[source]¶
return a pretty printed representation of an object :param obj: the object to pretty print
- Return type:
str
- cgl.core.utils.general.pretty_print_error(e: CglExecuteError)[source]¶
Nicely format a CglExecuteError for logging or console output.
- cgl.core.utils.general.remove_read_only_attribute(file_path)[source]¶
Removes read only attribute from file
- Parameters:
file_path – Absolute file path to file
cgl.core.utils.msd_tools module¶
cgl.core.utils.network module¶
- cgl.core.utils.network.check_for_network_drive_connection(address, drive)[source]¶
Check if network drive is currently mapped to computer :param address: Network location :param drive: Drive that network is mapped to
- Returns:
True if network is found. False is network address is not found
- cgl.core.utils.network.get_all_connected_network_drives(simple=False)[source]¶
Get all network drives mapped on current computer :returns: List of dictionaries for each connected network drive
Example
{ “Y:” : {“local” : “Y:”, “remote” : “10.0.0.100VPShare”}}
- cgl.core.utils.network.get_all_drives()[source]¶
Returns all drives computer is connected to. :returns: List of drives
- cgl.core.utils.network.get_ip_address(external=False)[source]¶
returns the computer’s external ip address.
- Returns:
ip address
- cgl.core.utils.network.get_local_drives()[source]¶
returns all the local drives. (Probably a more elegant way to do this.)
- Returns:
List of local drives
cgl.core.utils.pycharm_setup module¶
cgl.core.utils.read_write module¶
- class cgl.core.utils.read_write.NoAliasDumper(stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True)[source]¶
Bases:
Dumper
- cgl.core.utils.read_write.load_json(filepath)[source]¶
Loads a .json file in as a dictionary
- Parameters:
filepath
- Returns:
dictionary
- Return type:
data
- cgl.core.utils.read_write.load_xml(filepath)[source]¶
loads an xml as a dictionary
- Parameters:
filepath
- Returns:
dictionary
- Return type:
docs
- cgl.core.utils.read_write.load_yaml(filepath)[source]¶
Loads a .yaml file in as a dictionary
- Parameters:
filepath
- Returns:
dictionary
- Return type:
data
- cgl.core.utils.read_write.save_json(filepath, data)[source]¶
Saves a Dictionary as a .json file.
- Parameters:
filepath
data – dictionary
- cgl.core.utils.read_write.save_text_lines(text_array, file_path)[source]¶
this expects to get typical text that would print normally.
- Parameters:
text_array
file_path
- cgl.core.utils.read_write.save_xml(filepath, data)[source]¶
saves a dictionary as an xml file
- Parameters:
filepath
data
- cgl.core.utils.read_write.save_yaml(filepath, data)[source]¶
Saves a Dictionary as a .json file.
- Parameters:
filepath
data – dictionary
- cgl.core.utils.read_write.unzip(zipped_file, destination, password=None)[source]¶
- Parameters:
zipped_file
destination
password
- Returns:
destination path
cgl.core.utils.setup_codacy_coverage module¶
cgl.core.utils.web module¶
- cgl.core.utils.web.download_url(url, destination_file)[source]¶
Downloads the given file from url to destination file path.
- Parameters:
url – url location of a file on the web
destination_file – file to be created