Inheritance |
|
This class is the base for all other classes in PDG that can store attributes, such as pdg.WorkItem or pdg.Graph.
Methods ¶
addAttrib(name, type:
pdg.attribType, overwrite=
pdg.attribOverwrite.Match, error_level=
pdg.attribErrorLevel.Error)
→ pdg.AttributeFile or pdg.AttributeFloat or pdg.AttributeInt or pdg.AttributePyObject or pdg.AttributeString
Adds an attribute with the specified name and type.
The optional overwrite
argument can be set to a value from the pdg.attribOverwrite enum to control what happens when the objectm already has an attribute with the same name
. By default, if the attribute already exists and has the same type, then the existing attribute is returned. If the attribute exists with a different type, then an exception is thrown. If overwrite
is set to pdg.attribOverwrite.Always the existing attribute will be removed and replace by one with the new type
.
The optional error_level
argument can be used to control how PDG handles failures. By default an exception is thrown with a message that describes the source of the failure. If the pdg.attribErrorLevel.Warn enum value is passed instead and this object is a work item, the error message will instead be added as a warning to the node that owns the work item. Finally, passing in pdg.attribErrorLevel.Quiet will suppress all error reporting. When the error level is set to a value other than Error
, the method will return None
if the attribute cannot be added.
attrib(name)
→ pdg.AttributeFile or pdg.AttributeFloat or pdg.AttributeInt or pdg.AttributePyObject or pdg.AttributeString
Returns the attribute with the specified name, or None
if no such attribute exists.
The attribute is one of the supported attribute types listed in pdg.attribType. You can also write the attribute as attrib_owner.attrib[name]
.
attrib(name, type)
→ pdg.AttributeFile or pdg.AttributeFloat or pdg.AttributeInt or pdg.AttributePyObject or pdg.AttributeString
Returns the attribute with the specified name and type, or None
if no such attribute exists.
attribArray(name)
→ list
of int
, float
, str
or pdg.File
Returns the array stored on an attribute.
attribHash(include_internal=True, include_unowned=True, only_static=False)
→ int
Returns a hash value calculated based on all of attribute values. This can be useful to identify objects between cooks.
The include_internal
argument determines whether or not the hashing operation should include internal attributes defined by PDG itself, like item input/output files or the the command string.
If this is a work item, when the include_unowned
argument is False
the hashing operation will only consider attributes that were modified or added by the node that owns the work item. Otherwise, all attributes are considered.
If this is a work item, when the only_static
argument is True
the hashing operation will only consider attributes created when the work item was generated. Any attribute additions or modifications made while the work item was scheduled or cooked are not included in the hash.
attribHash(filter, include_internal=True, include_unowned=True, only_static=False)
→ int
Performs the same operation as above, but filters the attributes before hashing them using the list of attribute names passed in via the filter
argument.
attribMatch(pattern)
→ list
of str
Returns the list of attribute names from the that match the specified pdg.AttributePattern instance.
attribNames(type=pdg.attribType.Undefined)
→ list
of str
Returns the list of names for all attributes if type
is set to pdg.attribType.Undefined, otherwise returns the list of attribute names with the specified type.
attribValue(name, index=0)
→ int
, float
, str
or pdg.File
Returns the value of an attribute at the specified index. You can also write the attribute as attrib_owner[name][index]
.
attribValues(type=pdg.attribType.Undefined)
→ dict
of list
of int
, float
, and str
Returns a map of all attribute names to values if type
is set to pdg.attribType.Undefined, otherwise returns a map of names to values for all attributes of the specified type.
attribType(name)
→ pdg.attribType
Returns the type of attribute with the specified name, or pdg.attribType.Undefined
if no attribute with that name exists.
clearAttribs()
Clears and deletes all attributes.
clearAttribs(type)
Clears and deletes all attributes of the specified type.
dictAttribArray(name)
→ list
of pdg.Dictionary
Returns the dict attribute array.
dictAttribValue(name, index=0)
→ pdg.Dictionary
Returns the dict attribute value at the specified index.
eraseAttrib(name)
Erases an attribute with the specified name.
fileAttribArray(name)
→ list
of pdg.File
Returns the file attribute array.
fileAttribValue(name, index=0)
→ pdg.File
Returns the file attribute value at the specified index.
floatAttribArray(name)
→ list
of float
Returns the floating point attribute array.
floatAttribValue(name, index=0)
→ float
Returns the floating point attribute value at the specified index.
hasAttrib(name)
→ bool
Returns True
if this object has an attribute with the specified name.
intAttribArray(name)
→ list
of int
Returns the integer attribute array.
intAttribValue(name, index=0)
→ int
Returns the integer attribute value at the specified index.
loadAttributes(file_path, collision_strategy)
→ bool
Loads the attribute data from the specified JSON file into this object. The collision_strategy
should be one of the enum values from pdg.attribCollisionStrategy.
lockAttributes()
→ pdg.LockAttributesBlock
Locks this attributes using a context manager. For the duration of the context manager, it is safe to modify attributes without worry about other threads modifying them.
For example:
with attrib_owner.lockAttributes(): attrib_owner.setIntAttrib("example", 10)
Note
You should not call this method on work items from within a PDG node callback, such as onGenerate
or onPartition
. The node already ensures that the callback can safely access all of the work items.
numAttribs(type=pdg.attribType.Undefined)
→ int
Returns the total number of attributes in the map if type
is set to pdg.attribType.Undefined, otherwise returns the number of attributes of the specified type.
pyObjectAttribValue(name)
→ object
Returns the Python object stored on the specified attribute.
renameAttrib(src_name, dst_name, overwrite_existing=False)
→ bool
Renames the attribute with src_name
to dst_name
.
saveAttributes(file_path)
→ bool
Saves the attribute data stored on this object to the specified file path as JSON. If the file path ends in .gz
the file will be compressed using GZip, otherwise the file is saved as plain text JSON.
setAttribFlag(name, flag, value=True)
Sets or clears the pdg.attribFlag on the specified attribute.
setDictAttrib(name, value, index=0, overwrite=
pdg.attribOverwrite.Match)
Sets a dictionary attribute value at the specified index. If the attribute does not exist, then it is created.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
setDictAttrib(name, array, overwrite=
pdg.attribOverwrite.Match)
Sets a dictionary attribute array. If the attribute does not exist, then it is created.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
setFileAttrib(name, value, index=0, overwrite=
pdg.attribOverwrite.Match)
Sets a file attribute value at the specified index. If the attribute does not exist, then it is created.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
setFileAttrib(name, array, overwrite=
pdg.attribOverwrite.Match)
Sets a file attribute array. If the attribute does not exist, then it is created.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
setFloatAttrib(name, value, index=0, overwrite=
pdg.attribOverwrite.Match)
Sets an float attribute value at the specified index. If the attribute does not exist, then it is created.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
setFloatAttrib(name, array, overwrite=
pdg.attribOverwrite.Match)
Sets a float attribute array. If the attribute does not exist, then it is created.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
setIntAttrib(name, value, index=0, overwrite=
pdg.attribOverwrite.Match)
Sets an integer attribute value at the specified index. If the attribute does not exist, then it is created.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
setIntAttrib(name, array, overwrite=
pdg.attribOverwrite.Match)
Sets an integer attribute array. If the attribute does not exist, then it will be created.
setPyObjectAttrib(name, value, overwrite=
pdg.attribOverwrite.Match)
Sets a Python object attribute value. The attribute will increment the ref count on the object to ensure that it exists for the duration of the attribute itself.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
setStringAttrib(name, value, index=0, overwrite=
pdg.attribOverwrite.Match)
Sets a string attribute value at the specified index. If the attribute does not exist, then it is created.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
setStringAttrib(name, array, overwrite=
pdg.attribOverwrite.Match)
Sets a stringattribute
array. If the attribute does not exist, then it is created.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
stringAttribArray(name)
→ list
of str
Returns the string attribute array.
stringAttribValue(name, index=0)
→ str
Returns the string attribute value at the specified index.
timeDependentAttribs()
→ list
of str
Returns the list of attributes that are time dependent. This method is primarily used for work item that are in a batch with shared attributes on the batch parent.