diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..534c6d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# discard vscode lint settings +.vscode + +# discard all pyc files +*.pyc + +# Project settings +.idea/ +.vscode \ No newline at end of file diff --git a/python/app/splashscreen.py b/python/app/splashscreen.py index 5af276d..0731475 100644 --- a/python/app/splashscreen.py +++ b/python/app/splashscreen.py @@ -24,7 +24,6 @@ import os.path import subprocess import sys -import time if sys.version_info >= (3, 0): from urllib.parse import urlparse @@ -33,6 +32,7 @@ from urlparse import urlparse from urllib import urlretrieve + class Splashscreen: def __init__(self, app, parent=None): self.app = app @@ -45,48 +45,48 @@ def create(self, app_path, version): # Get data from ShotGrid project = sg.find_one( - 'Project', - [['id', 'is', current_context.project.get('id')]], - ['billboard', 'name', 'sg_working_title'] + "Project", + [["id", "is", current_context.project.get("id")]], + ["billboard", "name", "sg_working_title"], ) # Check if project has billboard - if project.get('billboard') is None: + if project.get("billboard") is None: return - billboard_url = project.get('billboard').get('url') + billboard_url = project.get("billboard").get("url") - project_name = project.get('name') - if project.get('sg_working_title') is not None: - project_name = project.get('sg_working_title') + project_name = project.get("name") + if project.get("sg_working_title") is not None: + project_name = project.get("sg_working_title") # TODO check default value splash_file = self.app.get_template("splash_screen_template").apply_fields({}) directory, filename = os.path.split(splash_file) filename, extension = os.path.splitext(filename) f, ext = os.path.splitext(urlparse(billboard_url).path) - tmp_splash_file = os.path.join(directory, filename + '_tmp' + ext) - tmp_splash_png = os.path.join(directory, filename + '_tmp.png') + tmp_splash_file = os.path.join(directory, filename + "_tmp" + ext) + tmp_splash_png = os.path.join(directory, filename + "_tmp.png") - self.logger.debug('Splash file path: {}'.format(splash_file)) + self.logger.debug("Splash file path: {}".format(splash_file)) c_oiiotool = self.app.get_setting("oiiotool") - if c_oiiotool is not '' and os.path.exists(c_oiiotool): + if c_oiiotool is not "" and os.path.exists(c_oiiotool): oiiotool = c_oiiotool else: - oiiotool = os.path.join(os.path.dirname(app_path), 'hoiiotool.exe') + oiiotool = os.path.join(os.path.dirname(app_path), "hoiiotool.exe") render_splash = True # Check if exists and image source is the same if os.path.exists(splash_file): info = subprocess.Popen( - [oiiotool, '--info', '-v', splash_file], + [oiiotool, "--info", "-v", splash_file], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) info_out, info_err = info.communicate() - info_data = info_out.decode("utf-8").split('\n') + info_data = info_out.decode("utf-8").split("\n") for data in info_data: if "ImageDescription" in data: if urlparse(billboard_url).path in data: @@ -95,56 +95,112 @@ def create(self, app_path, version): info.wait() if render_splash: - self.logger.debug('Creating new splash file.') - self.__create_splash(oiiotool, '800x415', 'white', 312, '+445+172', billboard_url, tmp_splash_file, - tmp_splash_png, splash_file, project_name, version) + self.logger.debug("Creating new splash file.") + self.__create_splash( + oiiotool, + "800x415", + "white", + 312, + "+445+172", + billboard_url, + tmp_splash_file, + tmp_splash_png, + splash_file, + project_name, + version, + ) else: - self.logger.debug('Splash file exists, skipping creation.') + self.logger.debug("Splash file exists, skipping creation.") try: - self.logger.debug('Setting splash file and message.') + self.logger.debug("Setting splash file and message.") os.environ["HOUDINI_SPLASH_FILE"] = splash_file houdini = os.path.splitext(os.path.split(app_path)[1])[0] - houdini_version = '' - if 'core' in houdini: - houdini_version = 'Core' - elif 'fx' in houdini: - houdini_version = 'FX' - os.environ["HOUDINI_SPLASH_MESSAGE"] = 'Houdini {type} {version}\n{project}'\ - .format(type=houdini_version, version=version, project=project.get('name')) + houdini_version = "" + if "core" in houdini: + houdini_version = "Core" + elif "fx" in houdini: + houdini_version = "FX" + os.environ["HOUDINI_SPLASH_MESSAGE"] = ( + "Houdini {type} {version}\n{project}".format( + type=houdini_version, version=version, project=project.get("name") + ) + ) except Exception as error: self.logger.error("Something went wrong %s..." % str(error)) - def __create_splash(self, oiiotool, resolution, logo_type, logo_width, logo_position, image_url, tmp_splash_file, - tmp_splash_png, splash_file, project_name, version): - logo = os.path.join(self.app.disk_location, 'resources', 'logos', 'Houdini_{}_color.png'.format(logo_type)) + def __create_splash( + self, + oiiotool, + resolution, + logo_type, + logo_width, + logo_position, + image_url, + tmp_splash_file, + tmp_splash_png, + splash_file, + project_name, + version, + ): + logo = os.path.join( + self.app.disk_location, + "resources", + "logos", + "Houdini_{}_color.png".format(logo_type), + ) try: + splash_dir = os.path.dirname(splash_file) + if not os.path.isdir(splash_dir): + os.mkdir(splash_dir) + # Download file urlretrieve(image_url, tmp_splash_file) # Add alpha and resize - process_bg = subprocess.Popen([oiiotool, tmp_splash_file, '--ch', 'R,G,B,A=1.0', '--resize', resolution, - '-o', tmp_splash_png]) + process_bg = subprocess.Popen( + [ + oiiotool, + tmp_splash_file, + "--ch", + "R,G,B,A=1.0", + "--resize", + resolution, + "-o", + tmp_splash_png, + ] + ) process_bg.wait() # Add logo - cmd = [oiiotool, - logo, '--resize', '{}x0'.format(logo_width), '--origin', logo_position, - tmp_splash_png, '--over', - ] + cmd = [ + oiiotool, + logo, + "--resize", + "{}x0".format(logo_width), + "--origin", + logo_position, + tmp_splash_png, + "--over", + ] # Add text if "19.5" in version: - cmd.extend(['--text:x=443:y=265:size=28:font=Arial', project_name]) + cmd.extend(["--text:x=443:y=265:size=28:font=Arial", project_name]) # Set output - cmd.extend([ - '--caption', urlparse(image_url).path, - '--ch', 'R,G,B', - '-o', splash_file - ]) + cmd.extend( + [ + "--caption", + urlparse(image_url).path, + "--ch", + "R,G,B", + "-o", + splash_file, + ] + ) process = subprocess.Popen( cmd, @@ -158,7 +214,7 @@ def __create_splash(self, oiiotool, resolution, logo_type, logo_width, logo_posi if stderr: err = stderr.decode("utf-8") - if 'WARNING' in err: + if "WARNING" in err: self.logger.warning(err) else: self.logger.error(err) @@ -171,5 +227,7 @@ def __create_splash(self, oiiotool, resolution, logo_type, logo_width, logo_posi return True except Exception as error: - self.logger.error("An error occurred while saving the billboard image. {}".format(error)) + self.logger.error( + "An error occurred while saving the billboard image. {}".format(error) + ) return False