Skip to content

Commit

Permalink
Disable medialinker from commandline (AcademySoftwareFoundation#355)
Browse files Browse the repository at this point in the history
* 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 authored and alatdneg committed Nov 13, 2018
1 parent 7dbc98e commit ddeed1d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 10 deletions.
28 changes: 25 additions & 3 deletions opentimelineio/console/otiocat.py
Expand Up @@ -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__':
Expand Down
18 changes: 13 additions & 5 deletions opentimelineio/console/otioconvert.py
Expand Up @@ -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()
Expand All @@ -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(
Expand Down
27 changes: 25 additions & 2 deletions opentimelineview/console.py
Expand Up @@ -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()

Expand All @@ -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

Expand Down Expand Up @@ -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
)

Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit ddeed1d

Please sign in to comment.