Permalink
Browse files

Disable medialinker from commandline (#355)

* Add commandline arguments to set the media linker to none to otiocat and convert.
* Add support to otioview for setting or disabling the media linker.
  • Loading branch information...
ssteinbach committed Nov 6, 2018
1 parent 9d9479a commit 4fd29f53e070153a884568d5b894265bc898644d
Showing with 63 additions and 10 deletions.
  1. +25 −3 opentimelineio/console/otiocat.py
  2. +13 −5 opentimelineio/console/otioconvert.py
  3. +25 −2 opentimelineview/console.py
@@ -43,26 +43,48 @@ def _parsed_args():
nargs='+',
help='files to print the contents of'
)
parser.add_argument(
'-m',
'--media-linker',
type=str,
default="Default",
help=(
"Specify a media linker. 'Default' means use the "
"$OTIO_DEFAULT_MEDIA_LINKER if set, 'None' or '' means explicitly "
"disable the linker, and anything else is interpreted as the name"
" of the media linker to use."
)
)
return parser.parse_args()
def _otio_compatible_file_to_json_string(fpath):
def _otio_compatible_file_to_json_string(fpath, ml):
"""Read the file at fpath with the default otio adapter and return the json
as a string.
"""
adapter = otio.adapters.from_name("otio_json")
return adapter.write_to_string(otio.adapters.read_from_file(fpath))
return adapter.write_to_string(
otio.adapters.read_from_file(fpath, media_linker_name=ml)
)
def main():
"""Parse arguments and call _otio_compatible_file_to_json_string."""
args = _parsed_args()
# allow user to explicitly set or pass to default or disable the linker.
if args.media_linker.lower() == 'default':
ml = otio.media_linker.MediaLinkingPolicy.ForceDefaultLinker
elif args.media_linker.lower() in ['none', '']:
ml = otio.media_linker.MediaLinkingPolicy.DoNotLinkMedia
else:
ml = args.media_linker
for fpath in args.filepath:
print(_otio_compatible_file_to_json_string(fpath))
print(_otio_compatible_file_to_json_string(fpath, ml))
if __name__ == '__main__':
@@ -81,9 +81,13 @@ def _parsed_args():
'-m',
'--media-linker',
type=str,
default=None,
help="Specify a media linker. Default is to use the "
"OTIO_DEFAULT_MEDIA_LINKER, if set.",
default="Default",
help=(
"Specify a media linker. 'Default' means use the "
"$OTIO_DEFAULT_MEDIA_LINKER if set, 'None' or '' means explicitly "
"disable the linker, and anything else is interpreted as the name"
" of the media linker to use."
)
)
return parser.parse_args()
@@ -102,8 +106,12 @@ def main():
if out_adapter is None:
out_adapter = otio.adapters.from_filepath(args.output).name
ml = otio.media_linker.MediaLinkingPolicy.ForceDefaultLinker
if args.media_linker:
# allow user to explicitly set or pass to default or disable the linker.
if args.media_linker.lower() == 'default':
ml = otio.media_linker.MediaLinkingPolicy.ForceDefaultLinker
elif args.media_linker.lower() in ['none', '']:
ml = otio.media_linker.MediaLinkingPolicy.DoNotLinkMedia
else:
ml = args.media_linker
result_tl = otio.adapters.read_from_file(
@@ -57,6 +57,18 @@ def _parsed_args():
'key=value. Values are strings, numbers or Python literals: True, '
'False, etc. Can be used multiple times: -a burrito="bar" -a taco=12.'
)
parser.add_argument(
'-m',
'--media-linker',
type=str,
default="Default",
help=(
"Specify a media linker. 'Default' means use the "
"$OTIO_DEFAULT_MEDIA_LINKER if set, 'None' or '' means explicitly "
"disable the linker, and anything else is interpreted as the name"
" of the media linker to use."
)
)
return parser.parse_args()
@@ -68,9 +80,10 @@ def __init__(self, timeline, *args, **kwargs):
class Main(QtWidgets.QMainWindow):
def __init__(self, adapter_argument_map, *args, **kwargs):
def __init__(self, adapter_argument_map, media_linker, *args, **kwargs):
super(Main, self).__init__(*args, **kwargs)
self.adapter_argument_map = adapter_argument_map or {}
self.media_linker = media_linker
self._current_file = None
@@ -156,6 +169,7 @@ def load(self, path):
self.tracks_widget.clear()
file_contents = otio.adapters.read_from_file(
path,
media_linker_name=self.media_linker,
**self.adapter_argument_map
)
@@ -190,6 +204,15 @@ def center(self):
def main():
args = _parsed_args()
# allow user to explicitly set or pass to default or disable the linker.
if args.media_linker.lower() == 'default':
ml = otio.media_linker.MediaLinkingPolicy.ForceDefaultLinker
elif args.media_linker.lower() in ['none', '']:
ml = otio.media_linker.MediaLinkingPolicy.DoNotLinkMedia
else:
ml = args.media_linker
argument_map = {}
for pair in args.adapter_arg:
if '=' in pair:
@@ -210,7 +233,7 @@ def main():
application = QtWidgets.QApplication(sys.argv)
window = Main(argument_map)
window = Main(argument_map, ml)
if args.input is not None:
window.load(args.input)

0 comments on commit 4fd29f5

Please sign in to comment.