def setTopWindow(self, top_window):
        super().setTopWindow(top_window)

        tm = self.table_view.table_model
        self.all_visible_table_columns = (tm.col_staged, tm.col_status, tm.col_name, tm.col_date)

        prefs = self.app.prefs.git
        if prefs.program is not None:
            git.Git.GIT_PYTHON_GIT_EXECUTABLE = str(prefs.program)

        self.log.info("Git using program %s" % (git.Git.GIT_PYTHON_GIT_EXECUTABLE,))

        if "GIT_ASKPASS" in os.environ:
            self.log.info("Using user's GIT_ASKPASS program %s" % (os.environ["GIT_ASKPASS"],))
            return

        self.askpass_server = wb_git_askpass_server.WbGitAskPassServer(self.app, self)

        devel_fallback = False
        self.askpass_server.start()
        if sys.platform == "win32":
            askpass = wb_platform_specific.getAppDir() / "scm-workbench-askpass.exe"
            if not askpass.exists():
                self.log.info("Cannot find %s" % (askpass,))
                # assume in development environment
                askpass = wb_platform_specific.getAppDir() / "scm-workbench-askpass.py"

        else:
            askpass = wb_platform_specific.getAppDir() / "scm-workbench-askpass"

        if not askpass.exists():
            self.log.error("Cannot find %s" % (askpass,))
            return

        os.environ["GIT_ASKPASS"] = str(askpass)
        self.log.info("Using Workbench's GIT_ASKPASS program")
Пример #2
0
def initCallbackServer(app):
    #pylint disable=global-statement
    global __callback_server
    assert __callback_server is None, 'Cannot call initCallbackServer twice'

    __callback_server = wb_git_callback_server.WbGitCallbackServer(app)

    __callback_server.start()
    if sys.platform == 'win32':
        callback = wb_platform_specific.getAppDir(
        ) / 'scm-workbench-git-callback.exe'
        if not callback.exists():
            app.log.info('Cannot find %s' % (callback, ))
            # assume in development environment
            callback = wb_platform_specific.getAppDir(
            ) / 'scm_workbench_git_callback.cmd'
    else:
        callback = wb_platform_specific.getAppDir(
        ) / 'scm-workbench-git-callback'

    if not callback.exists():
        app.log.error('Cannot find %s' % (callback, ))
        return

    if 'GIT_ASKPASS' in os.environ:
        app.log.info("Using user's GIT_ASKPASS program %s" %
                     (os.environ['GIT_ASKPASS'], ))

    else:
        git_extra_environ['GIT_ASKPASS'] = '******' % (str(callback), )
        app.log.info("Using Workbench's GIT_ASKPASS program")

    git_extra_environ['GIT_SEQUENCE_EDITOR'] = '"%s" sequence-editor' % (
        str(callback), )
    git_extra_environ['GIT_EDITOR'] = '"%s" editor' % (str(callback), )
    app.log.info("Setup Workbench's GIT callback program")
