Skip to content

fxfiles

FXProjectTemplate

A class representing an FX project template.

Attributes:

Name Type Description
name str

The name of the project.

root str

The root directory of the project.

info dict

The project information.

__str__

__str__() -> str

Returns a string representation of the FX project template.

Returns:

Name Type Description
str str

The string representation of the FX project template.

from_json classmethod

from_json(json_data: dict) -> FXProjectTemplate

Creates an FXProjectTemplate instance from a JSON object.

Parameters:

Name Type Description Default
json_data dict

The JSON data containing the project template information.

required

Returns:

Name Type Description
FXProjectTemplate FXProjectTemplate

The FXProjectTemplate instance created from the JSON data.

Examples:

>>> project_info = json.loads(
>>>     Path.joinpath(
>>>         Path("C:/path/to/project"), f"projectname_info.json"
>>>     ).read_text()
>>> )
>>> project = FXProjectTemplate.from_json(project_info)

from_string classmethod

from_string(input_string: str) -> FXProjectTemplate

Creates an FXProjectTemplate instance from a string.

Parameters:

Name Type Description Default
input_string str

The string containing information to create the

required

Returns:

Name Type Description
FXProjectTemplate FXProjectTemplate

The FXProjectTemplate instance created from the input string.

Examples:

>>> project = FXProjectTemplate.from_string("C:/path/to/project")
>>> print(project.name, project.root)
"Project Name", "C:/path/to/project"

FXWorkfileTemplate

A class representing an FX workfile template.

Attributes:

Name Type Description
sequence str

The sequence number.

shot str

The shot number.

step str

The step in the FX workflow.

task str

The task associated with the workfile.

version str

The version number.

__str__

__str__() -> str

Returns a string representation of the FX workfile template.

Returns:

Name Type Description
str str

The string representation of the FX workfile template.

from_string classmethod

from_string(input_string: str, return_int: bool = True) -> FXWorkfileTemplate

Creates an FXWorkfileTemplate instance from a string.

Parameters:

Name Type Description Default
input_string str

The string containing information to create the

required
return_int bool

If True, returns the sequence, shot and version as integers.

True

Returns:

Name Type Description
FXWorkfileTemplate FXWorkfileTemplate

The FXWorkfileTemplate instance created from the input string.

Raises:

Type Description
ValueError

If the input string format is invalid.

Examples:

>>> workfile = FXWorkfileTemplate.from_string("000_0020_LGT_main_v001")
>>> print(workfile.sequence, workfile.shot)
"000", "0020"

generate_filename

generate_filename() -> str

Generates a filename based on the attributes of the FX workfile template.

Returns:

Name Type Description
str str

The generated filename.

create_child_from_dict

create_child_from_dict(child_dict: dict, parent_dir: str) -> None

Recursively creates child folders and files based on the provided dict structure.

Parameters:

Name Type Description Default
child_dict dict

The dictionary containing the child structure.

required
parent_dir str

The parent directory where the child will be created.

required

create_structure_from_dict

create_structure_from_dict(structure_dict: dict, base_dir: str = '.') -> None

Creates the directory structure based on the provided dict structure.

Parameters:

Name Type Description Default
structure_dict dict

The dictionary containing the structure.

required
base_dir str

The base directory where the structure will be created.

'.'

extract_version_integer_value

extract_version_integer_value(string: str) -> Optional[int]

Extracts the integer value from a string in the format "vXXX".

Parameters:

Name Type Description Default
string str

The input string containing the value in the format "vXXX".

required

Returns:

Name Type Description
int Optional[int]

The integer value extracted from the input string.

Examples:

>>> extract_version_integer_value("v001")
1
>>> extract_version_integer_value("abc123")
None

find_version_in_filename

find_version_in_filename(
    filename: str, as_string: bool = False
) -> Optional[str]

Finds the version number in a filename.

Parameters:

Name Type Description Default
filename str

The filename to search for the version number.

required
as_string bool

