vtool.util_file

Class Summary

ProcessLog(path)

VersionFile(filepath)

Convenience to version a file or folder.

SettingsFile()

ControlNameFromSettingsFile([directory])

FindUniquePath(directory)

ReadCache()

Function Summary

get_permission(filepath)

get_vetala_version()

get_vetala_directory()

get_current_vetala_process_path()

clear_settings_cache()

get_basename(directory)

Get the last part of a directory name.

get_basename_no_extension(filepath)

Get the last part of a directory name.

get_dirname(directory)

Given a directory path, this will return the path above the last thing in the path.

get_root_dir()

get_user_dir()

Get the path to the user directory.

get_temp_dir()

Get path to the temp directory.

get_cwd()

Get the current working directory.

get_files(directory[, filter_text])

Get files found in the directory.

get_all_paths(root_dir)

get_all_rel_paths(root_dir)

get_code_folders(directory[, recursive, ...])

get_folders_without_prefix_dot(directory[, ...])

get_folders(directory[, recursive, ...])

Get folders found in the directory.

get_files_and_folders(directory)

Get files and folders found in the directory.

get_folders_date_sorted(directory)

Get folders date sorted found in the directory.

get_files_date_sorted(directory[, ...])

Get files date sorted found in the directory.

get_latest_file_at_path(path[, filter_text])

get_latest_file(file_paths[, ...])

get_files_with_extension(extension, directory)

Get files that have the extensions.

get_size(path[, round_value])

get_filesize(filepath[, round_value])

Get the size of a file.

get_folder_size(path[, round_value, skip_names])

skip_names will skip folders and files that have the same name specified in skip_names list.

format_date_time(python_date_time_value[, ...])

get_date()

get_date_and_time([separators])

get_last_modified_date(filepath)

Get the last date a file was modified.

get_user()

Get the current user.

get_file_text(filepath)

Get the text directly from a file.

get_text_lines(text)

get_file_lines(filepath)

Get the text from a file.

set_json(filepath, data[, append, sort_keys])

get_json(filepath)

exists(directory[, case_sensitive])

is_dir(directory[, case_sensitive])

returns

bool

is_file(filepath)

returns

bool

is_file_in_dir(filename, directory)

param filename

Filename including path.

is_same_date(file1, file2)

Check if 2 files have the same date.

is_same_text_content(file1, file2)

inc_path_name(directory[, padding])

Add padding to a name if it is not unique.

remove_extension(path)

get_common_path(path1, path2)

remove_common_path(path1, path2)

Given path1 = pathA/pathB and path2 = pathA/pathC

remove_common_path_simple(path1, path2)

This just subtracts a string that is the same at the beginning.

get_comments(comment_directory[, ...])

Get the comments from a comments.txt file.

get_default_directory()

get_vetala_settings_inst()

fix_slashes(directory)

Fix slashes in a path so they are all /

set_windows_slashes(directory)

Set all the slashes in a name, so they are all :param directory: The directory that one wants to convert to use windows slashes.

join_path(directory1, directory2)

Append directory2 to the end of directory1

rename(directory, name[, make_unique])

param directory

Full path to the directory to rename.

move(path1, path2)

Move the folder or file pointed to by path1 under the directory path2

write_lines(filepath, lines[, append])

Write a list of text lines to a file.

write_replace(filepath, stuff_to_write)

create_dir(name[, directory, make_unique])

param name

The name of the new directory.

delete_dir(name[, directory])

Delete the folder by name in the directory.

delete_read_only_error(action, name, exc)

Helper to delete read only files.

refresh_dir(directory[, delete_directory])

Delete everything in the directory.

create_file(name[, directory, make_unique])

param name

The name of the new file.

remove(name[, directory])

Remove a file or folder

delete_file(name[, directory, show_warning])

Delete the file by name in the directory.

copy_with_subprocess(cmd)

fast_copy(directory, directory_destination)

copy_dir(directory, directory_destination[, ...])

Copy the directory to a new directory.

copy_file(filepath, filepath_destination)

Copy the file to a new directory.

delete_versions(folder[, keep])

is_pyc_outdated(py_file)

delete_pyc(python_script)

Delete the .pyc file the corresponds to the .py file

remove_sourced_code(code_directory)

remove_modules_at_path(path)

source_python_module(code_directory)

load_python_module(module_name, directory)

Load a module by name and return its instance.

run_python_module(script_path)

get_module_variables(module)

get_package_children(path)

get_package_path_from_name(module_name[, ...])

get_line_imports(lines)

This needs to be replaced by AST stuff.

get_defined(module_path[, name_only])

Get classes and definitions from the text of a module.

get_defined_classes(module_path)

