def _run_shotgun_command(log, tk, action_name, entity_type, entity_ids): """ Helper method. Starts the shotgun engine and executes a command. """ # add some smarts about context management here if len(entity_ids) == 1: # this is a single selection ctx = tk.context_from_entity(entity_type, entity_ids[0]) else: # with multiple items selected, create a blank context ctx = tk.context_empty() # start the shotgun engine, load the apps e = engine.start_shotgun_engine(tk, entity_type, ctx) cmd = e.commands.get(action_name) if cmd: callback = cmd["callback"] # introspect and get number of args for this fn arg_count = callback.func_code.co_argcount # check if we are running a pre-013 engine # (this can be removed at a later point) if hasattr(e, "execute_old_style_command"): # 013 compliant engine! # choose between simple style callbacks or complex style # special shotgun callbacks - these always take two # params entity_type and entity_ids if arg_count > 1: # old style shotgun app launch - takes entity_type and ids as args e.execute_old_style_command(action_name, entity_type, entity_ids) else: # std tank app launch e.execute_command(action_name) else: # engine that is pre-013 # this engine does not have any specific callbacks # all apps that are pre-013 take two args callback(entity_type, entity_ids) else: # unknown command - this typically is caused by apps failing to initialize. e.log_error( "The action could not be executed! This is typically because there " "is an error in the app configuration which prevents the engine from " "initializing it.")
def _run_shotgun_command(log, tk, action_name, entity_type, entity_ids): """ Helper method. Starts the shotgun engine and executes a command. """ # add some smarts about context management here if len(entity_ids) == 1: # this is a single selection ctx = tk.context_from_entity(entity_type, entity_ids[0]) else: # with multiple items selected, create a blank context ctx = tk.context_empty() # start the shotgun engine, load the apps e = engine.start_shotgun_engine(tk, entity_type, ctx) cmd = e.commands.get(action_name) if cmd: callback = cmd["callback"] # introspect and get number of args for this fn arg_count = callback.func_code.co_argcount # check if we are running a pre-013 engine # (this can be removed at a later point) if hasattr(e, "execute_old_style_command"): # 013 compliant engine! # choose between simple style callbacks or complex style # special shotgun callbacks - these always take two # params entity_type and entity_ids if arg_count > 1: # old style shotgun app launch - takes entity_type and ids as args e.execute_old_style_command(action_name, entity_type, entity_ids) else: # std tank app launch e.execute_command(action_name) else: # engine that is pre-013 # this engine does not have any specific callbacks # all apps that are pre-013 take two args callback(entity_type, entity_ids) else: # unknown command - this typically is caused by apps failing to initialize. e.log_error("The action could not be executed! This is typically because there " "is an error in the app configuration which prevents the engine from " "initializing it.")
def _write_shotgun_cache(tk, entity_type, cache_file_name): """ Writes a shotgun cache menu file to disk. The cache is per type and per operating system """ cache_path = os.path.join(tk.pipeline_configuration.get_cache_location(), cache_file_name) # start the shotgun engine, load the apps e = engine.start_shotgun_engine(tk, entity_type) # get list of actions engine_commands = e.commands # insert special system commands if entity_type == "Project": engine_commands["__core_info"] = { "properties": { "title": "Check for Core Upgrades...", "deny_permissions": ["Artist"] } } engine_commands["__upgrade_check"] = { "properties": { "title": "Check for App Upgrades...", "deny_permissions": ["Artist"] } } # extract actions into cache file res = [] for (cmd_name, cmd_params) in engine_commands.items(): # some apps provide a special deny_platforms entry if "deny_platforms" in cmd_params["properties"]: # setting can be Linux, Windows or Mac curr_os = { "linux2": "Linux", "darwin": "Mac", "win32": "Windows" }[sys.platform] if curr_os in cmd_params["properties"]["deny_platforms"]: # deny this platform! :) continue if "title" in cmd_params["properties"]: title = cmd_params["properties"]["title"] else: title = cmd_name if "supports_multiple_selection" in cmd_params["properties"]: supports_multiple_sel = cmd_params["properties"][ "supports_multiple_selection"] else: supports_multiple_sel = False if "deny_permissions" in cmd_params["properties"]: deny = ",".join(cmd_params["properties"]["deny_permissions"]) else: deny = "" entry = [cmd_name, title, deny, str(supports_multiple_sel)] res.append("$".join(entry)) data = "\n".join(res) try: # if file does not exist, make sure it is created with open permissions cache_file_created = False if not os.path.exists(cache_path): cache_file_created = True # Write to cache file # Note that we are using binary form here to ensure that the line # endings are written out consistently on all different OSes # otherwise with wt mode, \n on windows will be turned into \n\r # which is not interpreted correctly by the jacascript code. f = open(cache_path, "wb") f.write(data) f.close() # make sure cache file has proper permissions if cache_file_created: old_umask = os.umask(0) try: os.chmod(cache_path, 0666) finally: os.umask(old_umask) except Exception, e: raise TankError("Could not write to cache file %s: %s" % (cache_path, e))
def _write_shotgun_cache(tk, entity_type, cache_file_name): """ Writes a shotgun cache menu file to disk. The cache is per type and per operating system """ cache_path = os.path.join(tk.pipeline_configuration.get_cache_location(), cache_file_name) # start the shotgun engine, load the apps e = engine.start_shotgun_engine(tk, entity_type) # get list of actions engine_commands = e.commands # insert special system commands if entity_type == "Project": engine_commands["__core_info"] = { "properties": {"title": "Check for Core Upgrades...", "deny_permissions": ["Artist"] } } engine_commands["__upgrade_check"] = { "properties": {"title": "Check for App Upgrades...", "deny_permissions": ["Artist"] } } # extract actions into cache file res = [] for (cmd_name, cmd_params) in engine_commands.items(): # some apps provide a special deny_platforms entry if "deny_platforms" in cmd_params["properties"]: # setting can be Linux, Windows or Mac curr_os = {"linux2": "Linux", "darwin": "Mac", "win32": "Windows"}[sys.platform] if curr_os in cmd_params["properties"]["deny_platforms"]: # deny this platform! :) continue if "title" in cmd_params["properties"]: title = cmd_params["properties"]["title"] else: title = cmd_name if "supports_multiple_selection" in cmd_params["properties"]: supports_multiple_sel = cmd_params["properties"]["supports_multiple_selection"] else: supports_multiple_sel = False if "deny_permissions" in cmd_params["properties"]: deny = ",".join(cmd_params["properties"]["deny_permissions"]) else: deny = "" entry = [ cmd_name, title, deny, str(supports_multiple_sel) ] res.append("$".join(entry)) data = "\n".join(res) try: # if file does not exist, make sure it is created with open permissions cache_file_created = False if not os.path.exists(cache_path): cache_file_created = True # Write to cache file # Note that we are using binary form here to ensure that the line # endings are written out consistently on all different OSes # otherwise with wt mode, \n on windows will be turned into \n\r # which is not interpreted correctly by the jacascript code. f = open(cache_path, "wb") f.write(data) f.close() # make sure cache file has proper permissions if cache_file_created: old_umask = os.umask(0) try: os.chmod(cache_path, 0666) finally: os.umask(old_umask) except Exception, e: raise TankError("Could not write to cache file %s: %s" % (cache_path, e))