vtool.util_file

Class Summary

ProcessLog(path)

WatchDirectoryThread()

Not developed fully.

VersionFile(filepath)

Convenience to version a file or folder.

SettingsFile()

ControlNameFromSettingsFile([directory])

FindUniquePath(directory)

ParsePython(filepath)

This needs to be replaced by something that uses the AST instead.

PythonScope(name)

ReadCache()

Function Summary

get_permission(filepath)

get_vetala_version()

get_vetala_directory()

is_locked(filepath)

lock(filepath)

remove_lock(filepath)

get_lock_name(filepath)

queue_file_access(func)

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_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_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])

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_installed_programs()

Not working at all, very hacky

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 the are all /

set_windows_slashes(directory)

Set all the slashes in a name so they are all :returns: The new directory path.

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.

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])

delete_pyc(python_script)

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

remove_sourced_code(code_directory)

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_class_map(lines)

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()
class ProcessLog(path)
record_temp_log(name, value)
end_temp_log()
class WatchDirectoryThread

Not developed fully.

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is the argument tuple for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

run(directory)

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

property daemon

A boolean value indicating whether this thread is a daemon thread.

This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.

The entire Python program exits when only daemon threads are left.

getName()
property ident

Thread identifier of this thread or None if it has not been started.

This is a nonzero integer. See the get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.

isAlive()

Return whether the thread is alive.

This method is deprecated, use is_alive() instead.

isDaemon()
is_alive()

Return whether the thread is alive.

This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.

join(timeout=None)

Wait until the thread terminates.

This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call is_alive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

property name

A string used for identification purposes only.

It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.

setDaemon(daemonic)
setName(name)
start()

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.

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)
class FindUniquePath(directory)
get()
set_padding(int_value)
class ParsePython(filepath)

This needs to be replaced by something that uses the AST instead.

find_scope_type(line, indent)
class PythonScope(name)
set_scope_type(scope_type_name)
set_bracket(bracket_string)
set_scope_lines(lines)
set_parent(parent_scope)
set_child(child_scope)
set_indent(indent)
class ReadCache
read_files = {}
classmethod is_read(path)
classmethod set_read_data(path, data)
classmethod remove_read_data(path)
classmethod cache_read_data(path)
is_locked(filepath)
lock(filepath)
remove_lock(filepath)
get_lock_name(filepath)
queue_file_access(func)
get_basename(directory)

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

Parameters

directoroy (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

directoroy (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_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.

Returns

A list of files in the directory.

Return type

list

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.

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.

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) – eg. .py, .data, etc.

  • directory (str) – A directory path.

  • fullpath (bool) – Wether to returh the filepath or just the file names.

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) –

Retrun

float: The size of the file specified by filepath.

get_folder_size(path, round_value=2, 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, 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

text (str) – Text from get_file_lines

Returns

list

set_json(filepath, data, append=False)
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

Wether 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_installed_programs()

Not working at all, very hacky

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 the are all /

Returns

The new directory path.

Return type

str

set_windows_slashes(directory)

Set all the slashes in a name so they are all :returns: The new directory path. :rtype: 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) – Wether to add a number to the name to make it unique, if needed.

Retrun

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

Wether 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) – Wether 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.

  • make_unique (bool) – Wether 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 dirpath 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.

  • make_unique (bool) – Wether 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

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.

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=[])

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 (Eg. 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)
delete_pyc(python_script)

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

remove_sourced_code(code_directory)
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 programattically 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_class_map(lines)
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=[], 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()