get_ast_function_name_and_args(function_node)

get_ast_function_args(function_node)

get_ast_class_sub_functions(module_path, ...)

get_ast_class_members(class_node[, parents, ...])

get_ast_assignment(text, line_number, assignment)

open_browser(filepath)

Open the file browser to the path specified.

open_website(url)

get_maya_path()

get_mayapy()

get_mayabatch()

get_process_batch_file()

get_process_deadline_file()

maya_batch_python_file(python_file_path)

launch_maya(version[, script])

Needs maya installed.

launch_nuke(version[, command])

Needs nuke installed.

run_ffmpeg()

Needs ffmpeg installed.

has_deadline()

get_deadline_command_from_settings()

get_permission(filepath)
get_vetala_version()
get_vetala_directory()
get_current_vetala_process_path()
class ProcessLog(path)
record_temp_log(name, value)
end_temp_log()
class VersionFile(filepath)

Convenience to version a file or folder.

Parameters

filepath (str) – The path to the file to version.

save_comment(comment=None, version_file=None)

Save a comment to a log file.

Parameters
  • comment (str) –

  • version_file (str) – The corresponding version file.

save(comment=None)

Save a version.

Parameters

comment (str) – The comment to add to the version.

Returns

The new version file name

Return type

str

save_default()
has_default()
has_versions()
get_count()
set_version_folder(folder_path)

Set the folder where the version folder should be created.

Parameters

folder_path (str) – Full path to where the version folder should be created.

set_version_folder_name(name)

Set the name of the version folder.

Parameters

name (str) –

set_version_name(name)

Set the version name.

Parameters

name (str) – The name of the version.

get_version_path(version_int)

Get the path to a version.

Parameters

version_int (int) – The version number.

Returns

The path to the version.

Return type

str

get_version_comment(version_int)

Get the version comment.

Parameters

version_int (int) – The version number.

Returns

The version comment.

Return type

str

get_organized_version_data()
Returns

version, comment, user, file_size, modified, version_file

get_version_data(version_int)

Get the version data. Comment and user.

Parameters

version_int (int) – The version number.

Returns

(comment, user)

Return type

tuple

get_version_numbers()
get_versions(return_version_numbers_also=False)

Get filepaths of all versions.

Returns

List of version filepaths.

Return type

list

get_latest_version()

Get the filepath to the latest version.

Returns

Filepath to latest version.

Return type

str

get_default()
delete_version(version_number)
class SettingsFile
set(name, value)
get(name)
has_setting(name)
has_setting_match(name)
has_settings()
get_settings()
get_file()
clear()
reload()
set_directory(directory, filename='settings.json')
class ControlNameFromSettingsFile(directory=None)
set_directory(directory, filename='settings.json')
set(name, value)
CONTROL_ALIAS = 'Control Alias'
DESCRIPTION = 'Description'
NUMBER = 'Number'
SIDE = 'Side'
get_name(description, side=None)
set_center_alias(alias)
set_control_alias(alias)
set_control_order(list_value)
set_left_alias(alias)
set_number_in_control_name(bool_value)
set_right_alias(alias)
set_uppercase(bool_value)
set_use_side_alias(bool_value)
class FindUniquePath(directory)
get()
set_padding(int_value)
class ReadCache
read_files = {}
classmethod is_read(path)
classmethod set_read_data(path, data)
classmethod remove_read_data(path)
classmethod cache_read_data(path)
clear_settings_cache()
get_basename(directory)

Get the last part of a directory name. If the name is C:/goo/foo, this will return foo.

Parameters

directory (str) – A directory path.

Returns

The last part of the directory path.

Return type

str

get_basename_no_extension(filepath)

Get the last part of a directory name. If the name is C:/goo/foo.py, this will return foo.

Parameters

filepath (str) – A directory path.

Returns

The last part of the directory path, without any extensions.

Return type

str

get_dirname(directory)

Given a directory path, this will return the path above the last thing in the path. If C:/goo/foo is give, C:/goo will be returned.

Parameters

directory (str) – A directory path.

Returns

The front portion of the path.

Return type

str

get_root_dir()
get_user_dir()

Get the path to the user directory.

Returns

The path to the user directory.

Return type

str

get_temp_dir()

Get path to the temp directory.

Returns

The path to the temp directory.

Return type

str

get_cwd()

Get the current working directory.

Returns

The path to the current working directory.

Return type

str

get_files(directory, filter_text='')

Get files found in the directory.

Parameters
  • directory (str) – A directory path.

  • filter_text (str) – TODO: Add description.

Returns

A list of files in the directory.

Return type

list

