def glimpse_version(_url): """Handler for glimpse://version.""" src = jinja.render('version.html', title='Version info', version=version.version(), copyright=glimpsebrowser.__copyright__) return 'text/html', src
def _gather_crash_info(self): """Gather crash information to display. Args: pages: A list of lists of the open pages (URLs as strings) cmdhist: A list with the command history (as strings) exc: An exception tuple (type, value, traceback) """ try: application = QApplication.instance() launch_time = application.launch_time.ctime() crash_time = datetime.datetime.now().ctime() text = 'Launch: {}\nCrash: {}'.format(launch_time, crash_time) self._crash_info.append(('Timestamps', text)) except Exception: self._crash_info.append(("Launch time", traceback.format_exc())) try: self._crash_info.append(("Version info", version.version())) except Exception: self._crash_info.append(("Version info", traceback.format_exc())) try: self._crash_info.append( ("Config", config.instance.dump_userconfig())) except Exception: self._crash_info.append(("Config", traceback.format_exc())) try: self._crash_info.append(("Environment", _get_environment_vars())) except Exception: self._crash_info.append(("Environment", traceback.format_exc()))
def run(args): """Initialize everything and run the application.""" if args.temp_basedir: args.basedir = tempfile.mkdtemp(prefix='glimpsebrowser-basedir-') quitter = Quitter(args) objreg.register('quitter', quitter) log.init.debug("Initializing directories...") standarddir.init(args) utils.preload_resources() log.init.debug("Initializing config...") configinit.early_init(args) global q_app q_app = Application(args) q_app.setOrganizationName("glimpsebrowser") q_app.setApplicationName("glimpsebrowser") q_app.setDesktopFileName("org.glimpsebrowser.glimpsebrowser") q_app.setApplicationVersion(glimpsebrowser.__version__) q_app.lastWindowClosed.connect(quitter.on_last_window_closed) if args.version: print(version.version()) sys.exit(usertypes.Exit.ok) crash_handler = crashsignal.CrashHandler(app=q_app, quitter=quitter, args=args, parent=q_app) crash_handler.activate() objreg.register('crash-handler', crash_handler) signal_handler = crashsignal.SignalHandler(app=q_app, quitter=quitter, parent=q_app) signal_handler.activate() objreg.register('signal-handler', signal_handler) try: server = ipc.send_or_listen(args) except ipc.Error: # ipc.send_or_listen already displays the error message for us. # We didn't really initialize much so far, so we just quit hard. sys.exit(usertypes.Exit.err_ipc) if server is None: if args.backend is not None: log.init.warning("Backend from the running instance will be used") sys.exit(usertypes.Exit.ok) else: server.got_args.connect(lambda args, target_arg, cwd: process_pos_args( args, cwd=cwd, via_ipc=True, target_arg=target_arg)) init(args, crash_handler) ret = qt_mainloop() return ret
def dump_exception_info(exc, pages, cmdhist, qobjects): """Dump exception info to stderr. Args: exc: An exception tuple (type, value, traceback) pages: A list of lists of the open pages (URLs as strings) cmdhist: A list with the command history (as strings) qobjects: A list of all QObjects as string. """ print(file=sys.stderr) print("\n\n===== Handling exception with --no-err-windows... =====\n\n", file=sys.stderr) print("\n---- Exceptions ----", file=sys.stderr) print(''.join(traceback.format_exception(*exc)), file=sys.stderr) print("\n---- Version info ----", file=sys.stderr) try: print(version.version(), file=sys.stderr) except Exception: traceback.print_exc() print("\n---- Config ----", file=sys.stderr) try: print(config.instance.dump_userconfig(), file=sys.stderr) except Exception: traceback.print_exc() print("\n---- Commandline args ----", file=sys.stderr) print(' '.join(sys.argv[1:]), file=sys.stderr) print("\n---- Open pages ----", file=sys.stderr) print('\n\n'.join('\n'.join(e) for e in pages), file=sys.stderr) print("\n---- Command history ----", file=sys.stderr) print('\n'.join(cmdhist), file=sys.stderr) print("\n---- Objects ----", file=sys.stderr) print(qobjects, file=sys.stderr) print("\n---- Environment ----", file=sys.stderr) try: print(_get_environment_vars(), file=sys.stderr) except Exception: traceback.print_exc()
def test_version_output(params, stubs, monkeypatch, config_stub): """Test version.version().""" class FakeWebEngineSettings: default_user_agent = ('Toaster/4.0.4 Chrome/CHROMIUMVERSION ' 'Teapot/4.1.8') config.instance.config_py_loaded = params.config_py_loaded import_path = os.path.abspath('/IMPORTPATH') patches = { 'glimpsebrowser.__file__': os.path.join(import_path, '__init__.py'), 'glimpsebrowser.__version__': 'VERSION', '_git_str': lambda: ('GIT COMMIT' if params.git_commit else None), 'platform.python_implementation': lambda: 'PYTHON IMPLEMENTATION', 'platform.python_version': lambda: 'PYTHON VERSION', 'sys.executable': 'EXECUTABLE PATH', 'PYQT_VERSION_STR': 'PYQT VERSION', 'earlyinit.qt_version': lambda: 'QT VERSION', '_module_versions': lambda: ['MODULE VERSION 1', 'MODULE VERSION 2'], '_pdfjs_version': lambda: 'PDFJS VERSION', 'QSslSocket': FakeQSslSocket('SSL VERSION', params.ssl_support), 'platform.platform': lambda: 'PLATFORM', 'platform.architecture': lambda: ('ARCHITECTURE', ''), '_os_info': lambda: ['OS INFO 1', 'OS INFO 2'], '_path_info': lambda: { 'PATH DESC': 'PATH NAME' }, 'QApplication': (stubs.FakeQApplication(style='STYLE') if params.style else stubs.FakeQApplication(instance=None)), 'QLibraryInfo.location': (lambda _loc: 'QT PATH'), 'sql.version': lambda: 'SQLITE VERSION', '_uptime': lambda: datetime.timedelta(hours=1, minutes=23, seconds=45), '_autoconfig_loaded': lambda: ("yes" if params.autoconfig_loaded else "no"), } substitutions = { 'git_commit': '\nGit commit: GIT COMMIT' if params.git_commit else '', 'style': '\nStyle: STYLE' if params.style else '', 'qt': 'QT VERSION', 'frozen': str(params.frozen), 'import_path': import_path, 'python_path': 'EXECUTABLE PATH', 'uptime': "1:23:45", 'autoconfig_loaded': "yes" if params.autoconfig_loaded else "no", } if params.config_py_loaded: substitutions["config_py_loaded"] = "{} has been loaded".format( standarddir.config_py()) else: substitutions["config_py_loaded"] = "no config.py was loaded" if params.with_webkit: patches['qWebKitVersion'] = lambda: 'WEBKIT VERSION' patches['objects.backend'] = usertypes.Backend.QtWebKit patches['webenginesettings'] = None substitutions['backend'] = 'new QtWebKit (WebKit WEBKIT VERSION)' else: monkeypatch.delattr(version, 'qtutils.qWebKitVersion', raising=False) patches['objects.backend'] = usertypes.Backend.QtWebEngine substitutions['backend'] = 'QtWebEngine (Chromium CHROMIUMVERSION)' patches['webenginesettings'] = FakeWebEngineSettings patches['QWebEngineProfile'] = True if params.known_distribution: patches['distribution'] = lambda: version.DistributionInfo( parsed=version.Distribution.arch, version=None, pretty='LINUX DISTRIBUTION', id='arch') substitutions['linuxdist'] = ('\nLinux distribution: ' 'LINUX DISTRIBUTION (arch)') substitutions['osinfo'] = '' else: patches['distribution'] = lambda: None substitutions['linuxdist'] = '' substitutions['osinfo'] = 'OS INFO 1\nOS INFO 2\n' substitutions['ssl'] = 'SSL VERSION' if params.ssl_support else 'no' for name, val in patches.items(): monkeypatch.setattr('glimpsebrowser.utils.version.' + name, val) if params.frozen: monkeypatch.setattr(sys, 'frozen', True, raising=False) else: monkeypatch.delattr(sys, 'frozen', raising=False) template = textwrap.dedent(""" glimpsebrowser vVERSION{git_commit} Backend: {backend} PYTHON IMPLEMENTATION: PYTHON VERSION Qt: {qt} PyQt: PYQT VERSION MODULE VERSION 1 MODULE VERSION 2 pdf.js: PDFJS VERSION sqlite: SQLITE VERSION QtNetwork SSL: {ssl} {style} Platform: PLATFORM, ARCHITECTURE{linuxdist} Frozen: {frozen} Imported from {import_path} Using Python from {python_path} Qt library executable path: QT PATH, data path: QT PATH {osinfo} Paths: PATH DESC: PATH NAME Autoconfig loaded: {autoconfig_loaded} Config.py: {config_py_loaded} Uptime: {uptime} """.lstrip('\n')) expected = template.rstrip('\n').format(**substitutions) assert version.version() == expected