def _export_layer(self, node, export_layer_path, active_doc): krita_app = Krita.instance() active_doc_bounds = active_doc.rootNode().bounds() # old versions of Krita had a different signature for this function # unfortunately since this function is not a python one we cannot # inspect it, so we do have to check the Krita version to know # how to approach this export if is_version_older(krita_app.version(), "4.2.0"): node.save(export_layer_path, active_doc.width(), active_doc.height()) else: node.save( export_layer_path, active_doc.width(), active_doc.height(), InfoObject(), active_doc_bounds, )
def _ensure_extension_up_to_date(): """ Ensure the basic adobe extension is installed in the OS-specific location and that it matches the extension bundled with the installed engine. """ extension_name = "com.sg.basic.ps" # the CEP install directory is OS-specific if sys.platform == "win32": app_data = os.getenv("APPDATA") elif sys.platform == "darwin": app_data = os.path.expanduser("~/Library/Application Support") else: raise Exception("This engine only runs on OSX & Windows.") # the adobe CEP install directory. This is where the extension is stored. adobe_cep_dir = os.path.join(app_data, "Adobe", "CEP", "extensions") logger.debug("Adobe CEP extension dir: %s" % (adobe_cep_dir, )) # make sure the directory exists. create it if not. if not os.path.exists(adobe_cep_dir): logger.debug("Extension folder does not exist. Creating it.") ensure_folder_exists(adobe_cep_dir) # get the path to the installed engine's .zxp file. the extension_name file i # is 3 levels up from this file. bundled_ext_path = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, "%s.zxp" % (extension_name, ))) if not os.path.exists(bundled_ext_path): raise Exception("Could not find bundled extension. Expected: '%s'" % (bundled_ext_path, )) # now get the version of the bundled extension version_file = "%s.version" % (extension_name, ) bundled_version_file_path = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, version_file)) if not os.path.exists(bundled_version_file_path): raise Exception("Could not find bundled version file. Expected: '%s'" % (bundled_version_file_path, )) # get the bundled version from the version file with open(bundled_version_file_path, "r") as bundled_version_file: bundled_version = bundled_version_file.read().strip() # check to see if the extension is installed in the CEP extensions directory installed_ext_dir = os.path.join(adobe_cep_dir, extension_name) # if not installed, install it if not os.path.exists(installed_ext_dir): logger.debug("Extension not installed. Installing it!") _install_extension(bundled_ext_path, installed_ext_dir) return # ---- already installed, check for udpate logger.debug("Bundled extension's version is: %s" % (bundled_version, )) # get the version from the installed extension's build_version.txt file installed_version_file_path = os.path.join(installed_ext_dir, version_file) logger.debug("The installed version file path is: %s" % (installed_version_file_path, )) if not os.path.exists(installed_version_file_path): raise Exception("Could not find installed version file '%s'" % (installed_version_file_path, )) # the version of the installed extension installed_version = None # get the installed version from the installed version info file with open(installed_version_file_path, "r") as installed_version_file: logger.debug("Extracting the version from the installed extension.") installed_version = installed_version_file.read().strip() if installed_version is None: raise Exception( "Could not determine version for the installed extension.") logger.debug("Installed extension's version is: %s" % (installed_version, )) from sgtk.util.version import is_version_older if bundled_version != "dev" and installed_version != "dev": if (bundled_version == installed_version or is_version_older(bundled_version, installed_version)): # the bundled version is the same or older. or it is a 'dev' build # which means always install that one. logger.debug( "Installed extension is equal to or newer than the bundled " "build. Nothing to do!") return # ---- extension in engine is newer. update! if bundled_version == "dev": logger.debug("Installing the bundled 'dev' version of the extension.") else: logger.debug( "Bundled extension build is newer than the installed extension " + "build! Updating...") # move the installed extension to the backup directory backup_ext_dir = tempfile.mkdtemp() logger.debug("Backing up the installed extension to: %s" % (backup_ext_dir, )) try: backup_folder(installed_ext_dir, backup_ext_dir) except Exception: shutil.rmtree(backup_ext_dir) raise Exception("Unable to create backup during extension update.") # now remove the installed extension logger.debug("Removing the installed extension directory...") try: shutil.rmtree(installed_ext_dir) except Exception: # try to restore the backup move_folder(backup_ext_dir, installed_ext_dir) raise Exception("Unable to remove the old extension during update.") # install the bundled .zxp file _install_extension(bundled_ext_path, installed_ext_dir) # if we're here, the install was successful. remove the backup try: logger.debug("Install success. Removing the backed up extension.") shutil.rmtree(backup_ext_dir) except Exception: # can't remove temp dir. no biggie. pass
def __ensure_extension_up_to_date(logger): """ Ensure the basic Adobe extension is installed in the OS-specific location and that it matches the extension bundled with the installed engine. """ extension_name = environment_utils.EXTENSION_NAME # the Adobe CEP install directory. This is where the extension is stored. adobe_cep_dir = environment_utils.get_adobe_cep_dir() logger.debug("Adobe CEP extension dir: %s" % (adobe_cep_dir, )) installed_ext_dir = environment_utils.get_extension_install_directory() # make sure the directory exists. create it if not. if not os.path.exists(adobe_cep_dir): logger.debug("Extension folder does not exist. Creating it.") ensure_folder_exists(adobe_cep_dir) # get the path to the installed engine's .zxp file. bundled_ext_path = os.path.abspath( os.path.join( os.path.dirname(__file__), os.path.pardir, os.path.pardir, "%s.zxp" % (extension_name, ), )) if not os.path.exists(bundled_ext_path): raise sgtk.TankError( "Could not find bundled extension. Expected: '%s'" % (bundled_ext_path, )) # now get the version of the bundled extension version_file = "%s.version" % (extension_name, ) bundled_version_file_path = os.path.abspath( os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir, version_file)) if not os.path.exists(bundled_version_file_path): raise sgtk.TankError( "Could not find bundled version file. Expected: '%s'" % (bundled_version_file_path, )) # get the bundled version from the version file with open(bundled_version_file_path, "r") as bundled_version_file: bundled_version = bundled_version_file.read().strip() # check to see if the extension is installed in the CEP extensions directory # if not installed, install it if not os.path.exists(installed_ext_dir): logger.debug("Extension not installed. Installing it!") __install_extension(bundled_ext_path, installed_ext_dir, logger) return # ---- already installed, check for udpate logger.debug("Bundled extension's version is: %s" % (bundled_version, )) # get the version from the installed extension's build_version.txt file installed_version_file_path = os.path.join(installed_ext_dir, version_file) logger.debug("The installed version file path is: %s" % (installed_version_file_path, )) if not os.path.exists(installed_version_file_path): logger.debug( "Could not find installed version file '%s'. Reinstalling" % (installed_version_file_path, )) __install_extension(bundled_ext_path, installed_ext_dir, logger) return # the version of the installed extension installed_version = None # get the installed version from the installed version info file with open(installed_version_file_path, "r") as installed_version_file: logger.debug("Extracting the version from the installed extension.") installed_version = installed_version_file.read().strip() if installed_version is None: logger.debug( "Could not determine version for the installed extension. Reinstalling" ) __install_extension(bundled_ext_path, installed_ext_dir, logger) return logger.debug("Installed extension's version is: %s" % (installed_version, )) from sgtk.util.version import is_version_older if bundled_version != "dev" and installed_version != "dev": if bundled_version == installed_version or is_version_older( bundled_version, installed_version): # the bundled version is the same or older. or it is a 'dev' build # which means always install that one. logger.debug( "Installed extension is equal to or newer than the bundled " "build. Nothing to do!") return # ---- extension in engine is newer. update! if bundled_version == "dev": logger.debug("Installing the bundled 'dev' version of the extension.") else: logger.debug( ("Bundled extension build is newer than the installed extension " "build! Updating...")) # install the bundled .zxp file __install_extension(bundled_ext_path, installed_ext_dir, logger)