get_all_paths(root_dir)
get_all_rel_paths(root_dir)
get_code_folders(directory, recursive=False, base_directory=None)
get_folders_without_prefix_dot(directory, recursive=False, base_directory=None)
get_folders(directory, recursive=False, filter_text='', skip_dot_prefix=False)

Get folders found in the directory.

Parameters
  • directory (str) – A directory path.

  • recursive (bool) – TODO: Fill in description.

  • filter_text (str) – TODO: Fill in description.

  • skip_dot_prefix (bool) – TODO: Fill in description.

Returns

A list of folders in the directory.

Return type

list

get_files_and_folders(directory)

Get files and folders found in the directory.

Parameters

directory (str) – A directory path.

Returns

A list of files and folders in the directory.

Return type

list

get_folders_date_sorted(directory)

Get folders date sorted found in the directory.

Parameters

directory (str) – A directory path.

Returns

A list of folders date sorted in the directory.

Return type

list

get_files_date_sorted(directory, extension=None, filter_text='')

Get files date sorted found in the directory.

Parameters
  • directory (str) – A directory path.

  • extension (str) – TODO: Fill in description.

  • filter_text (str) – TODO: Fill in description.

Returns

A list of files date sorted in the directory.

Return type

list

get_latest_file_at_path(path, filter_text='')
get_latest_file(file_paths, only_return_one_match=True)
get_files_with_extension(extension, directory, fullpath=False, filter_text='')

Get files that have the extensions.

Parameters
  • extension (str) – e.g. .py, .data, etc.

  • directory (str) – A directory path.

  • fullpath (bool) – Whether to return the filepath or just the file names.

  • filter_text (str) – TODO: Fill in description.

Returns

A list of files with the extension.

Return type

list

get_size(path, round_value=2)
get_filesize(filepath, round_value=2)

Get the size of a file.

Parameters
  • filepath (str) – TODO: Fill in description.

  • round_value (int) – TODO: Fill in description.

Return

float: The size of the file specified by filepath.

get_folder_size(path, round_value=2, skip_names=None)

skip_names will skip folders and files that have the same name specified in skip_names list.

format_date_time(python_date_time_value, separators=True)
get_date()
get_date_and_time(separators=True)
get_last_modified_date(filepath)

Get the last date a file was modified.

Parameters

filepath (str) –

Returns

A formatted date and time.

Return type

str

get_user()

Get the current user.

Returns

The name of the current user.

Return type

str

get_file_text(filepath)

Get the text directly from a file. One long string, no parsing.

get_text_lines(text)
get_file_lines(filepath)

Get the text from a file. Each line is stored as a different entry in a list.

Parameters

filepath (str) – TODO: Fill in description.

Returns

list

set_json(filepath, data, append=False, sort_keys=True)
get_json(filepath)
exists(directory, case_sensitive=False)
is_dir(directory, case_sensitive=False)
Returns

bool

is_file(filepath)
Returns

bool

is_file_in_dir(filename, directory)
Parameters
  • filename (str) – Filename including path.

  • directory (str) – Directory name including path.

Returns

Whether the file is in the directory.

Return type

bool

is_same_date(file1, file2)

Check if 2 files have the same date.

Parameters
  • file1 (str) – Filename including path.

  • file2 (str) – Filename including path.

Returns

bool

is_same_text_content(file1, file2)
inc_path_name(directory, padding=0)

Add padding to a name if it is not unique.

Parameters
  • directory (str) – Directory name including path.

  • padding (int) – Where the padding should start.

Returns

The new directory with path.

Return type

str

remove_extension(path)
get_common_path(path1, path2)
remove_common_path(path1, path2)

Given path1 = pathA/pathB and path2 = pathA/pathC

or path1 = pathA and path2 = pathA/pathC

return pathC

remove_common_path_simple(path1, path2)

This just subtracts a string that is the same at the beginning. path1 gets subtracted from path2

get_comments(comment_directory, comment_filename=None)

Get the comments from a comments.txt file.

Parameters
  • comment_directory (str) – Directory where the comments.txt file lives.

  • comment_filename (str) – The name of the comment file. By default, comments.txt

Returns

comment dict, keys are filename, and value is (comment, user)

Return type

dict

get_default_directory()
get_vetala_settings_inst()
fix_slashes(directory)

Fix slashes in a path so they are all /

Parameters

directory (str) – path that one wants to fix slashes on.

Returns

The new directory path.

Return type

str

set_windows_slashes(directory)

Set all the slashes in a name, so they are all :param directory: The directory that one wants to convert to use windows slashes. :type directory: str

Returns

The new directory path.

Return type

str

join_path(directory1, directory2)

Append directory2 to the end of directory1

Returns

The combined directory path.

Return type

str

