flame: refactory api calls

This commit is contained in:
Jakub Jezek 2022-01-07 14:26:06 +01:00
parent 16d920028c
commit 169b896ef4
No known key found for this signature in database
GPG key ID: D8548FBF690B100A
15 changed files with 238 additions and 214 deletions

View file

@ -1,126 +1,5 @@
from .api.utils import (
setup
)
from .api.pipeline import (
install,
uninstall,
ls,
containerise,
update_container,
remove_instance,
list_instances,
imprint,
maintained_selection
)
from .api.lib import (
FlameAppFramework,
maintain_current_timeline,
get_project_manager,
get_current_project,
get_current_sequence,
create_bin,
create_segment_data_marker,
get_segment_data_marker,
set_segment_data_marker,
set_publish_attribute,
get_publish_attribute,
get_sequence_segments,
maintained_segment_selection,
reset_segment_selection,
get_segment_attributes
)
from .api.menu import (
FlameMenuProjectConnect,
FlameMenuTimeline
)
from .api.workio import (
open_file,
save_file,
current_file,
has_unsaved_changes,
file_extensions,
work_root
)
import os
HOST_DIR = os.path.dirname(
os.path.abspath(__file__)
)
API_DIR = os.path.join(HOST_DIR, "api")
PLUGINS_DIR = os.path.join(HOST_DIR, "plugins")
PUBLISH_PATH = os.path.join(PLUGINS_DIR, "publish")
LOAD_PATH = os.path.join(PLUGINS_DIR, "load")
CREATE_PATH = os.path.join(PLUGINS_DIR, "create")
INVENTORY_PATH = os.path.join(PLUGINS_DIR, "inventory")
app_framework = None
apps = []
selection = None
__all__ = [
"HOST_DIR",
"API_DIR",
"PLUGINS_DIR",
"PUBLISH_PATH",
"LOAD_PATH",
"CREATE_PATH",
"INVENTORY_PATH",
"INVENTORY_PATH",
"app_framework",
"apps",
"selection",
# pipeline
"install",
"uninstall",
"ls",
"containerise",
"update_container",
"reload_pipeline",
"maintained_selection",
"remove_instance",
"list_instances",
"imprint",
"maintained_selection",
# utils
"setup",
# lib
"FlameAppFramework",
"maintain_current_timeline",
"get_project_manager",
"get_current_project",
"get_current_sequence",
"create_bin",
"create_segment_data_marker",
"get_segment_data_marker",
"set_segment_data_marker",
"set_publish_attribute",
"get_publish_attribute",
"get_sequence_segments",
"maintained_segment_selection",
"reset_segment_selection",
"get_segment_attributes"
# menu
"FlameMenuProjectConnect",
"FlameMenuTimeline",
# plugin
# workio
"open_file",
"save_file",
"current_file",
"has_unsaved_changes",
"file_extensions",
"work_root"
]

View file

@ -1,3 +1,117 @@
"""
OpenPype Autodesk Flame api
"""
from .constants import (
COLOR_MAP,
MARKER_NAME,
MARKER_COLOR,
MARKER_DURATION,
MARKER_PUBLISH_DEFAULT
)
from .lib import (
CTX,
FlameAppFramework,
maintain_current_timeline,
get_project_manager,
get_current_project,
get_current_sequence,
create_bin,
create_segment_data_marker,
get_segment_data_marker,
set_segment_data_marker,
set_publish_attribute,
get_publish_attribute,
get_sequence_segments,
maintained_segment_selection,
reset_segment_selection,
get_segment_attributes
)
from .utils import (
setup
)
from .pipeline import (
install,
uninstall,
ls,
containerise,
update_container,
remove_instance,
list_instances,
imprint,
maintained_selection
)
from .menu import (
FlameMenuProjectConnect,
FlameMenuTimeline
)
from .plugin import (
Creator,
PublishableClip
)
from .workio import (
open_file,
save_file,
current_file,
has_unsaved_changes,
file_extensions,
work_root
)
__all__ = [
# constants
"COLOR_MAP",
"MARKER_NAME",
"MARKER_COLOR",
"MARKER_DURATION",
"MARKER_PUBLISH_DEFAULT",
# lib
"CTX",
"FlameAppFramework",
"maintain_current_timeline",
"get_project_manager",
"get_current_project",
"get_current_sequence",
"create_bin",
"create_segment_data_marker",
"get_segment_data_marker",
"set_segment_data_marker",
"set_publish_attribute",
"get_publish_attribute",
"get_sequence_segments",
"maintained_segment_selection",
"reset_segment_selection",
"get_segment_attributes",
# pipeline
"install",
"uninstall",
"ls",
"containerise",
"update_container",
"reload_pipeline",
"maintained_selection",
"remove_instance",
"list_instances",
"imprint",
"maintained_selection",
# utils
"setup",
# menu
"FlameMenuProjectConnect",
"FlameMenuTimeline",
# plugin
"Creator",
"PublishableClip",
# workio
"open_file",
"save_file",
"current_file",
"has_unsaved_changes",
"file_extensions",
"work_root"
]

