usdmanager.utils module

Generic utility functions

usdmanager.utils.expandPath(path, parentPath=None, sdf_format_args=None, extractedDir=None)[source]

Expand and normalize a path that may have variables in it. Do not use this for URLs with query strings.

Parameters:
path : str

File path

parentPath : str | None

Parent file path this file is defined in relation to. Helps with asset resolution.

sdf_format_args : dict | None

Dictionary of key/value str pairs from a path’s :SDF_FORMAT_ARGS:

extractedDir: str | None

If the file is part of an extracted usdz archive, this is the path to the extracted dir of the archive.

Returns:

Normalized path with variables expanded.

Rtype:

str

usdmanager.utils.expandUrl(path, parentPath=None)[source]

Expand and normalize a URL that may have variables in it and a query string after it.

Parameters:
path : str

File path

parentPath : str | None

Parent file path this file is defined in relation to. Helps with asset resolution.

Returns:

URL with normalized path with variables expanded.

Rtype:

QtCore.QUrl

usdmanager.utils.findModules(subdir)[source]

Find and import all modules in a subdirectory of this project. Ignores any files starting with an underscore or tilde.

Parameters:
subdir : str

Subdirectory

Returns:

Imported modules

Rtype:

list

usdmanager.utils.generateTemporaryUsdFile(usdFileName, tmpDir=None)[source]

Generate a temporary ASCII USD file that the user can edit.

Parameters:
usdFileName : str

Binary USD file path

tmpDir : str | None

Temp directory to create the new file within

Returns:

Temporary file name

Rtype:

str

Raises OSError:

If usdcat fails

usdmanager.utils.getUsdzLayer(usdzDir, layer=None, usdz=None)[source]

Get a layer from an unzipped usdz archive.

Parameters:
usdzDir : str

Unzipped directory path

layer : str

Default layer within file (e.g. the portion within the square brackets here: @foo.usdz[path/to/file/within/package.usd]@)

usdz : str

Original usdz file path

Returns:

Layer file path

Rtype:

str

Raises ValueError:
 

If default layer not found

usdmanager.utils.humanReadableSize(size)[source]

Get a human-readable file size string from bytes.

Parameters:
size : int

File size, in bytes

Returns:

Human-readable file size

Rtype:

str

usdmanager.utils.isUsdCrate(path)[source]

Check if a file is a USD crate file by reading in the first line of the file. Doesn’t check the file extension.

Parameters:
path : str

USD file path

Returns:

If the USD file is a crate (binary) file.

Rtype:

bool

usdmanager.utils.isUsdExt(ext)[source]

Check if the given extension is an expected USD file extension.

Parameters:ext : str
Returns:If the file extension is a valid USD extension
Rtype:bool
usdmanager.utils.isUsdFile(path)[source]

Check if the given file is a USD file based on the file’s extension.

Parameters:path : str
Returns:If the file extension is a valid USD extension
Rtype:bool
usdmanager.utils.loadUiType(uiFile, sourceFile=None, className='DefaultWidgetClass')[source]

Used to define a custom widget’s class.

Parameters:
uiFile : str

UI file path. Can be relative if loading from the same directory as sourceFile.

sourceFile : str

File path of loading module. Used to help find embedded resources and to find uiFile when the file path is relative.

className : str

Class name

Returns:

Class type

Rtype:

type

usdmanager.utils.loadUiWidget(path, parent=None, source_path=None)[source]

Load a Qt Designer .ui file and return an instance of the user interface

Parameters:
path : str

Absolute path to .ui file

parent : QtWidgets.QWidget

The widget into which UI widgets are loaded

source_path : str

File loading the UI file, if the UI file is relative and needs to be found in the same directory

Returns:

The widget instance

Rtype:

QtWidgets.QWidget

usdmanager.utils.overrideCursor(*args, **kwds)[source]

For use with the “with” keyword, so the override cursor is always restored via a try/finally block, even if the commands in-between fail.

Example:
with overrideCursor():
# do something that may raise an error
usdmanager.utils.queryItemBoolValue(url, key, default=False)[source]

Get a boolean value from a query string.

Parameters:
url : QtCore.QUrl

Full URL with query string

key : str

Query key

default

Value if key not found

Returns:

Query value

Rtype:

bool

usdmanager.utils.queryItemValue(url, key, default=None)[source]

Qt.py compatibility, since Qt5 introduced QUrlQuery, but Qt.py doesn’t support that. PyQt4 just uses QUrl for everything, including hasQueryItem and queryItemValue.

Parameters:
url : QtCore.QUrl

Full URL with query string

key : str

Query key

default

Value if key not found

Returns:

Query value, or None

Rtype:

str | None

Raises ValueError:
 

If an invalid query string is given

usdmanager.utils.sdfQuery(link)[source]

Process a link’s query items to see if it has our special sdf entry. This is used to pass along :SDF_FORMAT_ARGS: key/value pairs to downstream files.

Parameters:
link : QtCore.QUrl

Link

Returns:

Sdf format args

Rtype:

dict

usdmanager.utils.strToUrl(path)[source]

Properly set the query parameter of a URL, which doesn’t seem to set QUrl.hasQuery properly unless using .setQuery (or .setQueryItems in Qt5).

Use this when a path might have a query string after it or start with file://. In all other cases. QUrl.fromLocalFile should work fine.

Parameters:
path : str

URL string

Returns:

URL object

Rtype:

QtCore.QUrl

usdmanager.utils.stripFileScheme(path)[source]

Strip any file URI scheme from the beginning of a path.

Parameters:
path : str
File path or file URL
Returns:File path
Rtype:str
usdmanager.utils.unzip(path, tmpDir=None)[source]

Unzip a usdz format file to a temporary directory.

Parameters:
path : str

Input .usdz file

tmpDir : str | None

Temp directory to create the new unzipped directory within

Returns:

Absolute path to destination directory for unzipped usdz

Rtype:

str

Raises zipfile.BadZipfile:
 

For bad ZIP files

Raises zipfile.LargeZipFile:
 

When a ZIP file would require ZIP64 functionality but that has not been enabled

usdmanager.utils.urlFragmentToQuery(url)[source]

Convert a URL with a fragment (e.g. url#?foo=bar) to a URL with a query string.

Normally, this app treats that as a file to NOT reload, using the query string as a mechanism to modify the currently loaded file, such as jumping to a line number. We instead convert this to a “normal” URL with a query string if the URL needs to load in a new tab or new window, for example.

Parameters:
url : QtCore.QUrl

URL

Returns:

Converted URL

Rtype:

QtCore.QUrl

usdmanager.utils.usdRegEx(exts)[source]

RegEx to find other file paths in USD-based text files.

Parameters:
exts:

Iterable of str file path extensions without the starting dot.

usdmanager.utils.usdcat(inputFile, outputFile, format=None)[source]

Generate a temporary ASCII USD file that the user can edit.

Parameters:
inputFile : str

Input file name

outputFile : str

Output file name

format : str | None

Output USD format (e.g. usda or usdc) Only used if outputFile’s extension is .usd

Raises OSError:

If usdcat fails

Raises ValueError:
 

If invalid format given compared to output file extension.

usdmanager.utils.usdzip(inputs, dest)[source]

Zip or unzip a usdz format file.

Parameters:
inputs : str | list

Input file name(s). String or list of strings

dest : str

Output directory (for unzip) or file name

Raises OSError:

If usdzip fails