def _assert_toolkit_enabled(splash, connection): """ Returns the path to the pipeline configuration for a given site. :param splash: Splash dialog """ # get the pipeline configuration for the site we are logged into while True: pc_schema = connection.schema_entity_read().get( "PipelineConfiguration") if pc_schema is not None: break # Toolkit is not turned on show the dialog that explains what to do splash.hide() dialog = TurnOnToolkit(connection) dialog.show() dialog.raise_() dialog.activateWindow() results = dialog.exec_() if results == dialog.Rejected: # dialog was canceled, raise the exception and let the main exception handler deal # with it. raise ToolkitDisabledError() splash.show()
def __handle_unexpected_exception(splash, shotgun_authenticator, error_message, app_bootstrap): """ Tears down the application, logs you out and displays an error message. :param splash: Splash dialog to hide. :param shotgun_authenticator: Used to clear the default user so we logout automatically on Desktop failure. :param error_message: Error string that will be displayed in a message box. :params app_bootstrap: The application bootstrap. """ if splash: splash.hide() exc_type, exc_value, exc_traceback = sys.exc_info() logger.exception("Fatal error, user will be logged out.") DesktopMessageBox.critical( "Shotgun Desktop Error", "Something went wrong in the Shotgun Desktop! If you drop us an email at " "[email protected], we'll help you diagnose the issue.\n" "Error: %s\n" "For more information, see the log file at %s." % (str(error_message), app_bootstrap.get_logfile_location()), detailed_text="".join( traceback.format_exception(exc_type, exc_value, exc_traceback))) # If we are logged in, we should log out so the user is not stuck in a loop of always # automatically logging in each time the app is launched again if shotgun_authenticator: shotgun_authenticator.clear_default_user()
def _assert_toolkit_enabled(splash, connection): """ Returns the path to the pipeline configuration for a given site. :param splash: Splash dialog """ # get the pipeline configuration for the site we are logged into while True: pc_schema = connection.schema_entity_read().get("PipelineConfiguration") if pc_schema is not None: break # Toolkit is not turned on show the dialog that explains what to do splash.hide() dialog = TurnOnToolkit(connection) dialog.show() dialog.raise_() dialog.activateWindow() results = dialog.exec_() if results == dialog.Rejected: # dialog was canceled, raise the exception and let the main exception handler deal # with it. raise ToolkitDisabledError() splash.show()
def __handle_unexpected_exception(splash, shotgun_authenticator, error_message, app_bootstrap): """ Tears down the application, logs you out and displays an error message. :param splash: Splash dialog to hide. :param shotgun_authenticator: Used to clear the default user so we logout automatically on Desktop failure. :param error_message: Error string that will be displayed in a message box. :params app_bootstrap: The application bootstrap. """ if splash: splash.hide() logger.exception("Fatal error, user will be logged out.") DesktopMessageBox.critical( "Shotgun Desktop Error", "Something went wrong in the Shotgun Desktop! If you drop us an email at " "[email protected], we'll help you diagnose the issue.\n" "For more information, see the log file at %s.\n" "Error: %s" % (app_bootstrap.get_logfile_location(), str(error_message)), detailed_text="".join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)) ) # If we are logged in, we should log out so the user is not stuck in a loop of always # automatically logging in each time the app is launched again if shotgun_authenticator: shotgun_authenticator.clear_default_user()
def __handle_exception(splash, shotgun_authenticator, error_message): """ Tears down the application, logs you out and displays an error message. :param splash: Splash dialog to hide. :param shotgun_authenticator: Used to clear the default user so we logout automatically on Desktop failure. :param error_message: Error string that will be displayed in a message box. """ if splash: splash.hide() logger.exception("Fatal error, user will be logged out.") DesktopMessageBox.critical("Shotgun Desktop Error", error_message) # If we are logged in, we should log out so the user is not stuck in a loop of always # automatically logging in each time the app is launched again if shotgun_authenticator: shotgun_authenticator.clear_default_user()
def __handle_unexpected_exception_during_websocket_init( splash, app_bootstrap, ex): """ Handles unexpected exception during websocket initialization. If hides the splashscreen and asks the user if we wants to keep launching the Desktop. :param splash: Splashscreen widget. :param app_bootstrap: The application bootstrap instance. :param ex: The unexpected exception. :returns: True if the user wants to continue, False otherwise. """ logger.exception("Could not start the browser integration:") splash.hide() return __query_quit_or_continue_launching( "Browser integration failed to start. It will not be available if " "you continue.\n" "Error: %s" % str(ex), app_bootstrap)
def __handle_unexpected_exception_during_websocket_init(splash, app_bootstrap, ex): """ Handles unexpected exception during websocket initialization. If hides the splashscreen and asks the user if we wants to keep launching the Desktop. :param splash: Splashscreen widget. :param app_bootstrap: The application bootstrap instance. :param ex: The unexpected exception. :returns: True if the user wants to continue, False otherwise. """ logger.exception("Could not start the browser integration:") splash.hide() return __query_quit_or_continue_launching( "Browser integration failed to start. It will not be available if " "you continue.\n" "Error: %s" % str(ex), app_bootstrap )
def main(**kwargs): """ Main :params app_bootstrap: AppBootstrap instance, used to get information from the installed application as well as updating the startup description location. See https://github.com/shotgunsoftware/tk-desktop-internal/blob/a31e9339b7e438cd111fb8f4a2b0436e77c98a17/Common/Shotgun/python/bootstrap.py#L133 for more info. :returns: Error code for the process. """ app_bootstrap = _BootstrapProxy(kwargs["app_bootstrap"]) # Do not import sgtk globally to avoid using the wrong sgtk once we bootstrap in # the right config. import sgtk global logger # Older versions of the desktop on Windows logged at %APPDATA%\Shotgun\tk-desktop.log. Notify the user that # this logging location is deprecated and the logs are now at %APPDATA%\Shotgun\Logs\tk-desktop.log if sys.platform == "win32" and LooseVersion( app_bootstrap.get_version()) <= "v1.3.6": logger.info( "Logging at this location will now stop and resume at {0}\\tk-desktop.log" .format(sgtk.LogManager().log_folder)) logger.info( "If you see any more logs past this line, you need to upgrade your site configuration to " "the latest core and apps using 'tank core' and 'tank updates'.") # Core will take over logging app_bootstrap.tear_down_logging() sgtk.LogManager().initialize_base_file_handler("tk-desktop") logger = sgtk.LogManager.get_logger(__name__) logger.debug("Running main from %s" % __file__) # Create some ui related objects app, splash = __init_app() # We might crash before even initializing the authenticator, so instantiate # it right away. shotgun_authenticator = None # Shotgun Desktop startup has always been logging every debug string to disk since the new authentication from 0.16 # was released and the startup has been difficult to work with and debug, so keep that logic in place during the # startup sequence. It will be restored during the ToolkitManager's pre_engine_start_callback. __backup_global_debug_flag() sgtk.LogManager().global_debug = True from sgtk import authentication from sgtk.descriptor import InvalidAppStoreCredentialsError from sgtk.authentication import ShotgunSamlUser try: # Reading user settings from disk. settings = sgtk.util.UserSettings() # It is very important to decouple logging in from creating the shotgun authenticator. # If there is an error during auto login, for example proxy settings changed and you # can't connect anymore, we need to be able to log the user out. shotgun_authenticator = sgtk.authentication.ShotgunAuthenticator() __optional_state_cleanup(splash, shotgun_authenticator, app_bootstrap) user = __do_login(splash, shotgun_authenticator) if not user: logger.info("Login canceled. Quitting.") return 0 # In the case where the site is using SSO, the user needs to renew # its claims regularily. So we kick off a separate newewal thread. if isinstance(user, ShotgunSamlUser): logger.debug("Starting SSO claims renewal") user.start_claims_renewal() else: logger.debug("Not using SSO") # Now that we are logged, we can proceed with launching the # application. exit_code = __launch_app(app, splash, user, app_bootstrap, settings) return exit_code except RequestRestartException: subprocess.Popen(sys.argv, close_fds=True) return 0 except authentication.AuthenticationCancelled: # The user cancelled an authentication request while the app was running, log him out. splash.hide() shotgun_authenticator.clear_default_user() return 0 except InvalidAppStoreCredentialsError, e: __handle_exception(splash, shotgun_authenticator, str(e)) return -1
try: # Makes sure that the certificate has been created on disk and registered with the OS (or browser on Linux). __ensure_certificate_ready(app_bootstrap, tk_framework_desktopserver, integration_settings.certificate_folder) # Launch the server server = tk_framework_desktopserver.Server( port=integration_settings.port, low_level_debug=integration_settings.low_level_debug, whitelist=integration_settings.whitelist, keys_path=integration_settings.certificate_folder) # This might throw a PortBusyError. server.start() splash.hide() return server, True except tk_framework_desktopserver.PortBusyError: # Gracefully let the user know that the Desktop might already be running. logger.exception("Could not start the browser integration:") splash.hide() return None, __query_quit_or_continue_launching( "Browser integration failed to start because port %d is already in use. The Shotgun " "Desktop may already be running on your machine." % integration_settings.port, app_bootstrap) except Exception, e: return None, __handle_unexpected_exception_during_websocket_init( splash, app_bootstrap, e) class _BootstrapProxy(object):
def main(**kwargs): """ Main :params app_bootstrap: AppBootstrap instance, used to get information from the installed application as well as updating the startup description location. See https://github.com/shotgunsoftware/tk-desktop-internal/blob/a31e9339b7e438cd111fb8f4a2b0436e77c98a17/Common/Shotgun/python/bootstrap.py#L133 for more info. :returns: Error code for the process. """ app_bootstrap = _BootstrapProxy(kwargs["app_bootstrap"]) # Do not import sgtk globally to avoid using the wrong sgtk once we bootstrap in # the right config. import sgtk global logger # Older versions of the desktop on Windows logged at %APPDATA%\Shotgun\tk-desktop.log. Notify the user that # this logging location is deprecated and the logs are now at %APPDATA%\Shotgun\Logs\tk-desktop.log if sys.platform == "win32" and LooseVersion(app_bootstrap.get_version()) <= "v1.3.6": logger.info( "Logging at this location will now stop and resume at {0}\\tk-desktop.log".format( sgtk.LogManager().log_folder ) ) logger.info( "If you see any more logs past this line, you need to upgrade your site configuration to " "the latest core and apps using 'tank core' and 'tank updates'." ) # Core will take over logging app_bootstrap.tear_down_logging() sgtk.LogManager().initialize_base_file_handler("tk-desktop") logger = sgtk.LogManager.get_logger(__name__) logger.debug("Running main from %s" % __file__) # Create some ui related objects app, splash = __init_app() # We might crash before even initializing the authenticator, so instantiate # it right away. shotgun_authenticator = None # Shotgun Desktop startup has always been logging every debug string to disk since the new authentication from 0.16 # was released and the startup has been difficult to work with and debug, so keep that logic in place during the # startup sequence. It will be restored during the ToolkitManager's pre_engine_start_callback. __backup_global_debug_flag() sgtk.LogManager().global_debug = True from sgtk import authentication from sgtk.descriptor import InvalidAppStoreCredentialsError from sgtk.authentication import ShotgunSamlUser try: # Reading user settings from disk. settings = sgtk.util.UserSettings() # It is very important to decouple logging in from creating the shotgun authenticator. # If there is an error during auto login, for example proxy settings changed and you # can't connect anymore, we need to be able to log the user out. shotgun_authenticator = sgtk.authentication.ShotgunAuthenticator() __optional_state_cleanup(splash, shotgun_authenticator, app_bootstrap) user = __do_login( splash, shotgun_authenticator ) if not user: logger.info("Login canceled. Quitting.") return 0 # In the case where the site is using SSO, the user needs to renew # its claims regularily. So we kick off a separate newewal thread. if isinstance(user, ShotgunSamlUser): logger.debug("Starting SSO claims renewal") user.start_claims_renewal() else: logger.debug("Not using SSO") # Now that we are logged, we can proceed with launching the # application. exit_code = __launch_app( app, splash, user, app_bootstrap, settings ) return exit_code except RequestRestartException: subprocess.Popen(sys.argv, close_fds=True) return 0 except authentication.AuthenticationCancelled: # The user cancelled an authentication request while the app was running, log him out. splash.hide() shotgun_authenticator.clear_default_user() return 0 except InvalidAppStoreCredentialsError, e: __handle_exception(splash, shotgun_authenticator, str(e)) return -1
try: # Makes sure that the certificate has been created on disk and registered with the OS (or browser on Linux). __ensure_certificate_ready(app_bootstrap, tk_framework_desktopserver, integration_settings.certificate_folder) # Launch the server server = tk_framework_desktopserver.Server( port=integration_settings.port, low_level_debug=integration_settings.low_level_debug, whitelist=integration_settings.whitelist, keys_path=integration_settings.certificate_folder ) # This might throw a PortBusyError. server.start() splash.hide() return server, True except tk_framework_desktopserver.PortBusyError: # Gracefully let the user know that the Desktop might already be running. logger.exception("Could not start the browser integration:") splash.hide() return None, __query_quit_or_continue_launching( "Browser integration failed to start because port %d is already in use. The Shotgun " "Desktop may already be running on your machine." % integration_settings.port, app_bootstrap ) except Exception, e: return None, __handle_unexpected_exception_during_websocket_init(splash, app_bootstrap, e) class _BootstrapProxy(object):