From 178594a515a2c7150ee7dd954b00513e623f93b4 Mon Sep 17 00:00:00 2001 From: Diego Garcia Huerta Date: Fri, 19 Jun 2020 21:55:06 +1000 Subject: [PATCH] black formatting --- engine.py | 63 +++++----------- .../tk-harmony_scene_operations.py | 11 +-- hooks/tk-multi-loader2/tk-harmony_actions.py | 6 +- hooks/tk-multi-publish2/basic/collector.py | 23 ++---- .../basic/publish_session.py | 32 +++------ .../basic/start_version_control.py | 33 +++------ .../scene_operation_tk-harmony.py | 18 +---- python/__init__.py | 2 +- python/tk_harmony/application.py | 65 +++++------------ python/tk_harmony/client.py | 71 +++++-------------- python/tk_harmony/menu_generation.py | 27 ++----- startup/bootstrap.py | 3 +- 12 files changed, 89 insertions(+), 265 deletions(-) diff --git a/engine.py b/engine.py index 928c650..6cc1025 100644 --- a/engine.py +++ b/engine.py @@ -107,9 +107,7 @@ def refresh_engine(scene_name, prev_context): try: # could not detect context from path, will use the project context # for menus if it exists - ctx = engine.sgtk.context_from_entity_dictionary( - engine.context.project - ) + ctx = engine.sgtk.context_from_entity_dictionary(engine.context.project) message = ( "Shotgun Harmony Engine could not detect " "the context\n from the project loaded. " @@ -182,9 +180,7 @@ def show_message(self, msg, level="info"): dlg.setIcon(level_icon[level]) dlg.setText(msg) dlg.setWindowTitle("Shotgun Harmony Engine") - dlg.setWindowFlags( - dlg.windowFlags() | QtCore.Qt.WindowStaysOnTopHint - ) + dlg.setWindowFlags(dlg.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) dlg.show() dlg.exec_() @@ -229,9 +225,7 @@ def __toggle_debug_logging(self): Toggles global debug logging on and off in the log manager. This will affect all logging across all of toolkit. """ - self.logger.debug( - "calling Harmony with debug: %s" % LogManager().global_debug - ) + self.logger.debug("calling Harmony with debug: %s" % LogManager().global_debug) # flip debug logging LogManager().global_debug = not LogManager().global_debug @@ -268,9 +262,7 @@ def __register_open_log_folder_command(self): { "short_name": "open_log_folder", "icon": icon_path, - "description": ( - "Opens the folder where log files are " "being stored." - ), + "description": ("Opens the folder where log files are " "being stored."), "type": "context_menu", }, ) @@ -382,15 +374,10 @@ def warn_dcc_app_version(self): # split off the major version number - accomodate complex # version strings and decimals: major_version_number_str = app_version_str.split(".")[0] - if ( - major_version_number_str - and major_version_number_str.isdigit() - ): + if major_version_number_str and major_version_number_str.isdigit(): # check against the compatibility_dialog_min_version # setting - min_ver = self.get_setting( - "compatibility_dialog_min_version" - ) + min_ver = self.get_setting("compatibility_dialog_min_version") if int(major_version_number_str) < min_ver: show_warning_dlg = False @@ -433,9 +420,7 @@ def pre_app_init(self): self.logger.debug("port: %s", port) application_client_class = self.tk_harmony.application.Application - self.logger.debug( - " application_client_class: %s " % application_client_class - ) + self.logger.debug(" application_client_class: %s " % application_client_class) self._dcc_app = application_client_class( self, parent=self._qt_app_central_widget, host=host, port=int(port) @@ -443,12 +428,8 @@ def pre_app_init(self): self.logger.debug(" self._dcc_app: %s " % self._dcc_app) self._dcc_app.register_callback("SHOW_MENU", self.on_show_menu) - self._dcc_app.register_callback( - "NEW_PROJECT_CREATED", self.on_new_project_created - ) - self._dcc_app.register_callback( - "PROJECT_OPENED", self.on_project_opened - ) + self._dcc_app.register_callback("NEW_PROJECT_CREATED", self.on_new_project_created) + self._dcc_app.register_callback("PROJECT_OPENED", self.on_project_opened) self._dcc_app.register_callback("PING", self.on_ping) self._dcc_app.register_callback("QUIT", self.on_app_quit) @@ -482,9 +463,7 @@ def create_shotgun_menu(self, disabled=False): if self.has_ui: # create our menu handler self.logger.debug("self._menu_generator: %s", self._menu_generator) - self._menu_generator = self.tk_harmony.MenuGenerator( - self, self._menu_name - ) + self._menu_generator = self.tk_harmony.MenuGenerator(self, self._menu_name) self.logger.debug("self._menu_generator: %s", self._menu_generator) self._qt_app.setActiveWindow(self._menu_generator.menu_handle) @@ -524,7 +503,7 @@ def init_qt_app(self): self._qt_app_main_window.setCentralWidget(self._qt_app_central_widget) self._qt_app.setQuitOnLastWindowClosed(False) - # Make the QApplication use the dark theme. Must be called after the + # Make the QApplication use the dark theme. Must be called after the # QApplication is instantiated self._initialize_dark_look_and_feel() @@ -605,9 +584,7 @@ def _run_app_instance_commands(self): if app_instance: # Add entry 'command name: command function' to the command # dictionary of this app instance. - cmd_dict = app_instance_commands.setdefault( - app_instance.instance_name, {} - ) + cmd_dict = app_instance_commands.setdefault(app_instance.instance_name, {}) cmd_dict[cmd_name] = value["callback"] # Run the series of app instance commands listed in the @@ -657,9 +634,7 @@ def _run_app_instance_commands(self): command_function() else: - known_commands = ", ".join( - "'%s'" % name for name in cmd_dict - ) + known_commands = ", ".join("'%s'" % name for name in cmd_dict) self.logger.warning( "%s configuration setting 'run_at_startup' " "requests app '%s' unknown command '%s'. " @@ -707,9 +682,7 @@ def _emit_log_message(self, handler, record): # where "basename" is the leaf part of the logging record name, # for example "tk-multi-shotgunpanel" or "qt_importer". if record.levelno < logging.INFO: - formatter = logging.Formatter( - "Debug: Shotgun %(basename)s: %(message)s" - ) + formatter = logging.Formatter("Debug: Shotgun %(basename)s: %(message)s") else: formatter = logging.Formatter("Shotgun %(basename)s: %(message)s") @@ -750,9 +723,7 @@ def close_windows(self): dialog.close() except Exception as exception: traceback.print_exc() - self.logger.error( - "Cannot close dialog %s: %s", dialog_window_title, exception - ) + self.logger.error("Cannot close dialog %s: %s", dialog_window_title, exception) # -------------------- # callbacks @@ -779,9 +750,7 @@ def on_show_menu(self, **kwargs): def on_new_project_created(self, **kwargs): path = kwargs.get("path") - change_context = self.get_setting( - "change_context_on_new_project", False - ) + change_context = self.get_setting("change_context_on_new_project", False) if change_context: refresh_engine(path, self.context) else: diff --git a/hooks/tk-multi-breakdown/tk-harmony_scene_operations.py b/hooks/tk-multi-breakdown/tk-harmony_scene_operations.py index b91ce9b..f0458b2 100644 --- a/hooks/tk-multi-breakdown/tk-harmony_scene_operations.py +++ b/hooks/tk-multi-breakdown/tk-harmony_scene_operations.py @@ -58,9 +58,7 @@ def scan_scene(self): for read_node in read_nodes: ref_path = dcc_app.get_node_metadata(read_node, attr_name) if ref_path: - ref_path = sgtk.util.shotgun_path.ShotgunPath.from_current_os_path( - ref_path - ) + ref_path = sgtk.util.shotgun_path.ShotgunPath.from_current_os_path(ref_path) refs.append( { @@ -79,9 +77,7 @@ def scan_scene(self): ref_path = dcc_app.get_scene_metadata(audio_metadata_name) if ref_path: - ref_path = sgtk.util.shotgun_path.ShotgunPath.from_current_os_path( - ref_path - ) + ref_path = sgtk.util.shotgun_path.ShotgunPath.from_current_os_path(ref_path) refs.append( { @@ -120,6 +116,5 @@ def update(self, items): if items: engine.show_busy( - "tk-multi-breakdown", - "Updating functionality has not been implemented yet.", + "tk-multi-breakdown", "Updating functionality has not been implemented yet." ) diff --git a/hooks/tk-multi-loader2/tk-harmony_actions.py b/hooks/tk-multi-loader2/tk-harmony_actions.py index ef2b04f..db94561 100644 --- a/hooks/tk-multi-loader2/tk-harmony_actions.py +++ b/hooks/tk-multi-loader2/tk-harmony_actions.py @@ -80,8 +80,7 @@ def generate_actions(self, sg_publish_data, actions, ui_area): app = self.parent app.log_debug( "Generate actions called for UI element %s. " - "Actions: %s. Publish Data: %s" - % (ui_area, actions, sg_publish_data) + "Actions: %s. Publish Data: %s" % (ui_area, actions, sg_publish_data) ) published_file_type = sg_publish_data["published_file_type"]["name"] @@ -93,8 +92,7 @@ def generate_actions(self, sg_publish_data, actions, ui_area): for action in actions: action_instances.append( { - "name": "Import %s as %s" - % (published_file_type, action.capitalize()), + "name": "Import %s as %s" % (published_file_type, action.capitalize()), "params": { "action": action, "published_file_type": published_file_type, diff --git a/hooks/tk-multi-publish2/basic/collector.py b/hooks/tk-multi-publish2/basic/collector.py index 425400a..c52934d 100644 --- a/hooks/tk-multi-publish2/basic/collector.py +++ b/hooks/tk-multi-publish2/basic/collector.py @@ -89,29 +89,22 @@ def get_export_path(self, settings): work_template = None work_template_setting = settings.get("Work Template") if work_template_setting: - work_template = publisher.engine.get_template_by_name( - work_template_setting.value - ) + work_template = publisher.engine.get_template_by_name(work_template_setting.value) - self.logger.debug( - "Work template defined for Toon Boom Harmony collection." - ) + self.logger.debug("Work template defined for Toon Boom Harmony collection.") work_export_template = None work_export_template_setting = settings.get("Work Export Template") if work_export_template_setting: self.logger.debug( - "Work Export template settings: %s" - % work_export_template_setting + "Work Export template settings: %s" % work_export_template_setting ) work_export_template = publisher.engine.get_template_by_name( work_export_template_setting.value ) - self.logger.debug( - "Work Export template defined for Toon Boom Harmony collection." - ) + self.logger.debug("Work Export template defined for Toon Boom Harmony collection.") if work_export_template and work_template: path = publisher.engine.app.get_current_project_path() @@ -150,9 +143,7 @@ def collect_current_harmony_session(self, settings, parent_item): ) # get the icon path to display for this item - icon_path = os.path.join( - self.disk_location, os.pardir, "icons", "session.png" - ) + icon_path = os.path.join(self.disk_location, os.pardir, "icons", "session.png") session_item.set_icon_from_path(icon_path) # if a work template is defined, add it to the item properties so @@ -160,9 +151,7 @@ def collect_current_harmony_session(self, settings, parent_item): work_template_setting = settings.get("Work Template") if work_template_setting: - work_template = publisher.engine.get_template_by_name( - work_template_setting.value - ) + work_template = publisher.engine.get_template_by_name(work_template_setting.value) # store the template on the item for use by publish plugins. we # can't evaluate the fields here because there's no guarantee the diff --git a/hooks/tk-multi-publish2/basic/publish_session.py b/hooks/tk-multi-publish2/basic/publish_session.py index bd40d54..c788612 100644 --- a/hooks/tk-multi-publish2/basic/publish_session.py +++ b/hooks/tk-multi-publish2/basic/publish_session.py @@ -46,9 +46,7 @@ def description(self): contain simple html for formatting. """ - loader_url = ( - "https://support.shotgunsoftware.com/hc/en-us/articles/219033078" - ) + loader_url = "https://support.shotgunsoftware.com/hc/en-us/articles/219033078" return """ Publishes the file to Shotgun. A Publish entry will be @@ -121,9 +119,7 @@ def settings(self): # inherit the settings from the base publish plugin base_settings = super(HarmonySessionPublishPlugin, self).settings or {} - base_settings["File Types"]["default"].append( - ["Harmony Project File", "xstage"] - ) + base_settings["File Types"]["default"].append(["Harmony Project File", "xstage"]) # settings specific to this class harmony_publish_settings = { @@ -191,13 +187,10 @@ def accept(self, settings, item): # provide a save button. the session will need to be saved before # validation will succeed. self.logger.warn( - "The Harmony session has not been saved.", - extra=_get_save_as_action(), + "The Harmony session has not been saved.", extra=_get_save_as_action() ) - self.logger.info( - "Harmony '%s' plugin accepted the current session." % (self.name,) - ) + self.logger.info("Harmony '%s' plugin accepted the current session." % (self.name,)) return {"accepted": True, "checked": True} def validate(self, settings, item): @@ -238,22 +231,18 @@ def validate(self, settings, item): if work_template: if not work_template.validate(path): self.logger.warning( - "The current session does not match the configured work " - "file template.", + "The current session does not match the configured work " "file template.", extra={ "action_button": { "label": "Save File", - "tooltip": "Save the current session to a " - "different file name", + "tooltip": "Save the current session to a " "different file name", # will launch wf2 if configured "callback": _get_save_as_action(), } }, ) else: - self.logger.debug( - "Work template configured and matches session file." - ) + self.logger.debug("Work template configured and matches session file.") else: self.logger.debug("No work template configured.") @@ -331,9 +320,7 @@ def publish(self, settings, item): # let the base class register the publish super(HarmonySessionPublishPlugin, self).publish(settings, item) - item.properties.sg_publish_path = item.properties.sg_publish_data[ - "path" - ]["local_path"] + item.properties.sg_publish_path = item.properties.sg_publish_data["path"]["local_path"] def finalize(self, settings, item): """ @@ -381,8 +368,7 @@ def _copy_work_to_publish(self, settings, item): work_template = item.properties.get("work_template") if not work_template: self.logger.debug( - "No work template set on the item. " - "Skipping copy file to publish location." + "No work template set on the item. " "Skipping copy file to publish location." ) return diff --git a/hooks/tk-multi-publish2/basic/start_version_control.py b/hooks/tk-multi-publish2/basic/start_version_control.py index 388e7a7..b0abbf0 100644 --- a/hooks/tk-multi-publish2/basic/start_version_control.py +++ b/hooks/tk-multi-publish2/basic/start_version_control.py @@ -34,9 +34,7 @@ def icon(self): """ # look for icon one level up from this hook's folder in "icons" folder - return os.path.join( - self.disk_location, os.pardir, "icons", "version_up.png" - ) + return os.path.join(self.disk_location, os.pardir, "icons", "version_up.png") @property def name(self): @@ -131,12 +129,9 @@ def accept(self, settings, item): version_number = self._get_version_number(path, item) if version_number is not None: self.logger.info( - "Harmony '%s' plugin rejected the current session..." - % (self.name,) - ) - self.logger.info( - " There is already a version number in the file..." + "Harmony '%s' plugin rejected the current session..." % (self.name,) ) + self.logger.info(" There is already a version number in the file...") self.logger.info(" Harmony file path: %s" % (path,)) return {"accepted": False} else: @@ -144,8 +139,7 @@ def accept(self, settings, item): # provide a save button. the session will need to be saved before # validation will succeed. self.logger.warn( - "The Harmony session has not been saved.", - extra=_get_save_as_action(), + "The Harmony session has not been saved.", extra=_get_save_as_action() ) self.logger.info( @@ -191,8 +185,7 @@ def validate(self, settings, item): version_path = publisher.util.get_version_path(path, "v001") if os.path.exists(version_path): error_msg = ( - "A file already exists with a version number. Please " - "choose another name." + "A file already exists with a version number. Please " "choose another name." ) self.logger.error(error_msg, extra=_get_save_as_action()) raise Exception(error_msg) @@ -223,9 +216,7 @@ def publish(self, settings, item): # save to the new version path _save_session(version_path) - self.logger.info( - "A version number has been added to the Harmony file..." - ) + self.logger.info("A version number has been added to the Harmony file...") self.logger.info(" Harmony file path: %s" % (version_path,)) def finalize(self, settings, item): @@ -262,23 +253,17 @@ def _get_version_number(self, path, item): work_template = item.properties.get("work_template") if work_template: if work_template.validate(path): - self.logger.debug( - "Using work template to determine version number." - ) + self.logger.debug("Using work template to determine version number.") work_fields = work_template.get_fields(path) if "version" in work_fields: version_number = work_fields.get("version") else: self.logger.debug("Work template did not match path") else: - self.logger.debug( - "Work template unavailable for version extraction." - ) + self.logger.debug("Work template unavailable for version extraction.") if version_number is None: - self.logger.debug( - "Using path info hook to determine version number." - ) + self.logger.debug("Using path info hook to determine version number.") version_number = publisher.util.get_version_number(path) return version_number diff --git a/hooks/tk-multi-workfiles2/scene_operation_tk-harmony.py b/hooks/tk-multi-workfiles2/scene_operation_tk-harmony.py index 9d3e5a9..922adcc 100644 --- a/hooks/tk-multi-workfiles2/scene_operation_tk-harmony.py +++ b/hooks/tk-multi-workfiles2/scene_operation_tk-harmony.py @@ -32,14 +32,7 @@ class SceneOperation(HookClass): pre_save_context = None def execute( - self, - operation, - file_path, - context, - parent_action, - file_version, - read_only, - **kwargs + self, operation, file_path, context, parent_action, file_version, read_only, **kwargs ): """ Main hook entry point @@ -86,10 +79,7 @@ def execute( app.log_debug("app context: %s" % app.context) app.log_debug("engine context: %s" % engine.context) app.log_debug("parent_action: %s" % parent_action) - app.log_debug( - "SceneOperation.pre_save_context: %s" - % SceneOperation.pre_save_context - ) + app.log_debug("SceneOperation.pre_save_context: %s" % SceneOperation.pre_save_context) app.log_debug("file_version: %s" % file_version) app.log_debug("read_only: %s" % read_only) app.log_debug("kwargs: %s" % kwargs) @@ -128,9 +118,7 @@ def execute( source_file = dcc_app.get_current_project_path() app.log_debug("source_file: %s" % source_file) app.log_debug("target_file: %s" % file_path) - dcc_app.save_project_as( - file_path, source_file=source_file, open_project=True - ) + dcc_app.save_project_as(file_path, source_file=source_file, open_project=True) elif operation == "reset": if parent_action not in ("new_file", "open_file"): diff --git a/python/__init__.py b/python/__init__.py index 30ba3f6..2d7047d 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -1 +1 @@ -from . import tk_harmony \ No newline at end of file +from . import tk_harmony diff --git a/python/tk_harmony/application.py b/python/tk_harmony/application.py index b57166c..147ebb1 100644 --- a/python/tk_harmony/application.py +++ b/python/tk_harmony/application.py @@ -26,9 +26,7 @@ def __init__(self, engine, parent=None, host=None, port=None): def connect(self): while not self.is_connected(): self.connect_to_host() - self.engine.logger.debug( - "Waiting for server: %s" % self.connection_status() - ) + self.engine.logger.debug("Waiting for server: %s" % self.connection_status()) def broadcast_event(self, event_name): self.send_command(event_name) @@ -100,15 +98,11 @@ def is_startup_project(self): return result def execute(self, statement_str): - result = self.send_and_receive_command( - "EXECUTE_STATEMENT", statement=statement_str - ) + result = self.send_and_receive_command("EXECUTE_STATEMENT", statement=statement_str) return result def extract_thumbnail(self, filename): - result = self.send_and_receive_command( - "EXTRACT_THUMBNAIL", path=filename - ) + result = self.send_and_receive_command("EXTRACT_THUMBNAIL", path=filename) return result # file management @@ -127,11 +121,7 @@ def new_file(self, app, context): app.log_debug("Needs saving: %s" % needs_saving) app_settings = sgtk.platform.find_app_settings( - app.engine.name, - app.name, - app.sgtk, - context, - app.engine.instance_name, + app.engine.name, app.name, app.sgtk, context, app.engine.instance_name ) settings = None @@ -142,11 +132,9 @@ def new_file(self, app, context): if not settings: raise TankError( - "Could not find the settings for app: %s context: %s" - % (app.name, context) + "Could not find the settings for app: %s context: %s" % (app.name, context) ) - # check if we have a different template to copy from than the original template_project_folder = settings.get("template_project_folder", None) if template_project_folder and os.path.exists(template_project_folder): @@ -185,9 +173,7 @@ def new_file(self, app, context): version += 1 # Harmony saves projects in folders - destination_folder, destination_filename = os.path.split( - destination_path - ) + destination_folder, destination_filename = os.path.split(destination_path) destination_folder = normpath(destination_folder).replace("\\", "/") app.log_debug("Destination_folder: %s" % destination_folder) app.log_debug("Destination_filename: %s" % destination_filename) @@ -223,14 +209,10 @@ def save_project_as(self, target_file, source_file=None, open_project=True): source_file = self.get_current_project_path() source_folder, source_filename = os.path.split(source_file) - source_filename_file, source_filename_ext = os.path.splitext( - source_filename - ) + source_filename_file, source_filename_ext = os.path.splitext(source_filename) target_folder, target_filename = os.path.split(target_file) - target_filename_file, target_filename_ext = os.path.splitext( - target_filename - ) + target_filename_file, target_filename_ext = os.path.splitext(target_filename) # we need to ignore all the other versions within the # folder of this WIP version except for the ones that @@ -257,9 +239,7 @@ def save_project_as(self, target_file, source_file=None, open_project=True): rename_files[source_filename] = target_filename if source_filename_file + ".aux" != target_filename_file + ".aux": - rename_files[source_filename_file + ".aux"] = ( - target_filename_file + ".aux" - ) + rename_files[source_filename_file + ".aux"] = target_filename_file + ".aux" # copy the folder to target # Note that I would happily use shutil.copytree, but we need to rename @@ -287,8 +267,7 @@ def save_project_as(self, target_file, source_file=None, open_project=True): ) self.engine.logger.debug( - "Copied source folder '%s' to folder '%s'." - % (source_folder, target_folder) + "Copied source folder '%s' to folder '%s'." % (source_folder, target_folder) ) if open_project: @@ -300,9 +279,7 @@ def get_start_frame(self): return result def set_start_frame(self, start_frame): - result = self.send_and_receive_command( - "SET_START_FRAME", start_frame=start_frame - ) + result = self.send_and_receive_command("SET_START_FRAME", start_frame=start_frame) return result def get_stop_frame(self): @@ -310,9 +287,7 @@ def get_stop_frame(self): return result def set_stop_frame(self, stop_frame): - result = self.send_and_receive_command( - "SET_STOP_FRAME", stop_frame=stop_frame - ) + result = self.send_and_receive_command("SET_STOP_FRAME", stop_frame=stop_frame) return result def get_frame_range(self): @@ -330,9 +305,7 @@ def get_frame_count(self): return result def set_frame_count(self, frame_count): - result = self.send_and_receive_command( - "SET_FRAME_COUNT", frame_count=frame_count - ) + result = self.send_and_receive_command("SET_FRAME_COUNT", frame_count=frame_count) return result # scene editing / management @@ -357,9 +330,7 @@ def import_project_resource(self, path, action): return result def get_nodes_of_type(self, node_types): - result = self.send_and_receive_command( - "GET_NODES_OF_TYPE", node_types=node_types - ) + result = self.send_and_receive_command("GET_NODES_OF_TYPE", node_types=node_types) return result def get_node_metadata(self, node, attr_name): @@ -369,15 +340,11 @@ def get_node_metadata(self, node, attr_name): return result def get_scene_metadata(self, attr_name): - result = self.send_and_receive_command( - "GET_SCENE_METADATA", attr_name=attr_name - ) + result = self.send_and_receive_command("GET_SCENE_METADATA", attr_name=attr_name) return result def get_columns_of_type(self, column_type): - result = self.send_and_receive_command( - "GET_COLUMNS_OF_TYPE", column_type=column_type - ) + result = self.send_and_receive_command("GET_COLUMNS_OF_TYPE", column_type=column_type) return result def get_sound_column_filenames(self, column_name): diff --git a/python/tk_harmony/client.py b/python/tk_harmony/client.py index 7b93dc4..52bfd65 100644 --- a/python/tk_harmony/client.py +++ b/python/tk_harmony/client.py @@ -87,8 +87,7 @@ def connect_to_host(self, host=None, port=None): if self.is_connected(): logger.warning( - "Connection already existed , removing connection to %s %s " - % (host, port) + "Connection already existed , removing connection to %s %s " % (host, port) ) self.connection.abort() @@ -97,9 +96,7 @@ def connect_to_host(self, host=None, port=None): if not self.connection.waitForConnected(1500): et2 = time.time() - logger.error( - "Error connecting to the server | %s secs" % (et2 - st2) - ) + logger.error("Error connecting to the server | %s secs" % (et2 - st2)) return self.connection_status() else: et2 = time.time() @@ -157,9 +154,7 @@ def _send(self, request): self.connection.write(block) if not self.connection.waitForBytesWritten(MAX_WRITE_RESPONSE_TIME): - logger.error( - "Could not write to socket: %s" % self.connection.errorString() - ) + logger.error("Could not write to socket: %s" % self.connection.errorString()) else: logger.debug("Sent data ok. %s" % self.connection.state()) @@ -175,12 +170,8 @@ def _receive(self): i = 0 while self.connection.bytesAvailable() > 0: - if ( - self._block_size == 0 - and self.connection.bytesAvailable() >= INT32_SIZE - ) or ( - self._block_size > 0 - and self.connection.bytesAvailable() >= self._block_size + if (self._block_size == 0 and self.connection.bytesAvailable() >= INT32_SIZE) or ( + self._block_size > 0 and self.connection.bytesAvailable() >= self._block_size ): self._block_size = stream.readInt32() # logger.debug( @@ -188,10 +179,7 @@ def _receive(self): # % (i, self._block_size) # ) - if ( - self._block_size > 0 - and self.connection.bytesAvailable() >= self._block_size - ): + if self._block_size > 0 and self.connection.bytesAvailable() >= self._block_size: data = stream.readRawData(self._block_size) request = QtCore.QTextCodec.codecForMib(106).toUnicode(data) # logger.debug("About to process request %s in queue: %s" % (i, request)) @@ -217,12 +205,7 @@ def _prepare_request(self, method, request_return=False, **kwargs): def _prepare_reply(self, request_id, result): reply = json.dumps( - { - "jsonrpc": "2.0", - "result": result, - "request_return": False, - "id": request_id, - } + {"jsonrpc": "2.0", "result": result, "request_return": False, "id": request_id} ) return request_id, reply @@ -258,22 +241,17 @@ def _process_request(self, request): else: logger.warning("Command not recognized: %s. Skipping." % method) elif "error" in command: - logger.error( - "Error occurred when requesting command. %s" % command["error"] - ) + logger.error("Error occurred when requesting command. %s" % command["error"]) else: logger.debug( - "Not a command, and not a message we were waiting answer for. %s" - % request_id + "Not a command, and not a message we were waiting answer for. %s" % request_id ) def send_and_receive_command(self, method, **kwargs): QtGui.QApplication.processEvents() st = time.time() - request_id, request = self._prepare_request( - method, request_return=True, **kwargs - ) + request_id, request = self._prepare_request(method, request_return=True, **kwargs) self._send(request) st1 = time.time() @@ -291,10 +269,7 @@ def send_and_receive_command(self, method, **kwargs): self._receiving = False et3 = time.time() result = self.responses.get(request_id) - logger.debug( - "Received command. in %s secs | Result: %s" - % ((et3 - st3), result) - ) + logger.debug("Received command. in %s secs | Result: %s" % ((et3 - st3), result)) else: logger.warning("Did not receive any data.") @@ -323,16 +298,12 @@ def error(self, socketError): logger.error("Host closed the connection...") elif socketError == QtNetwork.QAbstractSocket.HostNotFoundError: logger.error( - "The host was not found. Please check the host name and " - "port settings." + "The host was not found. Please check the host name and " "port settings." ) elif socketError == QtNetwork.QAbstractSocket.ConnectionRefusedError: logger.error("The server is not up and running yet.") else: - logger.error( - "The following error occurred: %s." - % self.connection.errorString() - ) + logger.error("The following error occurred: %s." % self.connection.errorString()) def close(self): self.connection.abort() @@ -373,12 +344,8 @@ def __init__(self, parent=None): buttonBox = QtGui.QDialogButtonBox() - buttonBox.addButton( - self.connectButton, QtGui.QDialogButtonBox.ActionRole - ) - buttonBox.addButton( - self.sendCommandButton, QtGui.QDialogButtonBox.ActionRole - ) + buttonBox.addButton(self.connectButton, QtGui.QDialogButtonBox.ActionRole) + buttonBox.addButton(self.sendCommandButton, QtGui.QDialogButtonBox.ActionRole) buttonBox.addButton(quitButton, QtGui.QDialogButtonBox.RejectRole) self.hostLineEdit.textChanged.connect(self.enablesendCommandButton) @@ -415,18 +382,14 @@ def ping(self): return "PONG" def show_menu(self, clickedPosition): - logger.debug( - "Client | Request for SHOW MENU received!: %s" % clickedPosition - ) + logger.debug("Client | Request for SHOW MENU received!: %s" % clickedPosition) def connect_to_host(self): self.client.close() self.client.register_callback("PING", self.ping) self.client.register_callback("SHOW_MENU", self.show_menu) - self.client.connect_to_host( - self.hostLineEdit.text(), int(self.portLineEdit.text()) - ) + self.client.connect_to_host(self.hostLineEdit.text(), int(self.portLineEdit.text())) self.sendCommandButton.setEnabled(True) commands = self.client.send_and_receive_command("DIR") diff --git a/python/tk_harmony/menu_generation.py b/python/tk_harmony/menu_generation.py index 03f17ef..1235cff 100644 --- a/python/tk_harmony/menu_generation.py +++ b/python/tk_harmony/menu_generation.py @@ -49,11 +49,7 @@ def hide(self): self.menu_handle.hide() def show(self, pos=None): - pos = ( - QtGui.QCursor.pos() - if pos is None - else QtCore.QPoint(pos[0], pos[1]) - ) + pos = QtGui.QCursor.pos() if pos is None else QtCore.QPoint(pos[0], pos[1]) qApp = QtGui.QApplication.instance() @@ -97,10 +93,7 @@ def create_menu(self, disabled=False): # scan through all menu items for cmd in menu_items: - if ( - cmd.get_app_instance_name() == app_instance_name - and cmd.name == menu_name - ): + if cmd.get_app_instance_name() == app_instance_name and cmd.name == menu_name: # found our match! cmd.add_command_to_menu(self.menu_handle) # mark as a favourite item @@ -135,9 +128,7 @@ def create_menu(self, disabled=False): self._add_divider(self.menu_handle) # add menu divider - self._add_menu_item( - "-- Exit Menu --", self.menu_handle, self.menu_handle.hide - ) + self._add_menu_item("-- Exit Menu --", self.menu_handle, self.menu_handle.hide) def _add_divider(self, parent_menu): divider = QtGui.QAction(parent_menu) @@ -184,9 +175,7 @@ def _add_context_menu(self): # Add the menu item only when there are some file system locations. if ctx.filesystem_locations: - self._add_menu_item( - "Jump to File System", ctx_menu, self._jump_to_fs - ) + self._add_menu_item("Jump to File System", ctx_menu, self._jump_to_fs) # divider (apps may register entries below this divider) self._add_divider(ctx_menu) @@ -299,9 +288,7 @@ def get_documentation_url_str(self): app = self.properties["app"] doc_url = app.documentation_url if doc_url.__class__ == unicode: - doc_url = unicodedata.normalize("NFKD", doc_url).encode( - "ascii", "ignore" - ) + doc_url = unicodedata.normalize("NFKD", doc_url).encode("ascii", "ignore") return doc_url return None @@ -332,9 +319,7 @@ def add_command_to_menu(self, menu): parent_menu = self.parent._add_sub_menu(item_label, parent_menu) # self._execute_deferred) - self.parent._add_menu_item( - parts[-1], parent_menu, self.callback, self.properties - ) + self.parent._add_menu_item(parts[-1], parent_menu, self.callback, self.properties) def _find_sub_menu_item(self, menu, label): """ diff --git a/startup/bootstrap.py b/startup/bootstrap.py index 3c3f512..22d2fe0 100644 --- a/startup/bootstrap.py +++ b/startup/bootstrap.py @@ -81,8 +81,7 @@ def start_toolkit_classic(): try: # Start up the toolkit engine from the environment data logger.debug( - "Launching engine instance '%s' for context %s" - % (env_engine, env_context) + "Launching engine instance '%s' for context %s" % (env_engine, env_context) ) engine = sgtk.platform.start_engine(env_engine, context.sgtk, context) logger.debug("Current engine '%s'" % sgtk.platform.current_engine())