Guerilla Parser class¶
-
class
guerilla_parser.
GuerillaParser
(content, diagnose=False)[source]¶ Bases:
object
Guerilla .gproject file parser.
Variables: -
classmethod
from_file
(path, *args, **kwords)[source]¶ Construct parser reading given file path content.
This is the main method to use if you want to use the parser.
Parameters: path (str) – Path of the Guerilla file to parse. Returns: Parser filled with content of given path. Return type: GuerillaParser
-
has_changed
¶ Return if current parsed file has changed.
A parsed file can be changed using
set_plug_value()
method.Returns: True if both parser instance have same modified content. Return type: bool
-
modified_content
¶ Modified parsed Guerilla file content.
A parsed file can be changed using
set_plug_value()
method.Returns: Modified parsed Guerilla file content. Return type: str
-
original_content
¶ Original (unmodified) parsed Guerilla file content.
Returns: Original (unmodified) parsed Guerilla file content. Return type: str
-
write
(path)[source]¶ Write modified content to given file path.
Parameters: path (str) – File path to write modified content in.
-
root
¶ Root node (top node of the parsed file).
On standard .gproject files, root node is the Document.
Returns: Root node. Return type: GuerillaNode
-
doc_format_rev
¶ Document format revision.
Returns: Document format revision. Return type: int Raises: AttributeError – If no document format revision is present in file.
-
nodes
¶ Recursively iterate over nodes of the gproject file (except root node).
Returns: Generator of nodes of the parsed Guerilla file. Return type: collections.iterator[GuerillaNode]
-
plugs
¶ Iterate over plugs of the gproject file.
Returns: Generator of plugs of the parsed Guerilla file. Return type: collections.iterator[GuerillaPlug]
-
path_to_node
(path)[source]¶ Find and return node at given path.
Example: >>> p.path_to_node('|foo|bar|bee') GuerillaNode('bee', 10, 'primitive') >>> p.path_to_node('$65|bar|bee') GuerillaNode('bee', 10, 'primitive')
Parameters: path (str) – Path to get node from.
Returns: Node found from given path.
Return type: Raises: - PathError – If root node can’t be found.
- PathError – If path contain unreachable nodes.
-
path_to_plug
(path)[source]¶ Find and return plug at given path.
Example: >>> p.path_to_plug('|foo|bar.DiffuseColor') GuerillaPlug('DiffuseColor', 'Plug', '|foo|bar|bee')
Parameters: path (str) – Path to get plug from. Returns: Plug found from given path. Return type: GuerillaPlug Raises: PathError – If path doen’t point to a plugs.
-
static
node_to_id_path
(node)[source]¶ Return the shortest id path for given node.
Node id paths are paths relative to the first parent node with an id.
This methode is mostly for internal use to find plug value in
set_plug_value()
but is exposed to the user for his own convinience; debugging, file compare, etc.Example: >>> p.node_to_id_path(my_node) '$60' >>> p.node_to_id_path(my_other_node) '$37|Frustum'
In the second line above,
my_other_node
is an implicit node. See file format information page for more information.Parameters: node (GuerillaNode) – Implicit node to get id path from. Returns: Return type: str
-
set_plug_value
(plug_values)[source]¶ While exposed, this method is not stable yet and could potentially change in the future.
Parameters: plug_values (list[(GuerillaPlug, str)]) –
-
classmethod