rename(directory, name, make_unique=False)
Parameters
  • directory (str) – Full path to the directory to rename.

  • name (str) – The new name.

  • make_unique (bool) – Whether to add a number to the name to make it unique, if needed.

Return

str: The path of the renamed folder, or False if rename fails.

move(path1, path2)

Move the folder or file pointed to by path1 under the directory path2

Parameters
  • path1 (str) – File or folder including path.

  • path2 (str) – Path where path1 should move to.

Returns

Whether the move was successful.

Return type

bool

write_lines(filepath, lines, append=False)

Write a list of text lines to a file. Every entry in the list is a new line.

Parameters
  • filepath (str) – filename and path

  • lines (list) – A list of text lines. Each entry is a new line.

  • append (bool) – Whether to append the text or if not replace it.

write_replace(filepath, stuff_to_write)
create_dir(name, directory=None, make_unique=False)
Parameters
  • name (str) – The name of the new directory.

  • directory (str) – TODO: Fill in description.

  • make_unique (bool) – Whether to pad the name with a number to make it unique. Only if the name is taken.

Returns

The folder name with path. False if create_dir failed.

Return type

str

delete_dir(name, directory=None)

Delete the folder by name in the directory.

Parameters
  • name (str) – The name of the folder to delete. Name can also be the full path, with no need to supply directory.

  • directory (str) – The directory path where the folder lives.

Returns

The folder that was deleted with path.

Return type

str

delete_read_only_error(action, name, exc)

Helper to delete read only files.

refresh_dir(directory, delete_directory=True)

Delete everything in the directory.

create_file(name, directory=None, make_unique=False)
Parameters
  • name (str) – The name of the new file.

  • directory (str) – TODO: Fill in description.

  • make_unique (bool) – Whether to pad the name with a number to make it unique. Only if the name is taken.

Returns

The filename with path. False if create_dir failed.

Return type

str

remove(name, directory=None)

Remove a file or folder

delete_file(name, directory=None, show_warning=True)

Delete the file by name in the directory.

Parameters
  • name (str) – The name of the file to delete.

  • directory (str) – The dirpath where the file lives.

  • show_warning (bool) – TODO: Fill in description.

Returns

The filepath that was deleted.

Return type

str

copy_with_subprocess(cmd)
fast_copy(directory, directory_destination)
copy_dir(directory, directory_destination, ignore_patterns=None)

Copy the directory to a new directory.

Parameters
  • directory (str) – The directory to copy with path.

  • directory_destination (str) – The destination directory.

  • ignore_patterns (list) – Add txt, py or extensions to ingore them from copying.

  • list (E.g. if py is added to the ignore patterns) –

  • copy. (all *.py files will be ignored from the) –

Returns

The destination directory

Return type

str

copy_file(filepath, filepath_destination)

Copy the file to a new directory.

Parameters
  • filepath (str) – The file to copy with path.

  • filepath_destination (str) – The destination directory.

Returns

The destination directory

Return type

str

delete_versions(folder, keep=1)
is_pyc_outdated(py_file)
delete_pyc(python_script)

Delete the .pyc file the corresponds to the .py file

remove_sourced_code(code_directory)
remove_modules_at_path(path)
source_python_module(code_directory)
load_python_module(module_name, directory)

Load a module by name and return its instance.

Parameters
  • module_name (str) – The name of the module found in the directory.

  • directory (str) – The directory path where the module lives.

Returns

The module instance. With the module instance you can access programmatically functions and attributes of the modules.

Return type

module instance

run_python_module(script_path)
get_module_variables(module)
get_package_children(path)
get_package_path_from_name(module_name, return_module_path=False)
get_line_imports(lines)

This needs to be replaced by AST stuff.

get_defined(module_path, name_only=False)

Get classes and definitions from the text of a module.

get_defined_classes(module_path)
get_ast_function_name_and_args(function_node)
get_ast_function_args(function_node)
get_ast_class_sub_functions(module_path, class_name)
get_ast_class_members(class_node, parents=None, skip_list=None)
get_ast_assignment(text, line_number, assignment)
open_browser(filepath)

Open the file browser to the path specified. Currently only works in windows.

Parameters

filepath (str) – Filename with path.

open_website(url)
get_maya_path()
get_mayapy()
get_mayabatch()
get_process_batch_file()
get_process_deadline_file()
maya_batch_python_file(python_file_path)
launch_maya(version, script=None)

Needs maya installed. If maya is installed in the default directory, will launch the version specified.

launch_nuke(version, command=None)

Needs nuke installed. If nuke is installed in default path, it will launch the version specified.

run_ffmpeg()

Needs ffmpeg installed.

has_deadline()
get_deadline_command_from_settings()