def setUp(self): """ Prepare unit test. """ super(TestSetupProjectWizard, self).setUp( parameters={"primary_root_name": "primary"} ) self._wizard = sgtk.get_command("setup_project_factory").execute({}) self._storage_locations = ShotgunPath( "Z:\\projects", "/mnt/projects", "/Volumes/projects" ) self._storage_locations.current_os = self.tank_temp self.mockgun.update( "LocalStorage", self.primary_storage["id"], self._storage_locations.as_shotgun_dict(), ) # Prepare the wizard for business. All these methods are actually passing # information directly to the SetupProjectParams object inside # the wizard, so there's no need to test them per-se. self._wizard.set_project(self.project["id"], force=True) self._wizard.set_use_distributed_mode() self.config_uri = os.path.join(self.fixtures_root, "config") self._wizard.set_config_uri(self.config_uri)
def test_01_setup_legacy_bootstrap_core(self): """ Sets up a site-wide configuration like Shotgun Desktop 1.3.6 used to do so we can make sure it doesn't get broken by more recent versions of tk-core. """ self.remove_files(self.legacy_bootstrap_core, self.site_config_location) if sys.platform == "darwin": path_param = "config_path_mac" elif sys.platform == "win32": path_param = "config_path_win" elif sys.platform.startswith("linux"): path_param = "config_path_linux" cw = sgtk.bootstrap.configuration_writer.ConfigurationWriter( sgtk.util.ShotgunPath.from_current_os_path( self.legacy_bootstrap_core), self.sg) # Activate the core. cw.ensure_project_scaffold() install_core_folder = os.path.join(self.legacy_bootstrap_core, "install", "core") os.makedirs(install_core_folder) cw.write_shotgun_file(Mock(get_path=lambda: "does_not_exist")) cw.write_install_location_file() sgtk.util.filesystem.copy_folder(self.tk_core_repo_root, install_core_folder, skip_list=[".git", "docs", "tests"]) cw.create_tank_command() # Setup the site config in the legacy auto_path mode that the Desktop used. params = { "auto_path": True, "config_uri": os.path.join(os.path.dirname(__file__), "data", "site_config"), "project_folder_name": "site", "project_id": None, path_param: self.site_config_location, } setup_project = sgtk.get_command("setup_project") setup_project.set_logger(logger) sgtk.set_authenticated_user(self.user) with patch("tank.pipelineconfig_utils.resolve_all_os_paths_to_core", return_value=sgtk.util.ShotgunPath.from_current_os_path( self.legacy_bootstrap_core).as_system_dict()): setup_project.execute(params)
def fixed_folders(self, entity_type, entity_ids): if len(entity_ids) == 0: self.log_info("No entities specified!") return tk = self.engine.sgtk unreg_cmd = sgtk.get_command('unregister_folders', tk) for entity_id in entity_ids: parameters = {"entity": {'type':entity_type, 'id': entity_id}} unreg_cmd.execute(parameters)
def test_01_setup_legacy_bootstrap_core(self): """ Test payload. See class docstring for details. """ if sys.platform == "darwin": path_param = "config_path_mac" elif sys.platform == "win32": path_param = "config_path_win" elif sys.platform.startswith("linux"): path_param = "config_path_linux" # create a basic install that we can run setup_project from install_location = os.path.join(self.temp_dir, "preflight_install") self._create_basic_install(install_location) # Now run setup_project for the basic config params = { "config_uri": "tk-config-basic", "force": True, "project_folder_name": "bootstrap_test", "project_id": self.project["id"], path_param: self.installed_config_location, } setup_project = sgtk.get_command("setup_project") setup_project.set_logger(logger) sgtk.set_authenticated_user(self.user) with patch("tank.pipelineconfig_utils.resolve_all_os_paths_to_core", return_value=sgtk.util.ShotgunPath.from_current_os_path( install_location).as_system_dict()): setup_project.execute(params) # Find the project and pipeline configuration in Shotgun. project = self.sg.find_one("Project", [["id", "is", self.project["id"]]]) pc = self.sg.find_one( "PipelineConfiguration", [["code", "is", "Primary"], ["project", "is", project]]) # Bootstrap into the tk-shell123 engine. manager = sgtk.bootstrap.ToolkitManager(self.user) manager.pipeline_configuration = pc["id"] try: engine = manager.bootstrap_engine("tk-shell123", project) except Exception as e: # note: due to core swapping this comparison needs to happen by name self.assertEqual(e.__class__.__name__, sgtk.platform.TankMissingEngineError.__name__) engine = manager.bootstrap_engine("tk-shell", project) self.assertEqual(engine.name, "tk-shell")
def test_01_setup_legacy_bootstrap_core(self): """ Test payload. See class docstring for details. """ if sys.platform == "darwin": path_param = "config_path_mac" elif sys.platform == "win32": path_param = "config_path_win" elif sys.platform.startswith("linux"): path_param = "config_path_linux" # create a basic install that we can run setup_project from install_location = os.path.join(self.temp_dir, "preflight_install") self._create_basic_install(install_location) # Now run setup_project for the basic config params = { "config_uri": "tk-config-basic", "force": True, "project_folder_name": "bootstrap_test", "project_id": self.project["id"], path_param: self.installed_config_location, } setup_project = sgtk.get_command("setup_project") setup_project.set_logger(logger) sgtk.set_authenticated_user(self.user) with patch( "tank.pipelineconfig_utils.resolve_all_os_paths_to_core", return_value=sgtk.util.ShotgunPath.from_current_os_path( install_location ).as_system_dict() ): setup_project.execute(params) # Find the project and pipeline configuration in Shotgun. project = self.sg.find_one("Project", [["id", "is", self.project["id"]]]) pc = self.sg.find_one("PipelineConfiguration", [["code", "is", "Primary"], ["project", "is", project]]) # Bootstrap into the tk-shell123 engine. manager = sgtk.bootstrap.ToolkitManager(self.user) manager.pipeline_configuration = pc["id"] try: engine = manager.bootstrap_engine("tk-shell123", project) except Exception as e: # note: due to core swapping this comparison needs to happen by name self.assertEqual(e.__class__.__name__, sgtk.platform.TankMissingEngineError.__name__) engine = manager.bootstrap_engine("tk-shell", project) self.assertEqual(engine.name, "tk-shell")
def __init__(self, project, parent=None): QtGui.QWizard.__init__(self, parent) # setup the command wizard from core wizard_factory = sgtk.get_command("setup_project_factory") # initialize storage setup pages self._storage_location_page_ids = [] # setup logging self._logger = logging.getLogger("tk-framework-adminui.setup_project") self._handler = EmittingHandler() self._logger.setLevel(logging.INFO) self._logger.addHandler(self._handler) wizard_factory.set_logger(self._logger) # run the factory to grab the wizard self.core_wizard = wizard_factory.execute({}) self.core_wizard.set_project(project["id"]) # setup the GUI self.ui = setup_project.Ui_Wizard() self.ui.setupUi(self) # hook up logging self._handler.connect(self.ui.progress_page.append_log_message) # hook up help handling self.helpRequested.connect(self._on_help_requested) # Setup fields self.ui.github_config_page.registerField("github_url*", self.ui.github_url) self.ui.disk_config_page.registerField("disk_path*", self.ui.path) self.ui.project_name_page.registerField("project_name*", self.ui.project_name) self.ui.config_location_page.registerField("config_path_mac", self.ui.mac_path) self.ui.config_location_page.registerField("config_path_win", self.ui.windows_path) self.ui.config_location_page.registerField("config_path_linux", self.ui.linux_path) # Let each page set itself up for page_id in self.pageIds(): page = self.page(page_id) if hasattr(page, "setup_ui"): self.page(page_id).setup_ui(page_id) # Setup Page Order self.ui.setup_type_page.set_default_configs_page(self.ui.default_configs_page) self.ui.setup_type_page.set_project_page(self.ui.project_config_page) self.ui.setup_type_page.set_github_page(self.ui.github_config_page) self.ui.setup_type_page.set_disk_page(self.ui.disk_config_page) self.ui.project_name_page.set_next_page(self.ui.config_location_page) self.ui.config_location_page.set_next_page(self.ui.progress_page) self.ui.config_location_page.setCommitPage(True) self.ui.summary_page.setFinalPage(True) # Override button formatting self.setButtonText(self.NextButton, "Continue") self.setButtonText(self.BackButton, "Back") self.setButtonText(self.FinishButton, "Done") self.setButtonText(self.CommitButton, "Run Setup") self.button(self.NextButton).setStyleSheet("background-color: rgb(16, 148,223);") self.button(self.FinishButton).setStyleSheet("background-color: rgb(16, 148,223);") self.button(self.CommitButton).setStyleSheet("background-color: rgb(16, 148,223);")
def Shotgun_Toolkit_Builder(project_id, config_file): if not os.path.exists(config_file): raise OSError("Could Not Find config file to parse %r" % config_file) else: tree = etree.parse(config_file) win_projects_folder = tree.findtext("win_projects_folder") mac_projects_folder = tree.findtext("mac_projects_folder") linux_projects_folder = tree.findtext("linux_projects_folder") win_schema_install = tree.findtext("win_schema_install") mac_schema_install = tree.findtext("mac_schema_install") linux_schema_install = tree.findtext("linux_schema_install") schema_config_uri = tree.findtext("schema_config_uri") if win_projects_folder is None: raise ValueError("The Windows Project Folder Must Have A Valid Folder Path And Nothing Was Given") if win_schema_install is None: raise ValueError("The Windows Schema Install Folder Must Have A Valid Folder Path And Nothing Was Given") if schema_config_uri is None: schema_config_uri = 'tk-config-default' if os.name == 'nt': # Check To Make Sure That The Base Projects Folder Exists # For Safty Reasons This Folder Is Not Automaticly Created if not os.path.exists(win_projects_folder): raise OSError("The Input Projects Folder Path %r Does Not Exist Please Create it And Run Again" % win_projects_folder) # Check To Make Sure That The Base Toolkit Config Folder Exists # For Safty Reasons This Folder Is Not Automaticly Created if not os.path.exists(win_schema_install): raise OSError("The Input Config Folder Path %r Does Not Exist Please Create it And Run Again" % win_schema_install) else: raise NotImplementedError("Only Windows Is Supported At This Time") project = sg_access.Entities.Project(project_id) # The Project name. project_name = project.name.value # Name of the folder which you want # to be the root point of the created project. # If a project already exists # this parameter must reflect the name of # the top level folder of the project. project_folder_name = project_name.replace(" ", "_") # Build The Base Project Folder Path if os.name == 'nt': win_project_path = os.path.join(win_projects_folder , project_folder_name) mac_project_path = mac_projects_folder if mac_projects_folder is None else os.path.join(mac_projects_folder , project_folder_name).replace("\\", "/") linux_project_path = linux_projects_folder if linux_projects_folder is None else os.path.join(linux_projects_folder , project_folder_name).replace("\\", "/") win_storage_path = os.path.join(win_schema_install, project_folder_name) mac_storage_path = mac_schema_install if mac_schema_install is None else os.path.join(mac_schema_install, project_folder_name).replace("\\", "/") linux_storage_path = linux_schema_install if linux_schema_install is None else os.path.join(linux_schema_install, project_folder_name).replace("\\", "/") # Check IF The Base Project and Storage Path Exists # And If Not Create It This Step Is Done Because # The ShotGun Tool Kit Will Not Create It For You # And Will Error out Because It Does Not Exist for folder_path in [win_project_path, win_storage_path]: if not os.path.exists(folder_path): os.makedirs(folder_path) else: raise NotImplementedError("Only Windows Is Supported At This Time") psetup = sgtk.get_command("setup_project") # The configuration to use when setting up this project. # This can be a path on disk to a directory containing a config, # a path to a git bare repo # (e.g. a git repo path which ends with .git) # or 'tk-config-default' to fetch the default config from the toolkit app store. # config_uri = "https://github.com/Mayaenite/Master_Config.git" config_uri = schema_config_uri # The path on disk where the configuration should be installed on Windows. config_path_win = win_storage_path # The path on disk where the configuration should be installed on Linux. config_path_linux = linux_storage_path # The path on disk where the configuration should be installed on Mac. config_path_mac = mac_storage_path # Enabling this flag allows you to run the # set up project on projects which have # already been previously set up. force = True # Check that the path to the storage exists. # this is enabled by default but can be turned off # in order to deal with certain expert level use # cases relating to UNC paths. check_storage_path_exists = False parameters = dict( config_uri = config_uri, config_path_win = config_path_win, config_path_linux = config_path_linux, config_path_mac = config_path_mac, project_folder_name = project_folder_name, project_id = project_id, check_storage_path_exists = check_storage_path_exists, force = force ) psetup.execute(parameters)
def __launch_app(app, splash, connection, app_bootstrap, server, settings): """ Shows the splash screen, optionally downloads and configures Toolkit, imports it, optionally updates it and then launches the desktop engine. :param app: Application object for event processing. :param splash: Splash dialog to update user on what is currently going on :param connection: Connection to the Shotgun server. :param server: The tk_framework_desktopserver.Server instance. :param settings: The application's settings. :returns: The error code to return to the shell. """ # show the splash screen splash.show() splash.set_message("Looking up site configuration.") app.processEvents() _assert_toolkit_enabled(splash, connection) logger.debug("Getting the default site config") default_site_config, pc = shotgun_desktop.paths.get_default_site_config_root( connection) # try and import toolkit toolkit_imported = False config_folder_exists_at_startup = os.path.exists(default_site_config) reset_site = __extract_command_line_argument("--reset-site") # If the config folder exists at startup but the user wants to wipe it, do it. if config_folder_exists_at_startup and reset_site: logger.info("Resetting site configuration at '%s'" % default_site_config) splash.set_message("Resetting site configuration ...") shutil.rmtree(default_site_config) # It doesn't exist anymore, so we can act as if it never existed in the first place config_folder_exists_at_startup = False # Remove all occurances of --reset-site so that if we restart the app it doesn't reset it # again. # If there is no pipeline configuration but we found something on disk nonetheless. if not pc and is_toolkit_already_configured(default_site_config): raise UnexpectedConfigFound(default_site_config) try: # In we found a pipeline configuration and the path for the config exists, try to import # Toolkit. if config_folder_exists_at_startup: logger.info("Trying site config from '%s'" % default_site_config) sgtk = __import_sgtk_from_path(default_site_config) toolkit_imported = True except Exception: logger.exception("There was an error importing Toolkit:") pass else: # Toolkit was imported, we need to initialize it now. if toolkit_imported: __initialize_sgtk_authentication(sgtk, app_bootstrap) if not toolkit_imported: # sgtk not available. initialize core logger.info("Import sgtk from site config failed. ") try: app.processEvents() splash.set_message("Initializing Toolkit") logger.info("Initializing Toolkit") core_path = initialize(splash, connection, settings.default_app_store_http_proxy) except Exception, error: logger.exception(error) if "ApiUser can not be accessed" in error.message: # Login does not have permission to see Scripts, throw an informative # error how to work around this for now. raise UpdatePermissionsError() else: raise try: # try again after the initialization is done logger.debug("Importing sgtk after initialization") sgtk = __get_initialized_sgtk(core_path, app_bootstrap) if sgtk is None: # Generate a generic error message, which will suggest to contact support. raise Exception("Could not access API post initialization.") splash.set_message("Setting up default site configuration...") # Install the default site config sg = sgtk.util.shotgun.create_sg_connection() # Site config has a none project id. project_id = None # If no pipeline configuration had been found. if not pc: # This site config has never been set by anyone, so we're the first. # If pipeline configurations are still project entities, we'll have to use the # TemplateProject as the project which will host the pipeline configuration. if does_pipeline_configuration_require_project(connection): template_project = sg.find_one( "Project", [["name", "is", "Template Project"], ["layout_project", "is", None]]) # Can't find template project, so we're effectively done here, we need a project # to create a pipeline configuration. if template_project is None: # Generate a generic error message, which will suggest to contact support. raise Exception( "Error finding the Template project on your site.") logger.info( "Creating the site config using the template project.") # We'll need to use the template project's id to setup the site config in this case. project_id = template_project["id"] else: logger.info( "Creating the site config without using a project.") else: # If a project is set in the pipeline configuration, it's an old style site config tied # to the template project, so we have to use it. if pc.get("project") is not None: logger.info("Reusing the site config with a project.") project_id = pc["project"]["id"] else: logger.info("Reusing the site config without a project.") # Create the directory if not os.path.exists(default_site_config): os.makedirs(default_site_config) # Setup the command to create the config if sys.platform == "darwin": path_param = "config_path_mac" elif sys.platform == "win32": path_param = "config_path_win" elif sys.platform.startswith("linux"): path_param = "config_path_linux" # allow the config uri to be overridden for testing config_uri = os.environ.get("SGTK_SITE_CONFIG_DEBUG_LOCATION", "tk-config-site") params = { "auto_path": True, "config_uri": config_uri, "project_folder_name": "site", "project_id": project_id, path_param: default_site_config, } setup_project = sgtk.get_command("setup_project") setup_project.set_logger(logger) try: setup_project.execute(params) except Exception, error: logger.exception(error) if "CRUD ERROR" in error.message: raise UpdatePermissionsError() else: raise # and now try to load up sgtk through the config again sgtk = __get_initialized_sgtk(default_site_config, app_bootstrap) tk = sgtk.sgtk_from_path(default_site_config) # now localize the core to the config splash.set_message("Localizing core...") localize = tk.get_command("localize") localize.set_logger(logger) localize.execute({}) # Get back the pipeline configuration, this is expected to be initialized further down. _, pc = shotgun_desktop.paths.get_default_site_config_root( connection)
def __init__(self, project, parent=None): QtGui.QWizard.__init__(self, parent) # setup the command wizard from core wizard_factory = sgtk.get_command("setup_project_factory") # initialize storage setup pages self._storage_location_page_ids = [] # setup logging self._logger = logging.getLogger("tk-framework-adminui.setup_project") self._handler = EmittingHandler() self._logger.setLevel(logging.INFO) self._logger.addHandler(self._handler) wizard_factory.set_logger(self._logger) # run the factory to grab the wizard self.core_wizard = wizard_factory.execute({}) self.core_wizard.set_project(project["id"]) # setup the GUI self.ui = setup_project.Ui_Wizard() self.ui.setupUi(self) # hook up logging self._handler.connect(self.ui.progress_page.append_log_message) # hook up help handling self.helpRequested.connect(self._on_help_requested) # Setup fields self.ui.github_config_page.registerField("github_url*", self.ui.github_url) self.ui.disk_config_page.registerField("disk_path*", self.ui.path) self.ui.project_name_page.registerField("project_name*", self.ui.project_name) self.ui.config_location_page.registerField("config_path_mac", self.ui.mac_path) self.ui.config_location_page.registerField("config_path_win", self.ui.windows_path) self.ui.config_location_page.registerField("config_path_linux", self.ui.linux_path) # Let each page set itself up for page_id in self.pageIds(): page = self.page(page_id) if hasattr(page, "setup_ui"): self.page(page_id).setup_ui(page_id) # Setup Page Order self.ui.setup_type_page.set_default_configs_page( self.ui.default_configs_page) self.ui.setup_type_page.set_project_page(self.ui.project_config_page) self.ui.setup_type_page.set_github_page(self.ui.github_config_page) self.ui.setup_type_page.set_disk_page(self.ui.disk_config_page) self.ui.project_name_page.set_next_page(self.ui.config_location_page) self.ui.config_location_page.set_next_page(self.ui.progress_page) self.ui.config_location_page.setCommitPage(True) self.ui.summary_page.setFinalPage(True) # Override button formatting self.setButtonText(self.NextButton, "Continue") self.setButtonText(self.BackButton, "Back") self.setButtonText(self.FinishButton, "Done") self.setButtonText(self.CommitButton, "Run Setup") self.button(self.NextButton).setStyleSheet( "background-color: rgb(16, 148,223);") self.button(self.FinishButton).setStyleSheet( "background-color: rgb(16, 148,223);") self.button(self.CommitButton).setStyleSheet( "background-color: rgb(16, 148,223);")
def __init__(self, project, parent=None): QtGui.QWizard.__init__(self, parent) # Disable Close button. Note that on mac, need to disable minimize # button also to do this (but maximize can stay). self.setWindowFlags(QtCore.Qt.Tool | QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowMaximizeButtonHint) # Set stylesheet modification for this wizard self.setStyleSheet( "QLineEdit:Disabled {background-color: rgb(60, 60, 60); color: rgb(128, 128, 128);}" ) # setup the command wizard from core wizard_factory = sgtk.get_command("setup_project_factory") # setup logging self._logger = logging.getLogger("tk-framework-adminui.setup_project") self._handler = EmittingHandler() self._logger.setLevel(logging.INFO) self._logger.addHandler(self._handler) wizard_factory.set_logger(self._logger) # run the factory to grab the wizard self.core_wizard = wizard_factory.execute({}) self.core_wizard.set_project(project["id"]) # setup the GUI self.ui = setup_project.Ui_Wizard() self.ui.setupUi(self) # hook up logging self._handler.connect(self.ui.progress_page.append_log_message) # hook up help handling self.helpRequested.connect(self._on_help_requested) # Setup fields self.ui.github_config_page.registerField("github_url*", self.ui.github_url) self.ui.disk_config_page.registerField("disk_path*", self.ui.path) self.ui.project_name_page.registerField("project_name*", self.ui.project_name) self.ui.config_location_page.registerField("config_path_mac", self.ui.mac_path) self.ui.config_location_page.registerField("config_path_win", self.ui.windows_path) self.ui.config_location_page.registerField("config_path_linux", self.ui.linux_path) # Let each page set itself up for page_id in self.pageIds(): page = self.page(page_id) if hasattr(page, "setup_ui"): self.page(page_id).setup_ui(page_id) # Setup Page Order self.ui.setup_type_page.set_default_configs_page( self.ui.default_configs_page) self.ui.setup_type_page.set_project_page(self.ui.project_config_page) self.ui.setup_type_page.set_github_page(self.ui.github_config_page) self.ui.setup_type_page.set_disk_page(self.ui.disk_config_page) self.ui.project_name_page.set_next_page(self.ui.config_location_page) self.ui.config_location_page.set_next_page(self.ui.progress_page) self.ui.config_location_page.setCommitPage(True) self.ui.summary_page.setFinalPage(True) # Override button formatting self.setButtonText(self.NextButton, "Continue") self.setButtonText(self.BackButton, "Back") self.setButtonText(self.FinishButton, "Done") self.setButtonText(self.CommitButton, "Run Setup") self.button(self.NextButton).setStyleSheet( "background-color: rgb(16, 148,223);") self.button(self.FinishButton).setStyleSheet( "background-color: rgb(16, 148,223);") self.button(self.CommitButton).setStyleSheet( "background-color: rgb(16, 148,223);") # load the stylesheet self._load_stylesheet()
def __init__(self, project, parent=None): QtGui.QWizard.__init__(self, parent) # Disable Close button. Note that on mac, need to disable minimize # button also to do this (but maximize can stay). self.setWindowFlags(QtCore.Qt.Tool | QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowMaximizeButtonHint) # Set stylesheet modification for this wizard self.setStyleSheet("QLineEdit:Disabled {background-color: rgb(60, 60, 60); color: rgb(128, 128, 128);}") # setup the command wizard from core wizard_factory = sgtk.get_command("setup_project_factory") # setup logging self._logger = logging.getLogger("tk-framework-adminui.setup_project") self._handler = EmittingHandler() self._logger.setLevel(logging.INFO) self._logger.addHandler(self._handler) wizard_factory.set_logger(self._logger) # run the factory to grab the wizard self.core_wizard = wizard_factory.execute({}) self.core_wizard.set_project(project["id"]) # setup the GUI self.ui = setup_project.Ui_Wizard() self.ui.setupUi(self) # hook up logging self._handler.connect(self.ui.progress_page.append_log_message) # hook up help handling self.helpRequested.connect(self._on_help_requested) # Setup fields self.ui.github_config_page.registerField("github_url*", self.ui.github_url) self.ui.disk_config_page.registerField("disk_path*", self.ui.path) self.ui.project_name_page.registerField("project_name*", self.ui.project_name) self.ui.config_location_page.registerField("config_path_mac", self.ui.mac_path) self.ui.config_location_page.registerField("config_path_win", self.ui.windows_path) self.ui.config_location_page.registerField("config_path_linux", self.ui.linux_path) # Let each page set itself up for page_id in self.pageIds(): page = self.page(page_id) if hasattr(page, "setup_ui"): self.page(page_id).setup_ui(page_id) # Setup Page Order self.ui.setup_type_page.set_default_configs_page(self.ui.default_configs_page) self.ui.setup_type_page.set_project_page(self.ui.project_config_page) self.ui.setup_type_page.set_github_page(self.ui.github_config_page) self.ui.setup_type_page.set_disk_page(self.ui.disk_config_page) self.ui.project_name_page.set_next_page(self.ui.config_location_page) self.ui.config_location_page.set_next_page(self.ui.progress_page) self.ui.config_location_page.setCommitPage(True) self.ui.summary_page.setFinalPage(True) # Override button formatting self.setButtonText(self.NextButton, "Continue") self.setButtonText(self.BackButton, "Back") self.setButtonText(self.FinishButton, "Done") self.setButtonText(self.CommitButton, "Run Setup") if QtCore.__version__.startswith("5."): self.button(self.NextButton).setStyleSheet("background-color: rgb(5, 100, 175);") self.button(self.FinishButton).setStyleSheet("background-color: rgb(5, 100, 175);") self.button(self.CommitButton).setStyleSheet("background-color: rgb(5, 100, 175);") else: self.button(self.NextButton).setStyleSheet("background-color: rgb(16, 148,223);") self.button(self.FinishButton).setStyleSheet("background-color: rgb(16, 148,223);") self.button(self.CommitButton).setStyleSheet("background-color: rgb(16, 148,223);") # load the stylesheet self._load_stylesheet()
def __launch_app(app, splash, connection, app_bootstrap, server): """ Shows the splash screen, optionally downloads and configures Toolkit, imports it, optionally updates it and then launches the desktop engine. :param app: Application object for event processing. :param splash: Splash dialog to update user on what is currently going on :param connection: Connection to the Shotgun server. :param server: The tk_framework_desktopserver.Server instance. :returns: The error code to return to the shell. """ # show the splash screen splash.show() splash.set_message("Looking up site configuration.") app.processEvents() _assert_toolkit_enabled(splash, connection) logger.debug("Getting the default site config") default_site_config, pc = shotgun_desktop.paths.get_default_site_config_root(connection) # try and import toolkit toolkit_imported = False config_folder_exists_at_startup = os.path.exists(default_site_config) reset_site = __extract_command_line_argument("--reset-site") # If the config folder exists at startup but the user wants to wipe it, do it. if config_folder_exists_at_startup and reset_site: logger.info("Resetting site configuration at '%s'" % default_site_config) splash.set_message("Resetting site configuration ...") shutil.rmtree(default_site_config) # It doesn't exist anymore, so we can act as if it never existed in the first place config_folder_exists_at_startup = False # Remove all occurances of --reset-site so that if we restart the app it doesn't reset it # again. # If there is no pipeline configuration but we found something on disk nonetheless. if not pc and is_toolkit_already_configured(default_site_config): raise UnexpectedConfigFound(default_site_config) try: # In we found a pipeline configuration and the path for the config exists, try to import # Toolkit. if config_folder_exists_at_startup: logger.info("Trying site config from '%s'" % default_site_config) sgtk = __import_sgtk_from_path(default_site_config) toolkit_imported = True except Exception: logger.exception("There was an error importing Toolkit:") pass else: # Toolkit was imported, we need to initialize it now. if toolkit_imported: __initialize_sgtk_authentication(sgtk, app_bootstrap) if not toolkit_imported: # sgtk not available. initialize core logger.info("Import sgtk from site config failed. ") try: app.processEvents() splash.set_message("Initializing Toolkit") logger.info("Initializing Toolkit") core_path = initialize(splash, connection) except Exception, error: logger.exception(error) if "ApiUser can not be accessed" in error.message: # Login does not have permission to see Scripts, throw an informative # error how to work around this for now. raise UpdatePermissionsError() else: raise try: # try again after the initialization is done logger.debug("Importing sgtk after initialization") sgtk = __get_initialized_sgtk(core_path, app_bootstrap) if sgtk is None: # Generate a generic error message, which will suggest to contact support. raise Exception("Could not access API post initialization.") splash.set_message("Setting up default site configuration...") # Install the default site config sg = sgtk.util.shotgun.create_sg_connection() # Site config has a none project id. project_id = None # If no pipeline configuration had been found. if not pc: # This site config has never been set by anyone, so we're the first. # If pipeline configurations are still project entities, we'll have to use the # TemplateProject as the project which will host the pipeline configuration. if does_pipeline_configuration_require_project(connection): template_project = sg.find_one( "Project", [["name", "is", "Template Project"], ["layout_project", "is", None]]) # Can't find template project, so we're effectively done here, we need a project # to create a pipeline configuration. if template_project is None: # Generate a generic error message, which will suggest to contact support. raise Exception("Error finding the Template project on your site.") logger.info("Creating the site config using the template project.") # We'll need to use the template project's id to setup the site config in this case. project_id = template_project["id"] else: logger.info("Creating the site config without using a project.") else: # If a project is set in the pipeline configuration, it's an old style site config tied # to the template project, so we have to use it. if pc.get("project") is not None: logger.info("Reusing the site config with a project.") project_id = pc["project"]["id"] else: logger.info("Reusing the site config without a project.") # Create the directory if not os.path.exists(default_site_config): os.makedirs(default_site_config) # Setup the command to create the config if sys.platform == "darwin": path_param = "config_path_mac" elif sys.platform == "win32": path_param = "config_path_win" elif sys.platform.startswith("linux"): path_param = "config_path_linux" # allow the config uri to be overridden for testing config_uri = os.environ.get("SGTK_SITE_CONFIG_DEBUG_LOCATION", "tk-config-site") params = { "auto_path": True, "config_uri": config_uri, "project_folder_name": "site", "project_id": project_id, path_param: default_site_config, } setup_project = sgtk.get_command("setup_project") setup_project.set_logger(logger) try: setup_project.execute(params) except Exception, error: logger.exception(error) if "CRUD ERROR" in error.message: raise UpdatePermissionsError() else: raise # and now try to load up sgtk through the config again sgtk = __get_initialized_sgtk(default_site_config, app_bootstrap) tk = sgtk.sgtk_from_path(default_site_config) # now localize the core to the config splash.set_message("Localizing core...") localize = tk.get_command("localize") localize.set_logger(logger) localize.execute({}) # Get back the pipeline configuration, this is expected to be initialized further down. _, pc = shotgun_desktop.paths.get_default_site_config_root(connection)