def __init__(self): """ Initializes the RV mode. An environment variable "TK_RV_MODE_NAME" will be set to the name of this mode. That variable can then be used by other logic to generate menu items in RV associated with this mode. """ self.startup_time = rvc.theTime() super(ToolkitBootstrap, self).__init__() self._mode_name = "sgtk_bootstrap" self.init( self._mode_name, None, [("external-gma-play-entity", self.pre_process_event, ""), ("external-gma-compare-entities", self.pre_process_event, ""), ("external-sgtk-launch-app", self.pre_process_event, ""), ("external-sgtk-initialize", self.pre_process_event, ""), ("license-state-transition", self.license_state_transition, "")], None) self.server_url = None self.toolkit_initialized = False self.licensing_style = "" self.event_queue = [] self.event_queue_time = 0.0 self.first_event = True # The menu generation code makes use of the TK_RV_MODE_NAME environment # variable. Each menu item that is created in RV is associated with a # mode identified by its name. We need to make a note of our name so we # can add menu items for this mode later. os.environ["TK_RV_MODE_NAME"] = self._mode_name
def process_queued_events(self): if self.event_queue: processed = [] sys.stderr.write("INFO: Queued events waited %g seconds.\n" % (rvc.theTime() - self.event_queue_time)) for e in self.event_queue: if (e[0], e[1]) not in processed: processed.append((e[0], e[1])) self.process_event(e[0], e[1]) self.event_queue = []
def process_event(self, name, contents): sys.stderr.write( "INFO: Processing event '%s' %g seconds after startup.\n" % (name, rvc.theTime() - self.startup_time)) if name == "external-gma-play-entity": self.external_gma_play_entity(name, contents) elif name == "external-gma-compare-entities": self.external_gma_compare_entities(name, contents) elif name == "external-sgtk-launch-app": self.external_launch_app(name, contents) rve.displayFeedback2("", 0.1) elif name == "external-launch-submit-tool": rvc.sendInternalEvent("launch-submit-tool", "") rve.displayFeedback2("", 0.1) elif name == "external-sgtk-initialize": rve.displayFeedback2("", 0.1)
def pre_process_event_pair(self, name, contents): # sys.stderr.write("pre_process_event: lic style '%s' \n" % self.licensing_style) if self.licensing_style != "shotgun": # RV is not licensed via Shotgun, so notify user. sys.stderr.write( "ERROR: Please authenticate RV with your Shotgun server and restart.\n" ) else: if self.toolkit_initialized: self.process_event(name, contents) else: if self.first_event: msg = "Initializing Shotgun ..." rve.displayFeedback2(msg, 2000.0) self.first_event = False self.event_queue += [(name, contents)] self.event_queue_time = rvc.theTime() if rvc.licensingState() == 2: self.init_and_process_events()
def initialize_toolkit(self): try: # Clear the "stand-in" mode menu, and let the apps rebuild it modeMenu = [("SG Review", None)] rvc.defineModeMenu(self._modeName, modeMenu) startTime = rvc.theTime() bundle_cache_dir = os.path.join(sgtk_dist_dir(), "bundle_cache") core = os.path.join(bundle_cache_dir, "manual", "tk-core", "v1.0.43") core = os.environ.get("RV_TK_CORE") or core # append python path to get to the actual code core = os.path.join(core, "python") log.info("Looking for tk-core here: %s" % str(core)) # now we can kick off sgtk sys.path.insert(0, core) sys.stderr.write( "INFO: Toolkit initialization: ready to import sgtk at %g sec.\n" % (rvc.theTime() - startTime)) # import bootstrapper import sgtk sys.stderr.write( "INFO: Toolkit initialization: sgtk import complete at %g sec.\n" % (rvc.theTime() - startTime)) # begin logging the toolkit log tree file sgtk.LogManager().initialize_base_file_handler("tk-rv") # import authentication code from sgtk_auth import get_toolkit_user # allow dev to override log level log_level = logging.WARNING if (os.environ.has_key("RV_TK_LOG_DEBUG")): log_level = logging.DEBUG # bind toolkit logging to our logger sgtk.LogManager().initialize_custom_handler(log_handler) # and set the level log_handler.setLevel(log_level) # Get an authenticated user object from rv's security architecture (user, url) = get_toolkit_user() self.server_url = url log.info("Will connect using %r" % user) # Now do the bootstrap! log.debug("Ready for bootstrap!") mgr = sgtk.bootstrap.ToolkitManager(user) sys.stderr.write( "INFO: Toolkit initialization: ToolkitManager complete at %g sec.\n" % (rvc.theTime() - startTime)) # In disted code, by default, all TK code is read from the # 'bundle_cache' baked during the build process. mgr.bundle_cache_fallback_paths = [bundle_cache_dir] dev_config = os.environ.get("RV_TK_DEV_CONFIG") if (dev_config): # Use designated developer's tk-config-rv instead of disted one. mgr.base_configuration = dict( type="dev", path=dev_config, ) else: mgr.base_configuration = dict( type="manual", name="tk-config-rv", version="v1.0.43", ) # tell the bootstrap API that we don't want to # allow for overrides from Shotgun mgr.do_shotgun_config_lookup = False # define the entry point for this plugin in # order to sandbox it relative to other plugins mgr.entry_point = "rv_review" # Bootstrap the tk-rv engine into an empty context! mgr.bootstrap_engine("tk-rv") log.debug("Bootstrapping process complete!") self.toolkit_initialized = True sys.stderr.write("INFO: Toolkit initialization took %g sec.\n" % (rvc.theTime() - startTime)) except Exception, e: sys.stderr.write( "ERROR: Toolkit initialization failed. Please authenticate RV with your Shotgun server and restart.\n" + "**********************************\n") traceback.print_exc(None, sys.stderr) sys.stderr.write("**********************************\n") rve.displayFeedback2("", 0.1)