View file

@ -0,0 +1,24 @@
"""
OpenPype Flame api constances
"""
# OpenPype marker workflow variables
MARKER_NAME = "OpenPypeData"
MARKER_DURATION = 0
MARKER_COLOR = "cyan"
MARKER_PUBLISH_DEFAULT = False
# OpenPype color definitions
COLOR_MAP = {
"red": (1.0, 0.0, 0.0),
"orange": (1.0, 0.5, 0.0),
"yellow": (1.0, 1.0, 0.0),
"pink": (1.0, 0.5, 1.0),
"white": (1.0, 1.0, 1.0),
"green": (0.0, 1.0, 0.0),
"cyan": (0.0, 1.0, 1.0),
"blue": (0.0, 0.0, 1.0),
"purple": (0.5, 0.0, 0.5),
"magenta": (0.5, 0.0, 1.0),
"black": (0.0, 0.0, 0.0)
}

View file

@ -5,30 +5,24 @@ import json
import pickle
import contextlib
from pprint import pformat
from .constants import (
MARKER_COLOR,
MARKER_DURATION,
MARKER_NAME,
COLOR_MAP,
MARKER_PUBLISH_DEFAULT
)
from openpype.api import Logger
log = Logger().get_logger(__name__)
log = Logger.get_logger(__name__)
class CTX:
# singleton used for passing data between api modules
app_framework = None
apps = []
selection = None
class ctx:
# OpenPype marker workflow variables
marker_name = "OpenPypeData"
marker_duration = 0
marker_color = "cyan"
publish_default = False
color_map = {
"red": (1.0, 0.0, 0.0),
"orange": (1.0, 0.5, 0.0),
"yellow": (1.0, 1.0, 0.0),
"pink": (1.0, 0.5, 1.0),
"white": (1.0, 1.0, 1.0),
"green": (0.0, 1.0, 0.0),
"cyan": (0.0, 1.0, 1.0),
"blue": (0.0, 0.0, 1.0),
"purple": (0.5, 0.0, 0.5),
"magenta": (0.5, 0.0, 1.0),
"black": (0.0, 0.0, 0.0)
}
@contextlib.contextmanager
def io_preferences_file(klass, filepath, write=False):
@ -379,7 +373,8 @@ def get_segment_data_marker(segment, with_marker=None):
color = marker.colour.get_value()
name = marker.name.get_value()
if name == ctx.marker_name and color == ctx.color_map[ctx.marker_color]:
if (name == MARKER_NAME) and (
color == COLOR_MAP[MARKER_COLOR]):
if not with_marker:
return json.loads(comment)
else:
@ -443,8 +438,8 @@ def get_publish_attribute(segment):
tag_data = get_segment_data_marker(segment)
if not tag_data:
set_publish_attribute(segment, ctx.publish_default)
return ctx.publish_default
set_publish_attribute(segment, MARKER_PUBLISH_DEFAULT)
return MARKER_PUBLISH_DEFAULT
return tag_data["publish"]
@ -465,14 +460,15 @@ def create_segment_data_marker(segment):
# create marker
marker = segment.create_marker(start_frame)
# set marker name
marker.name = ctx.marker_name
marker.name = MARKER_NAME
# set duration
marker.duration = ctx.marker_duration
marker.duration = MARKER_DURATION
# set colour
marker.colour = ctx.color_map[ctx.marker_color] # Red
marker.colour = COLOR_MAP[MARKER_COLOR] # Red
return marker
def get_sequence_segments(sequence, selected=False):
segments = []
# loop versions in sequence
@ -485,7 +481,7 @@ def get_sequence_segments(sequence, selected=False):
# loop all segment in remaining tracks
for segment in track.segments:
# ignore all segments not selected
if segment.selected != True and selected == True:
if segment.selected is not True and selected is True:
continue
# add it to original selection
segments.append(segment)

