def do_install(self): """ Performs the actual installation of the new version of the core API """ # validation if self.get_update_status() != TankCoreUpgrader.UPGRADE_POSSIBLE: raise Exception("Upgrade not allowed at this point. Run get_update_status for details.") # download attachment if self._latest_ver[constants.TANK_CODE_PAYLOAD_FIELD] is None: raise Exception("Cannot find a binary bundle for %s. Please contact support" % self._latest_ver["code"]) self._log.info("Begin downloading Toolkit Core API %s from the App Store..." % self._latest_ver["code"]) zip_tmp = os.path.join(tempfile.gettempdir(), "%s_tank_core.zip" % uuid.uuid4().hex) extract_tmp = os.path.join(tempfile.gettempdir(), "%s_tank_unzip" % uuid.uuid4().hex) # now have to get the attachment id from the data we obtained. This is a bit hacky. # data example for the payload field, as returned by the query above: # {'url': 'http://tank.shotgunstudio.com/file_serve/attachment/21', 'name': 'tank_core.zip', # 'content_type': 'application/zip', 'link_type': 'upload'} # # grab the attachment id off the url field and pass that to the download_attachment() # method below. try: attachment_id = int(self._latest_ver[constants.TANK_CODE_PAYLOAD_FIELD]["url"].split("/")[-1]) except: raise Exception("Could not extract attachment id from data %s" % self._latest_ver) bundle_content = self._sg.download_attachment(attachment_id) fh = open(zip_tmp, "wb") fh.write(bundle_content) fh.close() self._log.info("Download complete - now extracting content...") # unzip core zip file to temp location and run updater unzip_file(zip_tmp, extract_tmp) # and write a custom event to the shotgun event log data = {} data["description"] = "%s: Core API was downloaded" % self._local_sg.base_url data["event_type"] = "TankAppStore_CoreApi_Download" data["entity"] = self._latest_ver data["user"] = self._sg_script_user data["project"] = constants.TANK_APP_STORE_DUMMY_PROJECT data["attribute_name"] = constants.TANK_CODE_PAYLOAD_FIELD self._sg.create("EventLogEntry", data) self._log.info("Extraction complete - now installing Toolkit Core") sys.path.insert(0, extract_tmp) try: import _core_upgrader _core_upgrader.upgrade_tank(self._install_root, self._log) except Exception, e: self._log.exception(e) raise Exception("Could not run upgrade script! Error reported: %s" % e)
def _install_core(self): """ Performs the actual installation of the new version of the core API """ self._log.info("Now installing Toolkit Core.") sys.path.insert(0, self._new_core_descriptor.get_path()) try: import _core_upgrader _core_upgrader.upgrade_tank(self._install_root, self._log) except Exception as e: self._log.exception(e) raise Exception("Could not run update script! Error reported: %s" % e)
def install_core(self): # download latest core from the app store sg_studio_version = ".".join([str(x) for x in self._connection.server_info["version"]]) sg_app_store = Shotgun( constants.SGTK_APP_STORE, self._app_store_script, self._app_store_key, http_proxy=self._sg_proxy) (latest_core, core_path) = self._download_core( sg_studio_version, sg_app_store, self._server_url, self._app_store_current_script_user_entity) self.stepDone.emit("Now installing Shotgun Pipeline Toolkit Core") self._logger.debug("Now installing Shotgun Pipeline Toolkit Core") sys.path.insert(0, core_path) try: class EmitLogger(object): def __init__(self, host, debug=False): self.host = host self._debug = debug def debug(self, msg): if self._debug: self.host.stepDone.emit(msg) def info(self, msg): self.host.stepDone.emit(msg) def warning(self, msg): self.host.stepWarn.emit(msg) def error(self, msg): self.host.stepError.emit(msg) import _core_upgrader sgtk_install_folder = os.path.join(self._sgtk_folder, "install") _core_upgrader.upgrade_tank(sgtk_install_folder, EmitLogger(self, debug=False)) except Exception, e: self._logger.exception("Could not run upgrade script! Error reported: %s" % e) self.stepError.emit("Could not run upgrade script! Error reported: %s" % e) return
def install_core(self): # download latest core from the app store sg_studio_version = ".".join( [str(x) for x in self._connection.server_info["version"]]) sg_app_store = Shotgun(constants.SGTK_APP_STORE, self._app_store_script, self._app_store_key, http_proxy=self._actual_app_store_http_proxy) (latest_core, core_path) = self._download_core( sg_studio_version, sg_app_store, self._server_url, self._app_store_current_script_user_entity) self._logger.debug("Now installing Shotgun Pipeline Toolkit Core") sys.path.insert(0, core_path) try: import _core_upgrader sgtk_install_folder = os.path.join(self._sgtk_folder, "install") _core_upgrader.upgrade_tank(sgtk_install_folder, self._logger) except Exception, e: self._logger.exception( "Could not run upgrade script! Error reported: %s" % e) return