Skip to content

Commit 6da05dd

Browse files
mikekoetterMike Koetter
andauthored
Add hook function args to otioview and otioconvert (#651)
* feat(console): Add hook function args to otioview and otioconvert * fix(otioconvert): Forgot to update the label for error formatting * feat(otiocat): Add Hook function args to `otiocat` as well Co-authored-by: Mike Koetter <[email protected]>
1 parent 79ae31d commit 6da05dd

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/opentimelineview/console.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ def _parsed_args():
5757
'key=value. Values are strings, numbers or Python literals: True, '
5858
'False, etc. Can be used multiple times: -a burrito="bar" -a taco=12.'
5959
)
60+
parser.add_argument(
61+
'-H',
62+
'--hook-function-arg',
63+
type=str,
64+
default=[],
65+
action='append',
66+
help='Extra arguments to be passed to the hook functions in the form of '
67+
'key=value. Values are strings, numbers or Python literals: True, '
68+
'False, etc. Can be used multiple times: -H burrito="bar" -H taco=12.'
69+
)
6070
parser.add_argument(
6171
'-m',
6272
'--media-linker',
@@ -93,6 +103,7 @@ class Main(QtWidgets.QMainWindow):
93103
def __init__(
94104
self,
95105
adapter_argument_map,
106+
hook_function_argument_map,
96107
media_linker,
97108
media_linker_argument_map,
98109
*args,
@@ -102,6 +113,7 @@ def __init__(
102113
self.adapter_argument_map = adapter_argument_map or {}
103114
self.media_linker = media_linker
104115
self.media_linker_argument_map = media_linker_argument_map
116+
self.hook_function_argument_map = hook_function_argument_map
105117

106118
self._current_file = None
107119

@@ -193,6 +205,7 @@ def load(self, path):
193205
self.tracks_widget.clear()
194206
file_contents = otio.adapters.read_from_file(
195207
path,
208+
hook_function_argument_map=self.hook_function_argument_map,
196209
media_linker_name=self.media_linker,
197210
media_linker_argument_map=self.media_linker_argument_map,
198211
**self.adapter_argument_map
@@ -263,6 +276,10 @@ def main():
263276
args.media_linker_arg,
264277
"media linker"
265278
)
279+
hook_function_argument_map = otio_console.console_utils.arg_list_to_map(
280+
args.hook_function_arg,
281+
"hook function"
282+
)
266283
except ValueError as exc:
267284
sys.stderr.write("\n" + str(exc) + "\n")
268285
sys.exit(1)
@@ -271,6 +288,7 @@ def main():
271288

272289
window = Main(
273290
read_adapter_arg_map,
291+
hook_function_argument_map,
274292
media_linker_name,
275293
media_linker_argument_map
276294
)

src/py-opentimelineio/opentimelineio/console/otiocat.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ def _parsed_args():
6666
" of the media linker to use."
6767
)
6868
)
69+
parser.add_argument(
70+
'-H',
71+
'--hook-function-arg',
72+
type=str,
73+
default=[],
74+
action='append',
75+
help='Extra arguments to be passed to the hook functions in the form of '
76+
'key=value. Values are strings, numbers or Python literals: True, '
77+
'False, etc. Can be used multiple times: -H burrito="bar" -H taco=12.'
78+
)
6979
parser.add_argument(
7080
'-M',
7181
'--media-linker-arg',
@@ -83,6 +93,7 @@ def _parsed_args():
8393
def _otio_compatible_file_to_json_string(
8494
fpath,
8595
media_linker_name,
96+
hooks_args,
8697
media_linker_argument_map,
8798
adapter_argument_map
8899
):
@@ -94,6 +105,7 @@ def _otio_compatible_file_to_json_string(
94105
return adapter.write_to_string(
95106
otio.adapters.read_from_file(
96107
fpath,
108+
hook_function_argument_map=hooks_args,
97109
media_linker_name=media_linker_name,
98110
media_linker_argument_map=media_linker_argument_map,
99111
**adapter_argument_map
@@ -115,6 +127,10 @@ def main():
115127
args.adapter_arg,
116128
"adapter"
117129
)
130+
hooks_args = otio.console.console_utils.arg_list_to_map(
131+
args.hook_function_arg,
132+
"hook function"
133+
)
118134
media_linker_argument_map = otio.console.console_utils.arg_list_to_map(
119135
args.media_linker_arg,
120136
"media linker"
@@ -128,6 +144,7 @@ def main():
128144
_otio_compatible_file_to_json_string(
129145
fpath,
130146
media_linker_name,
147+
hooks_args,
131148
media_linker_argument_map,
132149
read_adapter_arg_map
133150
)

src/py-opentimelineio/opentimelineio/console/otioconvert.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ def _parsed_args():
9090
" of the media linker to use."
9191
)
9292
)
93+
parser.add_argument(
94+
'-H',
95+
'--hook-function-arg',
96+
type=str,
97+
default=[],
98+
action='append',
99+
help='Extra arguments to be passed to the hook functions in the form of '
100+
'key=value. Values are strings, numbers or Python literals: True, '
101+
'False, etc. Can be used multiple times: -H burrito="bar" -H taco=12.'
102+
)
93103
parser.add_argument(
94104
'-M',
95105
'--media-linker-arg',
@@ -201,6 +211,10 @@ def main():
201211
args.adapter_arg,
202212
"input adapter"
203213
)
214+
hooks_args = otio.console.console_utils.arg_list_to_map(
215+
args.hook_function_arg,
216+
"hook function"
217+
)
204218
ml_args = otio.console.console_utils.arg_list_to_map(
205219
args.media_linker_arg,
206220
"media linker"
@@ -212,6 +226,7 @@ def main():
212226
result_tl = otio.adapters.read_from_file(
213227
args.input,
214228
in_adapter,
229+
hook_function_argument_map=hooks_args,
215230
media_linker_name=media_linker_name,
216231
media_linker_argument_map=ml_args,
217232
**read_adapter_arg_map
@@ -247,6 +262,7 @@ def main():
247262
result_tl,
248263
args.output,
249264
out_adapter,
265+
hook_function_argument_map=hooks_args,
250266
**write_adapter_arg_map
251267
)
252268

0 commit comments

Comments
 (0)