View file

@ -1,7 +1,7 @@
import os
from Qt import QtWidgets
from copy import deepcopy
from pprint import pformat
from openpype.tools.utils.host_tools import HostToolsHelper
menu_group_name = 'OpenPype'
@ -26,9 +26,11 @@ default_flame_export_presets = {
def callback_selection(selection, function):
import openpype.hosts.flame as opflame
opflame.selection = selection
print(opflame.selection)
import openpype.hosts.flame.api as opfapi
opfapi.CTX.selection = selection
print("Hook Selection: \n\t{}".format(
pformat({type(item): item.name for item in CTX.selection})
))
function()

View file

@ -1,6 +1,7 @@
"""
Basic avalon integration
"""
import os
import contextlib
from avalon import api as avalon
from pyblish import api as pyblish
@ -11,10 +12,18 @@ from .lib import (
maintained_segment_selection,
get_current_sequence
)
from .. import HOST_DIR
API_DIR = os.path.join(HOST_DIR, "api")
PLUGINS_DIR = os.path.join(HOST_DIR, "plugins")
PUBLISH_PATH = os.path.join(PLUGINS_DIR, "publish")
LOAD_PATH = os.path.join(PLUGINS_DIR, "load")
CREATE_PATH = os.path.join(PLUGINS_DIR, "create")
INVENTORY_PATH = os.path.join(PLUGINS_DIR, "inventory")
AVALON_CONTAINERS = "AVALON_CONTAINERS"
log = Logger().get_logger(__name__)
log = Logger.get_logger(__name__)
def install():

View file

@ -1,13 +1,17 @@
import re
import os
from Qt import QtWidgets, QtCore
import openpype.api as openpype
from openpype import style
import openpype.hosts.flame as opflame
from . import lib, pipeline
from . import selection as opfapi_selection
from . import (
lib as flib,
pipeline as fpipeline,
constants
)
from copy import deepcopy
log = openpype.Logger().get_logger(__name__)
log = openpype.Logger.get_logger(__name__)
class CreatorWidget(QtWidgets.QDialog):
@ -283,7 +287,7 @@ class Spacer(QtWidgets.QWidget):
class Creator(openpype.Creator):
"""Creator class wrapper
"""
clip_color = lib.ctx.color_map["purple"]
clip_color = constants.COLOR_MAP["purple"]
rename_index = None
def __init__(self, *args, **kwargs):
@ -292,13 +296,13 @@ class Creator(openpype.Creator):
"flame"]["create"].get(self.__class__.__name__, {})
# adding basic current context flame objects
self.project = lib.get_current_project()
self.sequence = lib.get_current_sequence(opflame.selection)
self.project = flib.get_current_project()
self.sequence = flib.get_current_sequence(opfapi_selection)
if (self.options or {}).get("useSelection"):
self.selected = lib.get_sequence_segments(self.sequence, True)
self.selected = flib.get_sequence_segments(self.sequence, True)
else:
self.selected = lib.get_sequence_segments(self.sequence)
self.selected = flib.get_sequence_segments(self.sequence)
self.widget = CreatorWidget
@ -345,10 +349,10 @@ class PublishableClip:
# get main parent objects
self.current_segment = segment
sequence_name = lib.get_current_sequence([segment]).name.get_value()
sequence_name = flib.get_current_sequence([segment]).name.get_value()
self.sequence_name = str(sequence_name).replace(" ", "_")
self.clip_data = lib.get_segment_attributes(segment)
self.clip_data = flib.get_segment_attributes(segment)
# segment (clip) main attributes
self.cs_name = self.clip_data["segment_name"]
self.cs_index = int(self.clip_data["segment"])
@ -406,7 +410,7 @@ class PublishableClip:
self.marker_data.update({"reviewTrack": None})
# create pype tag on track_item and add data
pipeline.imprint(self.current_segment, self.marker_data)
fpipeline.imprint(self.current_segment, self.marker_data)
return self.current_segment

