usdmanager.parser module

File parsers

class usdmanager.parser.AbstractExtParser(parent=None)[source]

Bases: usdmanager.parser.FileParser

Determines which files are supported based on extension. Override exts in a subclass to add extensions.

acceptsFile(fileInfo, link)[source]

Accept files with the proper extension.

Parameters:
fileInfo : QFileInfo

File info object

link : QtCore.QUrl

Full URL, potentially with query string

exts = ()
class usdmanager.parser.FileParser(parent=None)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

Base class for RegEx-based file parsing.

RE_FILE_GROUP = 1
acceptsFile(fileInfo, link)[source]

Determine if this parser can accept the incoming file. Note: Parsers check this in a non-deterministic order. Ensure multiple parsers don’t accept the same file.

Override in subclass to filter for files this parser can support.

Parameters:
fileInfo : QFileInfo

File info object

link : QtCore.QUrl

Full URL, potentially with query string

Returns:

It the parser should be able to handle the file

Rtype:

bool

binary = False
cleanup()[source]

Reset variables for a new file.

Don’t override.

compile()[source]

Compile regular expression to find links based on the acceptable extensions stored in self.programs.

Override for language-specific RegEx.

NOTE: If this RegEx changes, the syntax highlighting rules may need to as well.

fileFormat = 5
static generateTempFile(fileName, tmpDir=None)[source]

For file formats supporting ASCII and binary representations, generate a temporary ASCII file that the user can edit.

Parameters:
fileName : str

Binary file path

tmpDir : str | None

Temp directory to create the new file within

Returns:

Temporary file name

Rtype:

str

htmlFormat(text)[source]

Wrap the final text in a proper HTML document.

Override to add additional HTML tags only to the HTML representation of this file.

Parameters:text : str
Returns:HTML text document
Rtype:str
icon

Used by autodoc_mock_imports.

lineCharLimit = 999
parse(nativeAbsPath, fileInfo, link)[source]

Parse a file for links, generating a plain text version and HTML version of the file text.

In general, don’t override unless you need to add something before parsing really starts, and then just call super() for the rest of this method.

Parameters:
nativeAbsPath : str

OS-native absolute file path

fileInfo : QFileInfo

File info object

link : QUrl

Full file path URL

parseLongLine(line)[source]

Process a long line. Link parsing is skipped by default for lines over a certain length.

Override if desired, like truncating the display of a long array.

Parameters:
line : str

Line of text

Returns:

Line of text

Rtype:

str

parseMatch(match, linkPath, nativeAbsPath, fileInfo)[source]

Parse a RegEx match of a patch to another file.

Override for specific language parsing.

Parameters:
match

RegEx match object

linkPath : str

Displayed file path matched by the RegEx

nativeAbsPath : str

OS-native absolute file path for the file being parsed

fileInfo : QFileInfo

File info object for the file being parsed

Returns:

HTML link

Rtype:

str

Raises ValueError:
 

If path does not exist or cannot be resolved.

progress

Used by autodoc_mock_imports.

read(path)[source]
Parameters:
path : str

OS-native absolute file path

Returns:

List of lines of text of file. Can be overridden by subclasses to handle things like crate conversion from binary to ASCII.

Rtype:

[str]

status

Used by autodoc_mock_imports.

stop(stop=True)[source]

Request to stop parsing the active file for links.

Don’t override.

Parameters:
stop : bool

To stop or not

stopTriggered(checked=False)[source]

Request to stop parsing the active file for links.

Don’t override.

Parameters:
checked : bool

For signal only

write(qFile, filePath, tab, tmpDir)[source]

Write out a plain text file.

Parameters:
qFile : QtCore.QFile

Object representing the file to write to

filePath : str

File path to write to

tab : str

Tab being written

tmpDir : str

Temporary directory, if needed for any write operations.

Raises SaveFileError:
 

If the file write fails.

class usdmanager.parser.PathCacheDict[source]

Bases: collections.defaultdict

Cache if file paths referenced more than once in a file exist, so we don’t check on disk over and over.

exception usdmanager.parser.SaveFileError(message, details=None)[source]

Bases: exceptions.Exception

Exception when saving files, where details can be used to provide the earlier traceback for the user in the error dialog’s details section.