fixes python3 compatibility

This commit is contained in:
Jakub Jezek 2021-12-02 19:02:04 +01:00
parent 5ace3472d7
commit fcec9a820d
No known key found for this signature in database
GPG key ID: D8548FBF690B100A
5 changed files with 31 additions and 22 deletions

View file

@ -23,6 +23,7 @@ from .pipeline import (
from .lib import ( from .lib import (
pype_tag_name, pype_tag_name,
flatten,
get_track_items, get_track_items,
get_current_project, get_current_project,
get_current_sequence, get_current_sequence,
@ -75,6 +76,7 @@ __all__ = [
# Lib functions # Lib functions
"pype_tag_name", "pype_tag_name",
"flatten",
"get_track_items", "get_track_items",
"get_current_project", "get_current_project",
"get_current_sequence", "get_current_sequence",

View file

@ -37,14 +37,14 @@ self.default_bin_name = "openpypeBin"
AVALON_CONFIG = os.getenv("AVALON_CONFIG", "pype") AVALON_CONFIG = os.getenv("AVALON_CONFIG", "pype")
def get_current_project(remove_untitled=False): def flatten(input_list):
def flatten(l): for item in input_list:
for i in l: if isinstance(item, (list, tuple)):
if isinstance(i, (list, tuple)): yield from flatten(item)
yield from flatten(i) else:
else: yield item
yield i
def get_current_project(remove_untitled=False):
projects = flatten(hiero.core.projects()) projects = flatten(hiero.core.projects())
if not remove_untitled: if not remove_untitled:
return next(iter(projects)) return next(iter(projects))
@ -256,7 +256,7 @@ def set_track_item_pype_tag(track_item, data=None):
Returns: Returns:
hiero.core.Tag hiero.core.Tag
""" """
data = data or dict() data = data or {}
# basic Tag's attribute # basic Tag's attribute
tag_data = { tag_data = {
@ -290,7 +290,7 @@ def get_track_item_pype_data(track_item):
Returns: Returns:
dict: data found on pype tag dict: data found on pype tag
""" """
data = dict() data = {}
# get pype data tag from track item # get pype data tag from track item
tag = get_track_item_pype_tag(track_item) tag = get_track_item_pype_tag(track_item)
@ -305,8 +305,20 @@ def get_track_item_pype_data(track_item):
try: try:
# capture exceptions which are related to strings only # capture exceptions which are related to strings only
value = ast.literal_eval(v) if re.match(r"^[\d]+$", v):
except (ValueError, SyntaxError): value = int(v)
elif re.match(r"^True$", v):
value = True
elif re.match(r"^False$", v):
value = False
elif re.match(r"^None$", v):
value = None
elif re.match(r"^[\w\d_]+$", v):
value = v
else:
value = ast.literal_eval(v)
except (ValueError, SyntaxError) as msg:
log.warning(msg)
value = v value = v
data.update({key: value}) data.update({key: value})

View file

@ -81,13 +81,11 @@ def create_time_effects(otio_clip, track_item):
otio_effect = otio.schema.LinearTimeWarp() otio_effect = otio.schema.LinearTimeWarp()
otio_effect.name = "Speed" otio_effect.name = "Speed"
otio_effect.time_scalar = speed otio_effect.time_scalar = speed
otio_effect.metadata = {}
# freeze frame effect # freeze frame effect
if speed == 0.: if speed == 0.:
otio_effect = otio.schema.FreezeFrame() otio_effect = otio.schema.FreezeFrame()
otio_effect.name = "FreezeFrame" otio_effect.name = "FreezeFrame"
otio_effect.metadata = {}
if otio_effect: if otio_effect:
# add otio effect to clip effects # add otio effect to clip effects

View file

@ -4,8 +4,6 @@ from openpype.hosts.hiero import api as phiero
from openpype.hosts.hiero.api.otio import hiero_export from openpype.hosts.hiero.api.otio import hiero_export
import hiero import hiero
from compiler.ast import flatten
# # developer reload modules # # developer reload modules
from pprint import pformat from pprint import pformat
@ -339,10 +337,10 @@ class PrecollectInstances(pyblish.api.ContextPlugin):
continue continue
track_index = track.trackIndex() track_index = track.trackIndex()
_sub_track_items = flatten(track.subTrackItems()) _sub_track_items = phiero.flatten(track.subTrackItems())
# continue only if any subtrack items are collected # continue only if any subtrack items are collected
if len(_sub_track_items) < 1: if not list(_sub_track_items):
continue continue
enabled_sti = [] enabled_sti = []
@ -357,7 +355,7 @@ class PrecollectInstances(pyblish.api.ContextPlugin):
enabled_sti.append(_sti) enabled_sti.append(_sti)
# continue only if any subtrack items are collected # continue only if any subtrack items are collected
if len(enabled_sti) < 1: if not enabled_sti:
continue continue
# add collection of subtrackitems to dict # add collection of subtrackitems to dict
@ -371,7 +369,7 @@ class PrecollectInstances(pyblish.api.ContextPlugin):
Returns list of Clip's hiero.core.Annotation Returns list of Clip's hiero.core.Annotation
""" """
annotations = [] annotations = []
subTrackItems = flatten(clip.subTrackItems()) subTrackItems = phiero.flatten(clip.subTrackItems())
annotations += [item for item in subTrackItems if isinstance( annotations += [item for item in subTrackItems if isinstance(
item, hiero.core.Annotation)] item, hiero.core.Annotation)]
return annotations return annotations
@ -382,7 +380,7 @@ class PrecollectInstances(pyblish.api.ContextPlugin):
Returns list of Clip's hiero.core.SubTrackItem Returns list of Clip's hiero.core.SubTrackItem
""" """
subtracks = [] subtracks = []
subTrackItems = flatten(clip.parent().subTrackItems()) subTrackItems = phiero.flatten(clip.parent().subTrackItems())
for item in subTrackItems: for item in subTrackItems:
if "TimeWarp" in item.name(): if "TimeWarp" in item.name():
continue continue

View file

@ -171,8 +171,7 @@ class CollectOcioSubsetResources(pyblish.api.InstancePlugin):
instance.data["representations"].append(repre) instance.data["representations"].append(repre)
self.log.debug(">>>>>>>> {}".format(repre)) self.log.debug(">>>>>>>> {}".format(repre))
import pprint self.log.debug(instance.data)
self.log.debug(pprint.pformat(instance.data))
def _create_representation(self, start, end, **kwargs): def _create_representation(self, start, end, **kwargs):
""" """