Пример #3
0
    def __init__(self, app_name_parts, args, debug_class, extra_loggers=None):
        self.top_window = None
        self.main_window = None
        # used to set the names of files and windows for this app
        self.app_name_parts = app_name_parts

        # setup the platform specific support
        wb_platform_specific.setupPlatform(self.app_name_parts, sys.argv[0])

        if extra_loggers is None:
            extra_loggers = []

        wb_logging.AppLoggingMixin.__init__(self, extra_loggers)
        wb_background_thread.BackgroundWorkMixin.__init__(self)

        self.may_quit = False

        self.args = args

        self.startup_dir = os.getcwd()

        self.all_temp_files = []
        self.all_processes = []

        # on the Mac the app's cwd is the resource folder
        if wb_platform_specific.isMacOs():
            if 'PWD' in os.environ:
                os.chdir(os.environ['PWD'])
            else:
                os.chdir(os.environ['HOME'])

        self.__debug_noredirect = False
        self.__debug = False
        self.__trace = False
        self.__git_debug = False
        self.__log_stdout = False

        self.all_positional_args = []

        debug_config_string = None

        while len(args) > 1:
            arg = args[1]

            if arg.startswith('-psn_'):
                del args[1]

            elif arg.startswith('--name='):
                self.opt_name = arg[len('--name='):]
                del args[1]

            elif arg == '--noredirect':
                self.__debug_noredirect = True
                del args[1]

            elif arg == '--log-stdout':
                self.__log_stdout = True
                del args[1]

            elif arg == '--debug' and len(args) > 2:
                self.__debug = True
                debug_config_string = args[2]
                del args[1]
                del args[1]

            elif arg == '--start-dir' and len(args) > 2:
                os.chdir(args[2])
                del args[1]
                del args[1]

            elif arg == '--':
                break

            elif self.optionParse(args):
                pass

            elif arg.startswith('--'):
                print('Error: unknown option %s' % (arg, ))
                break

            else:
                self.all_positional_args.append(arg)
                del args[1]

        self.args = args
        self.app_name = os.path.basename(args[0])
        self.app_dir = os.path.dirname(args[0])
        if self.app_dir == '':
            self.app_dir = self.startup_dir

        locale_path = wb_platform_specific.getLocalePath()
        self.translation = gettext.translation(
            '-'.join([part.lower() for part in self.app_name_parts]),
            str(locale_path),
            # language defaults
            fallback=True)

        import builtins
        # T_( 'non plural' )
        builtins.__dict__['T_'] = self.translation.gettext
        # S_( 'singular', 'plural', n )
        builtins.__dict__['S_'] = self.translation.ngettext
        # U_( 'static string' )
        # define here to keep mypy happy - humm  does not work...
        builtins.__dict__['U_'] = U_

        # Debug settings
        self.__last_client_error = []

        # part 1 of settings up logging
        self.setupLogging()

        # and debug trace
        self.debug_options = debug_class(self.log)
        if debug_config_string is not None:
            self.debug_options.setDebug(debug_config_string)

        self.debugLogApp = self.debug_options.debugLogApp

        self.setupAppDebug()

        # these messages just go into the log file not the log widget
        self.log.info('startup_dir %s' % (self.startup_dir, ))
        self.log.info('locale_path %s' % (locale_path, ))
        self.log.info('find %r' %
                      (gettext.find('scm-workbench', str(locale_path)), ))
        self.log.info('info %r' % (self.translation.info(), ))

        for path in sys.path:
            self.log.info('sys.path: %r' % (path, ))

        for var in sorted(os.environ):
            self.log.info('Environment %s=%s' % (var, os.environ[var]))

        self.log.info('app_dir %s' % (wb_platform_specific.getAppDir(), ))
        self.log.info('preferences_dir %s' %
                      (wb_platform_specific.getPreferencesDir(), ))
        self.log.info('Qt libraryPaths %r' %
                      (QtWidgets.QApplication.libraryPaths(), ))

        QtWidgets.QApplication.__init__(self, [sys.argv[0]])

        self.__is_dark_mode = self.palette().text().color().lightnessF(
        ) > self.palette().window().color().lightnessF()
        self.prefs = None

        # capture logs into the log widget
        self.__wb_log = wb_logging.WbLog(self)

        # background threads depend on Qt
        self.startBackgroundThread()
        self.log.infoheader(
            T_('Starting %s') % (' '.join(self.app_name_parts), ))

        self.prefs_manager = self.createPreferencesManager()
        try:
            self.log.info('Reading preferences')
            self.prefs_manager.readPreferences()

        except xml_preferences.ParseError as e:
            # the preferences are defaulted on a failure to load
            self.log.error(str(e))

        self.prefs = self.prefs_manager.getPreferences()

        if self.isDarkMode():
            self.setDarkPalette()
            self.__wb_log.initStyles()

        self.code_font = None

        # part 2 of settings up logging is done in main window code
        self.main_window = self.createMainWindow()

        self.applicationStateChanged.connect(
            self.applicationStateChangedHandler)