View file

@ -16,7 +16,7 @@ if not FLAME_V:
raise KeyError("Missing key in environment `OPENPYPE_FLAME_VERSION`")
try:
from libwiretapPythonClientAPI import (
from libwiretapPythonClientAPI import ( # noqa
WireTapClientInit)
except ImportError:
flame_python_path = "/opt/Autodesk/flame_{}/python".format(FLAME_V)
@ -26,7 +26,7 @@ except ImportError:
sys.path.append(flame_python_path)
from libwiretapPythonClientAPI import (
from libwiretapPythonClientAPI import ( # noqa
WireTapClientInit,
WireTapClientUninit,
WireTapNodeHandle,

View file

@ -5,17 +5,14 @@ from pprint import pformat
import atexit
import openpype
import avalon
import openpype.hosts.flame as opflame
flh = sys.modules[__name__]
flh._project = None
import openpype.hosts.flame.api as opfapi
def openpype_install():
"""Registering OpenPype in context
"""
openpype.install()
avalon.api.install(opflame)
avalon.api.install(opfapi)
print("Avalon registred hosts: {}".format(
avalon.api.registered_host()))
@ -48,19 +45,19 @@ sys.excepthook = exeption_handler
def cleanup():
"""Cleaning up Flame framework context
"""
if opflame.apps:
if opfapi.CTX.apps:
print('`{}` cleaning up apps:\n {}\n'.format(
__file__, pformat(opflame.apps)))
while len(opflame.apps):
app = opflame.apps.pop()
__file__, pformat(opfapi.CTX.apps)))
while len(opfapi.CTX.apps):
app = opfapi.CTX.apps.pop()
print('`{}` removing : {}'.format(__file__, app.name))
del app
opflame.apps = []
opfapi.CTX.apps = []
if opflame.app_framework:
print('PYTHON\t: %s cleaning up' % opflame.app_framework.bundle_name)
opflame.app_framework.save_prefs()
opflame.app_framework = None
if opfapi.CTX.app_framework:
print('PYTHON\t: %s cleaning up' % opfapi.CTX.app_framework.bundle_name)
opfapi.CTX.app_framework.save_prefs()
opfapi.CTX.app_framework = None
atexit.register(cleanup)
@ -69,9 +66,9 @@ atexit.register(cleanup)
def load_apps():
"""Load available apps into Flame framework
"""
opflame.apps.append(opflame.FlameMenuProjectConnect(opflame.app_framework))
opflame.apps.append(opflame.FlameMenuTimeline(opflame.app_framework))
opflame.app_framework.log.info("Apps are loaded")
opfapi.CTX.apps.append(opfapi.FlameMenuProjectConnect(opfapi.CTX.app_framework))
opfapi.CTX.apps.append(opfapi.FlameMenuTimeline(opfapi.CTX.app_framework))
opfapi.CTX.app_framework.log.info("Apps are loaded")
def project_changed_dict(info):
@ -89,10 +86,10 @@ def app_initialized(parent=None):
Args:
parent (obj, optional): Parent object. Defaults to None.
"""
opflame.app_framework = opflame.FlameAppFramework()
opfapi.CTX.app_framework = opfapi.FlameAppFramework()
print("{} initializing".format(
opflame.app_framework.bundle_name))
opfapi.CTX.app_framework.bundle_name))
load_apps()
@ -131,15 +128,15 @@ def _build_app_menu(app_name):
# first find the relative appname
app = None
for _app in opflame.apps:
for _app in opfapi.CTX.apps:
if _app.__class__.__name__ == app_name:
app = _app
if app:
menu.append(app.build_menu())
if opflame.app_framework:
menu_auto_refresh = opflame.app_framework.prefs_global.get(
if opfapi.CTX.app_framework:
menu_auto_refresh = opfapi.CTX.app_framework.prefs_global.get(
'menu_auto_refresh', {})
if menu_auto_refresh.get('timeline_menu', True):
try:
@ -163,8 +160,8 @@ def project_saved(project_name, save_time, is_auto_save):
save_time (str): time when it was saved
is_auto_save (bool): autosave is on or off
"""
if opflame.app_framework:
opflame.app_framework.save_prefs()
if opfapi.CTX.app_framework:
opfapi.CTX.app_framework.save_prefs()
def get_main_menu_custom_ui_actions():

View file

@ -5,7 +5,7 @@ Flame utils for syncing scripts
import os
import shutil
from openpype.api import Logger
log = Logger().get_logger(__name__)
log = Logger.get_logger(__name__)
def _sync_utility_scripts(env=None):

View file

@ -8,7 +8,7 @@ from openpype.api import Logger
# )
log = Logger().get_logger(__name__)
log = Logger.get_logger(__name__)
exported_projet_ext = ".otoc"

View file

@ -6,6 +6,7 @@ import socket
from openpype.lib import (
PreLaunchHook, get_openpype_username)
from openpype.hosts import flame as opflame
import openpype.hosts.flame.api as opfapi
import openpype
from pprint import pformat
@ -79,7 +80,7 @@ class FlamePrelaunch(PreLaunchHook):
app_arguments = self._get_launch_arguments(data_to_script)
opflame.setup(self.launch_context.env)
opfapi.setup(self.launch_context.env)
self.launch_context.launch_args.extend(app_arguments)

View file

@ -11,7 +11,7 @@ from . import utils
import flame
from pprint import pformat
reload(utils) # noqa
reload(utils) # type: ignore
log = logging.getLogger(__name__)

View file

@ -1,9 +1,8 @@
from copy import deepcopy
import openpype.hosts.flame as opflame
import openpype.hosts.flame.api.plugin as fplugin
import openpype.hosts.flame.api.lib as flib
reload(fplugin)
reload(flib)
import openpype.hosts.flame.api as opfapi
reload(opfapi) # noqa
def _get_video_track_names(sequence):
track_names = []
@ -13,7 +12,8 @@ def _get_video_track_names(sequence):
return track_names
class CreateShotClip(fplugin.Creator):
class CreateShotClip(opfapi.Creator):
"""Publishable clip"""
label = "Create Publishable Clip"
@ -22,7 +22,7 @@ class CreateShotClip(fplugin.Creator):
defaults = ["Main"]
gui_tracks = _get_video_track_names(
flib.get_current_sequence(opflame.selection)
opfapi.get_current_sequence(opfapi.CTX.selection)
)
gui_name = "Pype publish attributes creator"
gui_info = "Define sequential rename and fill hierarchy data."
@ -267,4 +267,4 @@ class CreateShotClip(fplugin.Creator):
self.rename_index = i
# convert track item to timeline media pool item
fplugin.PublishableClip(self, segment, **kwargs).convert()
opfapi.PublishableClip(self, segment, **kwargs).convert()

View file

@ -1,12 +1,10 @@
import os
import pyblish.api
import openpype.hosts.flame as opflame
import openpype.hosts.flame.api as opfapi
from openpype.hosts.flame.otio import flame_export as otio_export
from openpype.hosts.flame.api import lib, pipeline
from pprint import pformat
reload(lib) # noqa
reload(pipeline) # noqa
reload(otio_export) # noqa
reload(opfapi) # type: ignore
reload(otio_export) # type: ignore
@pyblish.api.log
@ -20,9 +18,9 @@ class CollectTestSelection(pyblish.api.ContextPlugin):
def process(self, context):
self.log.info(
"Active Selection: {}".format(opflame.selection))
"Active Selection: {}".format(opfapi.CTX.selection))
sequence = lib.get_current_sequence(opflame.selection)
sequence = opfapi.get_current_sequence(opfapi.CTX.selection)
self.test_imprint_data(sequence)
self.test_otio_export(sequence)
@ -43,15 +41,15 @@ class CollectTestSelection(pyblish.api.ContextPlugin):
self.log.info("Otio exported to: {}".format(export_path))
def test_imprint_data(self, sequence):
with lib.maintained_segment_selection(sequence) as selected_segments:
for segment in selected_segments:
with opfapi.maintained_segment_selection(sequence) as sel_segments:
for segment in sel_segments:
if str(segment.name)[1:-1] == "":
continue
self.log.debug("Segment with OpenPypeData: {}".format(
segment.name))
pipeline.imprint(segment, {
opfapi.imprint(segment, {
'asset': segment.name.get_value(),
'family': 'render',
'subset': 'subsetMain'