diff --git a/pype/hooks/resolve/prelaunch.py b/pype/hooks/resolve/prelaunch.py index ebf101dc1d..e3e1c83077 100644 --- a/pype/hooks/resolve/prelaunch.py +++ b/pype/hooks/resolve/prelaunch.py @@ -26,8 +26,28 @@ class ResolvePrelaunch(PypeHook): if not env: env = os.environ - env["PRE_PYTHON_SCRIPT"] = os.path.normpath(env["PRE_PYTHON_SCRIPT"]) - self.log.info(env["PRE_PYTHON_SCRIPT"]) + # making sure pyton 3.6 is installed at provided path + py36_dir = os.path.normpath(env.get("PYTHON36_RES", "")) + assert os.path.isdir(py36_dir), ( + "Python 3.6 is not installed at the provided folder path. Either " + "make sure the `environments\resolve.json` is having correctly set " + "`PYTHON36_RES` or make sure Python 3.6 is installed in given path." + f"\nPYTHON36_RES: `{py36_dir}`" + ) + env["PYTHON36_RES"] = py36_dir + + # setting utility scripts dir for scripts syncing + us_dir = os.path.normpath(env.get("RESOLVE_UTILITY_SCRIPTS_DIR", "")) + assert os.path.isdir(us_dir), ( + "Resolve utility script dir does not exists. Either make sure " + "the `environments\resolve.json` is having correctly set " + "`RESOLVE_UTILITY_SCRIPTS_DIR` or reinstall DaVinci Resolve. \n" + f"RESOLVE_UTILITY_SCRIPTS_DIR: `{us_dir}`" + ) + + # correctly format path for pre python script + pre_py_sc = os.path.normpath(env.get("PRE_PYTHON_SCRIPT", "")) + env["PRE_PYTHON_SCRIPT"] = pre_py_sc try: __import__("pype.resolve") @@ -39,7 +59,6 @@ class ResolvePrelaunch(PypeHook): else: # Resolve Setup integration - # importlib.reload(prlib) rlib.setup(env) return True diff --git a/pype/resolve/__init__.py b/pype/resolve/__init__.py index 1e6c7c2274..0683cfa92f 100644 --- a/pype/resolve/__init__.py +++ b/pype/resolve/__init__.py @@ -8,8 +8,8 @@ from .lib import ( setup, reload_pipeline, ls, - LOAD_PATH, - CREATE_PATH, + # LOAD_PATH, + # CREATE_PATH, PUBLISH_PATH ) @@ -48,8 +48,8 @@ def install(): pyblish.register_plugin_path(PUBLISH_PATH) log.info("Registering Premiera plug-ins..") - avalon.register_plugin_path(avalon.Loader, LOAD_PATH) - avalon.register_plugin_path(avalon.Creator, CREATE_PATH) + # avalon.register_plugin_path(avalon.Loader, LOAD_PATH) + # avalon.register_plugin_path(avalon.Creator, CREATE_PATH) def uninstall(): @@ -67,5 +67,5 @@ def uninstall(): pyblish.deregister_plugin_path(PUBLISH_PATH) log.info("Deregistering Premiera plug-ins..") - avalon.deregister_plugin_path(avalon.Loader, LOAD_PATH) - avalon.deregister_plugin_path(avalon.Creator, CREATE_PATH) + # avalon.deregister_plugin_path(avalon.Loader, LOAD_PATH) + # avalon.deregister_plugin_path(avalon.Creator, CREATE_PATH) diff --git a/pype/resolve/lib.py b/pype/resolve/lib.py index 012bcdd80c..95586b00eb 100644 --- a/pype/resolve/lib.py +++ b/pype/resolve/lib.py @@ -1,34 +1,21 @@ import os import sys import shutil -import json -from pysync import walktree -import requests from avalon import api from pype.widgets.message_window import message from pypeapp import Logger - log = Logger().get_logger(__name__, "resolve") self = sys.modules[__name__] -self._has_been_setup = False -self._registered_gui = None AVALON_CONFIG = os.environ["AVALON_CONFIG"] - PARENT_DIR = os.path.dirname(__file__) PACKAGE_DIR = os.path.dirname(PARENT_DIR) PLUGINS_DIR = os.path.join(PACKAGE_DIR, "plugins") -self.EXTENSIONS_PATH_REMOTE = os.path.join(PARENT_DIR, "extensions") -self.EXTENSIONS_PATH_LOCAL = None -self.EXTENSIONS_CACHE_PATH = None - -self.LOAD_PATH = os.path.join(PLUGINS_DIR, "resolve", "load") -self.CREATE_PATH = os.path.join(PLUGINS_DIR, "resolve", "create") -self.INVENTORY_PATH = os.path.join(PLUGINS_DIR, "resolve", "inventory") +self.UTILITY_SCRIPTS = os.path.join(PARENT_DIR, "resolve_utility_scripts") self.PUBLISH_PATH = os.path.join( PLUGINS_DIR, "resolve", "publish" @@ -48,6 +35,36 @@ def ls(): pass +def sync_utility_scripts(env=None): + """ Synchronizing basic utlility scripts for resolve. + + To be able to run scripts from inside `Resolve/Workspace/Scripts` menu + all scripts has to be accessible from defined folder. + """ + if not env: + env = os.environ + + us_dir = env.get("RESOLVE_UTILITY_SCRIPTS_DIR", "") + scripts = os.listdir(self.UTILITY_SCRIPTS) + + log.info(f"Utility Scripts Dir: `{self.UTILITY_SCRIPTS}`") + log.info(f"Utility Scripts: `{scripts}`") + + # make sure no script file is in folder + if next((s for s in os.listdir(us_dir)), None): + for s in os.listdir(us_dir): + path = os.path.join(us_dir, s) + log.info(f"Removing `{path}`...") + os.remove(path) + + # copy scripts into Resolve's utility scripts dir + for s in scripts: + src = os.path.join(self.UTILITY_SCRIPTS, s) + dst = os.path.join(us_dir, s) + log.info(f"Copying `{src}` to `{dst}`...") + shutil.copy2(src, dst) + + def reload_pipeline(): """Attempt to reload pipeline at run-time. @@ -86,4 +103,7 @@ def setup(env=None): if not env: env = os.environ + # synchronize resolve utility scripts + sync_utility_scripts(env) + log.info("Resolve Pype wrapper has been installed") diff --git a/pype/resolve/python_get_resolve.py b/pype/resolve/resolve_utility_scripts/python_get_resolve.py similarity index 100% rename from pype/resolve/python_get_resolve.py rename to pype/resolve/resolve_utility_scripts/python_get_resolve.py diff --git a/pype/resolve/resolve_utility_scripts/resolveapitest.py b/pype/resolve/resolve_utility_scripts/resolveapitest.py new file mode 100644 index 0000000000..e7cc32a864 --- /dev/null +++ b/pype/resolve/resolve_utility_scripts/resolveapitest.py @@ -0,0 +1,72 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# This script tests Resolve 15 scripting API on MacOS. +# We suspect an issue with import of fusionscript.so. +# To test launch Resolve Studio first and then run this script. +# The script will save a text report. +# igor@hdhead.com + +from datetime import datetime +import os +import sys +import imp + +eol = '\n' +pathLib = 'C:\\Program Files\\Blackmagic Design\\DaVinci Resolve\\fusionscript.dll' + +reportDir = "C:\\Users\\jezsc" + +# Create initial report file. It will overwrite existing! +reportName = 'Resolve_API_Report.txt' +reportPath = os.path.join(reportDir, reportName) +reportfile = open(reportPath, 'w') +reportfile.close() + + +def report(entry): + # Print to console + print entry + + # Write a report entry + reportfile = open(reportPath, 'a') + reportfile.write(entry) + reportfile.write(eol) + reportfile.close() + + +# These are the values we'll discover and save +report('Time: ' + str(datetime.now())) +report('Python Version: ' + sys.version) +report('Interpreter Path: ' + sys.executable) +report('___________________________________' + eol) + +report('If no lines follow we have likely experienced a Fatal Python Error.') + +try: + # Will the API library import? Does it exist? + smodule = imp.load_dynamic('fusionscript', pathLib) + report('Imported fusionscript.so') + + # It looks like the library imported. Can we create a resolve instance now? + try: + resolve = smodule.scriptapp('Resolve') + if 'None' in str(type(resolve)): + report('Resolve instance is created, but Resolve is not found.') + sys.exit() + if 'PyRemoteObject' in str(type(resolve)): + report('Resolve instance is created and Resolve is responsive.') + except Exception, e: + report(str(e)) + + # Let's go nuts and count how many projects are in the Project Manager + try: + projman = resolve.GetProjectManager() + projects = projman.GetProjectsInCurrentFolder() + report('Project Count: ' + str(len(projects))) + report('All is well!') + except Exception, e: + report(str(e)) + +except Exception, e: + report(str(e)) diff --git a/pype/resolve/resolve_utility_scripts/test.py b/pype/resolve/resolve_utility_scripts/test.py new file mode 100644 index 0000000000..7d32aabfe5 --- /dev/null +++ b/pype/resolve/resolve_utility_scripts/test.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3.6 +from python_get_resolve import GetResolve + +resolve = GetResolve() +PM = resolve.GetProjectManager() +P = PM.GetCurrentProject() + +print(P.GetName()) diff --git a/pype/resolve/pre_python_console_script.py b/pype/resolve/utility/pre_python_console_script.py similarity index 100% rename from pype/resolve/pre_python_console_script.py rename to pype/resolve/utility/pre_python_console_script.py diff --git a/pype/resolve/utility/python_get_resolve.py b/pype/resolve/utility/python_get_resolve.py new file mode 100644 index 0000000000..862a5bb758 --- /dev/null +++ b/pype/resolve/utility/python_get_resolve.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +""" +This file serves to return a DaVinci Resolve object +""" + +import sys + +def GetResolve(): + try: + # The PYTHONPATH needs to be set correctly for this import statement to work. + # An alternative is to import the DaVinciResolveScript by specifying absolute path (see ExceptionHandler logic) + import DaVinciResolveScript as bmd + except ImportError: + if sys.platform.startswith("darwin"): + expectedPath="/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules/" + elif sys.platform.startswith("win") or sys.platform.startswith("cygwin"): + import os + expectedPath=os.getenv('PROGRAMDATA') + "\\Blackmagic Design\\DaVinci Resolve\\Support\\Developer\\Scripting\\Modules\\" + elif sys.platform.startswith("linux"): + expectedPath="/opt/resolve/libs/Fusion/Modules/" + + # check if the default path has it... + print("Unable to find module DaVinciResolveScript from $PYTHONPATH - trying default locations") + try: + import imp + bmd = imp.load_source('DaVinciResolveScript', expectedPath+"DaVinciResolveScript.py") + except ImportError: + # No fallbacks ... report error: + print("Unable to find module DaVinciResolveScript - please ensure that the module DaVinciResolveScript is discoverable by python") + print("For a default DaVinci Resolve installation, the module is expected to be located in: "+expectedPath) + sys.exit() + + return bmd.scriptapp("Resolve")