Пример #4
0
    def __init__( self, app_name_parts, args, debug_class, extra_loggers=None ):
        self.top_window = None
        self.main_window = None
        # used to set the names of files and windows for this app
        self.app_name_parts = app_name_parts

        # setup the platform specific support
        wb_platform_specific.setupPlatform( self.app_name_parts, sys.argv[0] )

        QtWidgets.QApplication.__init__( self, [sys.argv[0]] )

        if extra_loggers is None:
            extra_loggers = []

        wb_logging.AppLoggingMixin.__init__( self, extra_loggers )
        wb_background_thread.BackgroundWorkMixin.__init__( self )

        self.may_quit = False

        self.args = args

        self.startup_dir = os.getcwd()

        self.all_temp_files = []
        self.all_processes = []

        # on the Mac the app's cwd is the resource folder
        if wb_platform_specific.isMacOs():
            if 'PWD' in os.environ:
                os.chdir( os.environ['PWD'] )
            else:
                os.chdir( os.environ['HOME'] )

        self.__debug_noredirect = False
        self.__debug = False
        self.__trace = False
        self.__git_debug = False
        self.__log_stdout = False

        self.all_positional_args = []

        debug_config_string = None

        while len(args) > 1:
            arg = args[ 1 ]

            if arg.startswith( '-psn_' ):
                del args[ 1 ]

            elif arg.startswith( '--name=' ):
                self.opt_name = arg[len('--name='):]
                del args[ 1 ]

            elif arg == '--noredirect':
                self.__debug_noredirect = True
                del args[ 1 ]

            elif arg == '--log-stdout':
                self.__log_stdout = True
                del args[ 1 ]

            elif arg == '--debug' and len(args) > 2:
                self.__debug = True
                debug_config_string = args[2]
                del args[ 1 ]
                del args[ 1 ]

            elif arg == '--start-dir' and len(args) > 2:
                os.chdir( args[2]  )
                del args[1]
                del args[1]

            elif arg == '--':
                break

            elif self.optionParse( args ):
                pass

            elif arg.startswith( '--' ):
                print( 'Error: unknown option %s' % (arg,) )
                break

            else:
                self.all_positional_args.append( arg )
                del args[1]

        self.args = args
        self.app_name = os.path.basename( args[0] )
        self.app_dir = os.path.dirname( args[0] )
        if self.app_dir == '':
            self.app_dir = self.startup_dir

        self.background_thread.start()

        locale_path = wb_platform_specific.getLocalePath()
        self.translation = gettext.translation(
                '-'.join( [part.lower() for part in self.app_name_parts] ),
                str(locale_path),
                # language defaults
                fallback=True )

        import builtins
        # T_( 'non plural' )
        builtins.__dict__['T_'] = self.translation.gettext
        # S_( 'singular', 'plural', n )
        builtins.__dict__['S_'] = self.translation.ngettext
        # U_( 'static string' )
        # define here to keep mypy happy - humm  does not work...
        builtins.__dict__['U_'] = U_

        # Debug settings
        self.__last_client_error = []

        # part 1 of settings up logging

        self.setupLogging()

        # and debug trace
        self._debug_options = debug_class( self.log )
        if debug_config_string is not None:
            self._debug_options.setDebug( debug_config_string )

        self._debugApp = self._debug_options._debugApp

        self.setupScmDebug()

        # these messages just go into the log file not the log widget
        self.log.info( 'startup_dir %s' % (self.startup_dir,) )
        self.log.info( 'locale_path %s' % (locale_path,) )
        self.log.info( 'find %r' % (gettext.find( 'scm-workbench', str(locale_path) ),) )
        self.log.info( 'info %r' % (self.translation.info(),) )

        for path in sys.path:
            self.log.info( 'sys.path: %r' % (path,) )

        for var in sorted( os.environ.keys() ):
            self.log.info( 'Environment %s=%s' % (var, os.environ[ var ]) )

        self.log.info( 'app_dir %s' % (wb_platform_specific.getAppDir(),) )
        self.log.info( 'preferences_dir %s' % (wb_platform_specific.getPreferencesDir(),) )

        # and capture logs into the log widget
        self.__wb_log = wb_logging.WbLog( self )

        self.prefs_manager = self.createPreferencesManager()
        try:
            self.log.info( 'Reading preferences' )
            self.prefs_manager.readPreferences()

        except xml_preferences.ParseError as e:
            # the preferences are defaulted on a failure to load
            self.log.error( str(e) )

        self.prefs = self.prefs_manager.getPreferences()

        # part 2 of settings up logging is done in main window code
        self.main_window = self.createMainWindow()

        self.applicationStateChanged.connect( self.applicationStateChangedHandler )