If True, returns the version number as a string with the 'v' prefix. Defaults to False.

False

Returns:

Type Description
Optional[str]

Optional[str]: The version number found in the filename, if any.

get_all_metadata

get_all_metadata(file_path: str) -> Dict[str, Optional[str]]

Retrieve all metadata for a file or directory.

Parameters:

Name Type Description Default
file_path str

Path to the file or directory to retrieve metadata from.

required

Returns:

Type Description
Dict[str, Optional[str]]

Dictionary of all metadata names and their values. If a metadata entry

Dict[str, Optional[str]]

is not found, its value is None.

get_metadata_type

get_metadata_type(metadata_name: str, metadata_value: str) -> type

Determines the data type of a metadata value.

Parameters:

Name Type Description Default
metadata_name str

The name of the metadata entry. This is mostly used for special cases where the type can be determined based on the name only.

required
metadata_value str

The metadata value to determine the type of.

required

Returns:

Name Type Description
type type

The data type of the metadata value. Returns str if the type cannot be determined.

get_multiple_metadata

get_multiple_metadata(
    file_path: str, metadata_names: List[str]
) -> Dict[str, Optional[str]]

Retrieve multiple metadata entries for a file.

Parameters:

Name Type Description Default
file_path str

Path to the file.

required
metadata_names List[str]

List of metadata names to retrieve.

required

Returns:

Type Description
Dict[str, Optional[str]]

Dictionary of metadata names and their values. If a metadata entry is

Dict[str, Optional[str]]

not found, its value is None.

get_next_version

get_next_version(
    path: str, as_string: bool = False, return_highest: bool = False
) -> Union[int, str]

Determines the next version number based on the existing versioned files in the given directory.

This function scans the specified directory for files with version numbers at the end of their names, in the format _vNNN where N is a digit. It identifies the highest version number currently present and returns the next version number, incremented by one.

Parameters:

Name Type Description Default
path str

The path to the directory containing the versioned files.

required
as_string bool

If True, returns the next version number as a string with the 'v' prefix. Defaults to False.

False
return_highest bool

If True, returns the highest version number found in the directory. Defaults to False.

False

Returns:

Type Description
Union[int, str]

Union[int, str]: The next version number to be used, incremented by one from the highest existing version. Returns 1 if no versioned files are found.

Examples:

>>> get_next_version("/path/to/your/directory")
4
>>> get_next_version("/path/to/your/directory", as_string=True)
"v004"

path_to_unix

path_to_unix(path: str) -> str

Replaces backward slashes with forward slashes (Unix format) in a given path.

Parameters:

Name Type Description Default
path str

The input path containing backward slashes.

required

Returns:

Name Type Description
str str

The path with all backward slashes replaced by forward slashes.

Examples:

>>> path_to_unix("C:\Users\User\Documents")
"C:/Users/User/Documents"

replace_placeholders_in_dict

replace_placeholders_in_dict(data: Dict, replacements: Dict) -> Dict

Recursively replaces placeholders in a dictionary with values from another dictionary.

Parameters:

Name Type Description Default
data Dict

The dictionary to process.

required
replacements Dict

The dictionary containing placeholder-replacement pairs.

required

Returns:

Name Type Description
Dict Dict

The dictionary with placeholders replaced by values.

replace_placeholders_in_string

replace_placeholders_in_string(s: str, replacements: Dict) -> str

Replaces placeholders in a string with values from a dictionary.

Note

Placeholders are in the format $placeholder$.

Parameters:

Name Type Description Default
s str

The string to process.

required
replacements Dict

The dictionary containing placeholder-replacement pairs.

required

Returns:

Name Type Description
str str

The string with placeholders replaced by values.

set_multiple_metadata

set_multiple_metadata(file_path: str, metadata: Dict[str, str]) -> None

Set multiple metadata entries for a file.

Parameters:

Name Type Description Default
file_path str

Path to the file.

required
metadata Dict[str, str]

Dictionary of metadata names and values to set.

required