conductor.lib.file_utils module

conductor.lib.file_utils.conform_platform_filepath(filepath)

For the given path, ensure that the path conforms to the standards that Conductor expects. Each platform may potentially have different rules that it follows in order to achieve this.

conductor.lib.file_utils.conform_win_path(filepath)

For the given filepath, resolve any environment variables in the path and convert all backlashes to forward slashes

conductor.lib.file_utils.create_file(filepath, mode=432)

Create an empty file with the given permissions (octal)

conductor.lib.file_utils.get_common_dirpath(paths)

Find the common directory between all of the filepaths (essentially find the lowest common denominator of all of the given paths). If theirs is no common directory shared between the paths, return None

For example, given these three filepaths:

'/home/cat/names/fred.txt'
'/home/cat/names/sally.txt'
'/home/cat/games/chase.txt'

Return '/home/cat'

Exclude the root symbol (“/” or a lettered drive in the case of windows) as a valid common directory.

conductor.lib.file_utils.get_files(dirpath, recurse=True)

Return all files found in the given directory.

Optionally recurse the directory to also include files that are located in subdirectories as well

conductor.lib.file_utils.get_files_from_path_expression(path_expression)

Given a path expression (such as an image sequence path), seek out all files that are part of that path expression (e.g all of the files that are part of that image sequence) and return a list of their explicit paths. This function relies on what is actually on disk, so only files that are found on disk will be returned. If no files are found, return an empty list.

Supports a variety of path expressions. Here are a few examples:

"image.####.exr"   # Hash syntax
"image.####"       # no extension  - if there is no extension for the file then that must be specified by the no_extension argument
"image.%04d.exr"   # printf format
"image<UDIM>.exr   # Udim
"image.$F.exr      # Houdini

In addition to matching against the file name/root, this function also matches expressions found against the directory name/path, e.g.:

/data/shot-###/image.exr
/data/shot-###/image.####.exr
/data/shot-###/image.%04d.exr
/data/shot-###/camera-$F/image.%04d.exr
conductor.lib.file_utils.get_rx_matches(path_expression, expressions, limit=0)

Loop through the given list of expressions (regexes), and return those that match the given path_expression. If a limit is provided, return the first n expressions that match.

conductor.lib.file_utils.get_tx_path(filepath, existing_only=False)

For the given filepath, construct a parallel *.tx filepath residing in the same directory (same name, different extension).

If existing_only is True, only return the tx filepath if it exists on disk, otherwise return an empty string.

conductor.lib.file_utils.get_tx_paths(filepaths, existing_only=False)

Return the tx filepaths for the given filepaths

conductor.lib.file_utils.process_dependencies(paths)

For the given lists of dependency paths, return a dictionary where the keys are the dependency filepaths and the values are paths, and the values are a a string, describing what is wrong with the path (if anything). If the path is valid, the value will be None

conductor.lib.file_utils.process_upload_filepath(path, strict=True)

Process the given path to ensure that the path is valid (exists on disk), and return any/all files which the path may represent.

For example, if the path is a directory or an image sequence, then explicitly list and return all files that that path represents/contains.

Parameters:strict (bool) –

When True and the give path does not exist on disk, raise an exception.

Note that when this function is given a directory path, and and it finds any broken symlinks within the directory, the

This function should be able to handle various types of paths:

  1. Directory path
  2. File path
  3. Image sequence path

Process the path by doing the following:

  1. If the path is an image sequence notation, “explode” it and return each frame’s filepath.

    This relies on the file actually being on disk, as the underlying call is to glob.glob(regex).

    Validate that there is at least one frame on disk for the image sequence. There is no 100% reliable way to know how many frames should actually be part of the image sequence, but we can at least validate that there is a single frame.

  2. If the path is a directory then recursively add all file/dir paths contained within it

  3. If the path is a file then ensure that it exists on disk and that it conforms to Conductor’s expectations.

conductor.lib.file_utils.process_upload_filepaths(paths)

Given the list of paths, process each one, ultimately returning a flattened list of all processed paths

conductor.lib.file_utils.quote_path(filepath)

Wrap the given filepath in double quotes and escape its content.

conductor.lib.file_utils.separate_path(path, no_extension=False)

Separate the given path into three pieces:

  1. The directory (if any)
  2. The base filename (mandatory)
  3. The file extension (if any)

For example, given this path:

"/animals/fuzzy_cat.jpg"

return:

"/animals", "fuzzy_cat", ".jpg"

The path argument may be a full filepath (including the directory) or just the name of the file.

Note that there is no way to know with 100% certainty that if a file name has a period in it that the characters that follow that period are the file extension. By default, this function will assume that all files that are passed into it have a file extension, and the extension is identified by the last period in the file. In cases where a file does not have a file extension, this must be indicated to this function by setting the no_extension argument to be True.

An example that illustrates the issue: A file named “2942_image.10312”. The “10312” could either represent a frame number or an extension. There is no way to know for sure. By default, the function will assume that the “10312” is an extension. Override this behavior by setting the no_extension arg to True.

conductor.lib.file_utils.strip_drive_letter(filepath)

If the given filepath has a drive letter, remove it and return the rest of the path:

C:\cat.txt         -->    \cat.txt
Z:\cat.txt         -->    \cat.txt
c:/cat.txt         -->    /cat.txt
z:/cat.txt         -->    /cat.txt
//cat.txt          -->    //cat.txt
\cat.txt           -->    \cat.txt
\cat\c:\dog.txt   -->    \cat\c:\dog.txt
/cat/c:/dog.txt    -->    /cat/c:/dog.txt
c:\cat\z:\dog.txt  -->    \cat\z:\dog.txt

Note that os.path.splitdrive should not be used (anymore), due to a change in behavior that was implemented somewhere between Python 2.7.6 vs 2.7.11

conductor.lib.file_utils.validate_path(filepath)

Validate that the given filepath:

  1. Does not contain colons. This is docker path limitation
  2. Starts with a “/”. Otherwise the path cannot be mounted in a Linux filesystem

If the filepath is valid, return None. Otherwise return a message that describes why the filepath is invalid.