5 def __init__(self
, name_str
, cmd_str
, optset_list
):
6 self
.name_str
= name_str
10 self
.var_list
["in"] = None
11 self
.var_list
["out"] = None
12 self
.var_list
["quality"] = None
14 self
.optset_list
= optset_list
16 def set_var(self
, var_str
, val_str
):
17 if val_str
.find("&") != -1:
18 raise "Warning: Trying to execute arbitrary code"
19 self
.var_list
[var_str
] = val_str
21 def _insert_known_vars(self
, instr
):
22 for var
in self
.var_list
:
23 if self
.var_list
[var
] != None:
24 p
= re
.compile( '\$\{' + var
+ '\}')
25 instr
= p
.sub( self
.var_list
[var
], instr
)
28 def _contains_vars(self
, instr
):
29 if instr
.find("$") != -1:
35 cmd_to_run
= self
.cmd_str
37 # insert all known variables in cmd string
38 cmd_to_run
= self
._insert
_known
_vars
(cmd_to_run
)
40 # for the optional parameters where all subparameters are known, expand expression otherwise remove totally
41 for opts_name_str
in self
.optset_list
:
42 opts_expr_str
= self
._insert
_known
_vars
(self
.optset_list
[opts_name_str
])
43 p
= re
.compile("\$\[" + opts_name_str
+ "\]")
44 if self
._contains
_vars
(opts_expr_str
):
45 cmd_to_run
= p
.sub("", cmd_to_run
)
47 cmd_to_run
= p
.sub(opts_expr_str
, cmd_str
)
53 self
.command_list
= {}
56 def _read_config(self
):
57 doc
= libxml2
.parseFile("rendercommands.xml")
58 cmd_xmllist
= doc
.xpathEval( '//command')
60 for cmdnode
in cmd_xmllist
:
63 for p
in cmdnode
.properties
:
65 cmd_name_str
= str(p
.children
)
67 cmd_call_str
= str(p
.children
)
72 for optset
in cmdnode
.children
:
76 for p
in optset
.properties
:
78 opts_name_str
= str(p
.children
)
79 elif p
.name
== "expr":
80 opts_expr_str
= str(p
.children
)
81 if opts_name_str
== None or opts_expr_str
== None:
84 raise "optionsetting must have both name and expr"
86 optset_list
[opts_name_str
] = opts_expr_str
88 if cmd_name_str
== None or cmd_call_str
== None:
91 raise "command must have both name and call"
93 self
.command_list
[cmd_name_str
] = RenderCommand(cmd_name_str
, cmd_call_str
, optset_list
)
96 return self
.command_list
.values().__iter
__()
99 commands
= RenderCommands()
102 c
.set_var("in", "source.avi")
103 c
.set_var("out", "dest.avi")
106 if __name__
== "__main__":