Ejemplo n.º 1
0
 def test_system_datadir_not_exist_linux(self, monkeypatch, tmpdir,
                                         fake_args):
     """Test that system-wide path isn't used on linux if path not exist."""
     fake_args.basedir = str(tmpdir)
     standarddir.init(fake_args)
     monkeypatch.setattr(os.path, 'exists', lambda path: False)
     assert standarddir.system_data() == standarddir.data()
Ejemplo n.º 2
0
 def test_system_datadir_unsupportedos(self, monkeypatch, tmpdir,
                                       fake_args):
     """Test that system-wide path is not used on non-Linux OS."""
     fake_args.basedir = str(tmpdir)
     standarddir.init(fake_args)
     monkeypatch.setattr('sys.platform', "potato")
     assert standarddir.system_data() == standarddir.data()
Ejemplo n.º 3
0
 def test_cache(self, monkeypatch, tmpdir):
     """Test cache dir with XDG_CACHE_HOME not set."""
     monkeypatch.setenv('HOME', str(tmpdir))
     monkeypatch.delenv('XDG_CACHE_HOME', raising=False)
     standarddir.init(None)
     expected = tmpdir / '.cache' / 'qutebrowser_test'
     assert standarddir.cache() == expected
Ejemplo n.º 4
0
    def _init_modules(self):
        """Initialize all 'modules' which need to be initialized."""
        log.init.debug("Initializing readline-bridge...")
        readline_bridge = readline.ReadlineBridge()
        objreg.register('readline-bridge', readline_bridge)

        log.init.debug("Initializing directories...")
        standarddir.init()
        log.init.debug("Initializing config...")
        config.init(self._args)
        log.init.debug("Initializing crashlog...")
        self._handle_segfault()
        log.init.debug("Initializing websettings...")
        websettings.init()
        log.init.debug("Initializing quickmarks...")
        quickmark_manager = quickmarks.QuickmarkManager()
        objreg.register('quickmark-manager', quickmark_manager)
        log.init.debug("Initializing proxy...")
        proxy.init()
        log.init.debug("Initializing cookies...")
        cookie_jar = cookies.CookieJar(self)
        objreg.register('cookie-jar', cookie_jar)
        log.init.debug("Initializing cache...")
        diskcache = cache.DiskCache(self)
        objreg.register('cache', diskcache)
        log.init.debug("Initializing main window...")
        win_id = mainwindow.MainWindow.spawn(
            False if self._args.nowindow else True)
        main_window = objreg.get('main-window', scope='window', window=win_id)
        self.setActiveWindow(main_window)
Ejemplo n.º 5
0
 def test_data(self, monkeypatch, tmpdir):
     """Test data dir with XDG_DATA_HOME not set."""
     monkeypatch.setenv('HOME', str(tmpdir))
     monkeypatch.delenv('XDG_DATA_HOME', raising=False)
     standarddir.init(None)
     expected = tmpdir / '.local' / 'share' / 'qutebrowser_test'
     assert standarddir.data() == str(expected)
Ejemplo n.º 6
0
def test_init(mocker, tmpdir, args_kind):
    """Do some sanity checks for standarddir.init().

    Things like _init_cachedir_tag() are tested in more detail in other tests.
    """
    assert standarddir._locations == {}

    m_windows = mocker.patch('qutebrowser.utils.standarddir._move_windows')
    m_mac = mocker.patch('qutebrowser.utils.standarddir._move_macos')
    if args_kind == 'normal':
        args = types.SimpleNamespace(basedir=None)
    elif args_kind == 'basedir':
        args = types.SimpleNamespace(basedir=str(tmpdir))
    else:
        assert args_kind == 'none'
        args = None

    standarddir.init(args)

    assert standarddir._locations != {}
    if args_kind == 'normal':
        if sys.platform == 'darwin':
            assert not m_windows.called
            assert m_mac.called
        elif os.name == 'nt':
            assert m_windows.called
            assert not m_mac.called
        else:
            assert not m_windows.called
            assert not m_mac.called
    else:
        assert not m_windows.called
        assert not m_mac.called
Ejemplo n.º 7
0
 def test_cache(self):
     """Test cache dir with XDG_CACHE_HOME not set."""
     env = {'HOME': self.temp_dir, 'XDG_CACHE_HOME': None}
     with helpers.environ_set_temp(env):
         standarddir.init(None)
         expected = os.path.join(self.temp_dir, '.cache', 'qutebrowser')
         self.assertEqual(standarddir.cache(), expected)
Ejemplo n.º 8
0
 def test_basedir(self, tmpdir, typ):
     """Test --basedir."""
     expected = str(tmpdir / typ)
     args = types.SimpleNamespace(basedir=str(tmpdir))
     standarddir.init(args)
     func = getattr(standarddir, typ)
     assert func() == expected
Ejemplo n.º 9
0
 def test_config_none(self):
     """Test initializing with config path set to None."""
     args = types.SimpleNamespace(confdir='')
     with helpers.environ_set_temp(self.env):
         standarddir.init(args)
         config.init()
     self.assertFalse(os.listdir(self.conf_path))
Ejemplo n.º 10
0
 def test_config(self, monkeypatch, tmpdir):
     """Test config dir with XDG_CONFIG_HOME not set."""
     monkeypatch.setenv('HOME', str(tmpdir))
     monkeypatch.delenv('XDG_CONFIG_HOME', raising=False)
     standarddir.init(None)
     expected = tmpdir / '.config' / 'qutebrowser_test'
     assert standarddir.config() == str(expected)
Ejemplo n.º 11
0
 def test_data(self):
     """Test data dir with XDG_DATA_HOME not set."""
     env = {'HOME': self.temp_dir, 'XDG_DATA_HOME': None}
     with helpers.environ_set_temp(env):
         standarddir.init(None)
         expected = os.path.join(self.temp_dir, '.local', 'share',
                                 'qutebrowser')
         self.assertEqual(standarddir.data(), expected)
Ejemplo n.º 12
0
 def test_config_none(self, monkeypatch):
     """Test initializing with config path set to None."""
     args = types.SimpleNamespace(confdir='', datadir='', cachedir='')
     for k, v in self.env.items():
         monkeypatch.setenv(k, v)
     standarddir.init(args)
     config.init()
     assert not os.listdir(str(self.conf_path))
Ejemplo n.º 13
0
 def test_runtimedir(self, tmpdir, monkeypatch):
     """Test runtime dir (which has no args)."""
     monkeypatch.setattr(
         'qutebrowser.utils.standarddir.QStandardPaths.writableLocation',
         lambda _typ: str(tmpdir))
     args = types.SimpleNamespace(confdir=None, cachedir=None, datadir=None)
     standarddir.init(args)
     assert standarddir.runtime() == str(tmpdir)
Ejemplo n.º 14
0
 def test_confdir_none(self, mocker):
     """Test --confdir with None given."""
     # patch makedirs to a noop so we don't really create a directory
     mocker.patch('qutebrowser.utils.standarddir.os.makedirs')
     args = types.SimpleNamespace(confdir=None, cachedir=None, datadir=None,
                                  basedir=None)
     standarddir.init(args)
     assert standarddir.config().split(os.sep)[-1] == 'qute_test'
Ejemplo n.º 15
0
 def test_basedir_relative(self, tmpdir):
     """Test --basedir with a relative path."""
     basedir = (tmpdir / 'basedir')
     basedir.ensure(dir=True)
     with tmpdir.as_cwd():
         args = types.SimpleNamespace(basedir='basedir')
         standarddir.init(args)
         assert standarddir.config() == str(basedir / 'config')
Ejemplo n.º 16
0
def run(args):
    """Initialize everything and run the application."""
    if args.temp_basedir:
        args.basedir = tempfile.mkdtemp(prefix='qutebrowser-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 qApp
    qApp = Application(args)
    qApp.setOrganizationName("qutebrowser")
    qApp.setApplicationName("qutebrowser")
    qApp.setDesktopFileName("qutebrowser")
    qApp.setApplicationVersion(qutebrowser.__version__)
    qApp.lastWindowClosed.connect(quitter.on_last_window_closed)

    if args.version:
        print(version.version())
        sys.exit(usertypes.Exit.ok)

    crash_handler = crashsignal.CrashHandler(app=qApp,
                                             quitter=quitter,
                                             args=args,
                                             parent=qApp)
    crash_handler.activate()
    objreg.register('crash-handler', crash_handler)

    signal_handler = crashsignal.SignalHandler(app=qApp,
                                               quitter=quitter,
                                               parent=qApp)
    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
Ejemplo n.º 17
0
def _init_modules(args, crash_handler):
    """Initialize all 'modules' which need to be initialized.

    Args:
        args: The argparse namespace.
        crash_handler: The CrashHandler instance.
    """
    # pylint: disable=too-many-statements
    log.init.debug("Initializing save manager...")
    save_manager = savemanager.SaveManager(qApp)
    objreg.register('save-manager', save_manager)
    save_manager.add_saveable('version', _save_version)
    log.init.debug("Initializing network...")
    networkmanager.init()
    log.init.debug("Initializing readline-bridge...")
    readline_bridge = readline.ReadlineBridge()
    objreg.register('readline-bridge', readline_bridge)
    log.init.debug("Initializing directories...")
    standarddir.init(args)
    log.init.debug("Initializing config...")
    config.init(qApp)
    save_manager.init_autosave()
    log.init.debug("Initializing web history...")
    history.init(qApp)
    log.init.debug("Initializing crashlog...")
    if not args.no_err_windows:
        crash_handler.handle_segfault()
    log.init.debug("Initializing sessions...")
    sessions.init(qApp)
    log.init.debug("Initializing js-bridge...")
    js_bridge = qutescheme.JSBridge(qApp)
    objreg.register('js-bridge', js_bridge)
    log.init.debug("Initializing websettings...")
    websettings.init()
    log.init.debug("Initializing adblock...")
    host_blocker = adblock.HostBlocker()
    host_blocker.read_hosts()
    objreg.register('host-blocker', host_blocker)
    log.init.debug("Initializing quickmarks...")
    quickmark_manager = urlmarks.QuickmarkManager(qApp)
    objreg.register('quickmark-manager', quickmark_manager)
    log.init.debug("Initializing bookmarks...")
    bookmark_manager = urlmarks.BookmarkManager(qApp)
    objreg.register('bookmark-manager', bookmark_manager)
    log.init.debug("Initializing proxy...")
    proxy.init()
    log.init.debug("Initializing cookies...")
    cookie_jar = cookies.CookieJar(qApp)
    objreg.register('cookie-jar', cookie_jar)
    log.init.debug("Initializing cache...")
    diskcache = cache.DiskCache(qApp)
    objreg.register('cache', diskcache)
    log.init.debug("Initializing completions...")
    completionmodels.init()
    log.init.debug("Misc initialization...")
    _maybe_hide_mouse_cursor()
    objreg.get('config').changed.connect(_maybe_hide_mouse_cursor)
Ejemplo n.º 18
0
 def test_config_none(self, monkeypatch, env):
     """Test initializing with config path set to None."""
     args = types.SimpleNamespace(confdir='', datadir='', cachedir='',
                                  basedir=None)
     for k, v in env.items():
         monkeypatch.setenv(k, v)
     standarddir.init(args)
     config.init()
     assert not os.listdir(env['XDG_CONFIG_HOME'])
Ejemplo n.º 19
0
def run(args):
    """Initialize everything and run the application."""
    if args.temp_basedir:
        args.basedir = tempfile.mkdtemp(prefix='qutebrowser-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("qutebrowser")
    q_app.setApplicationName("qutebrowser")
    q_app.setDesktopFileName("qutebrowser")
    q_app.setApplicationVersion(qutebrowser.__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
Ejemplo n.º 20
0
 def test_runtimedir(self, tmpdir, monkeypatch):
     """Test runtime dir (which has no args)."""
     monkeypatch.setattr(
         'qutebrowser.utils.standarddir.QStandardPaths.writableLocation',
         lambda _typ: str(tmpdir))
     args = types.SimpleNamespace(confdir=None, cachedir=None, datadir=None,
                                  basedir=None)
     standarddir.init(args)
     assert standarddir.runtime() == str(tmpdir / 'qute_test')
Ejemplo n.º 21
0
def _init_modules(args, crash_handler):
    """Initialize all 'modules' which need to be initialized.

    Args:
        args: The argparse namespace.
        crash_handler: The CrashHandler instance.
    """
    # pylint: disable=too-many-statements
    log.init.debug("Initializing save manager...")
    save_manager = savemanager.SaveManager(qApp)
    objreg.register('save-manager', save_manager)
    save_manager.add_saveable('version', _save_version)
    log.init.debug("Initializing network...")
    networkmanager.init()
    log.init.debug("Initializing readline-bridge...")
    readline_bridge = readline.ReadlineBridge()
    objreg.register('readline-bridge', readline_bridge)
    log.init.debug("Initializing directories...")
    standarddir.init(args)
    log.init.debug("Initializing config...")
    config.init(qApp)
    save_manager.init_autosave()
    log.init.debug("Initializing web history...")
    history.init(qApp)
    log.init.debug("Initializing crashlog...")
    if not args.no_err_windows:
        crash_handler.handle_segfault()
    log.init.debug("Initializing sessions...")
    sessions.init(qApp)
    log.init.debug("Initializing js-bridge...")
    js_bridge = qutescheme.JSBridge(qApp)
    objreg.register('js-bridge', js_bridge)
    log.init.debug("Initializing websettings...")
    websettings.init()
    log.init.debug("Initializing adblock...")
    host_blocker = adblock.HostBlocker()
    host_blocker.read_hosts()
    objreg.register('host-blocker', host_blocker)
    log.init.debug("Initializing quickmarks...")
    quickmark_manager = urlmarks.QuickmarkManager(qApp)
    objreg.register('quickmark-manager', quickmark_manager)
    log.init.debug("Initializing bookmarks...")
    bookmark_manager = urlmarks.BookmarkManager(qApp)
    objreg.register('bookmark-manager', bookmark_manager)
    log.init.debug("Initializing proxy...")
    proxy.init()
    log.init.debug("Initializing cookies...")
    cookie_jar = cookies.CookieJar(qApp)
    objreg.register('cookie-jar', cookie_jar)
    log.init.debug("Initializing cache...")
    diskcache = cache.DiskCache(qApp)
    objreg.register('cache', diskcache)
    log.init.debug("Initializing completions...")
    completionmodels.init()
    log.init.debug("Misc initialization...")
    _maybe_hide_mouse_cursor()
    objreg.get('config').changed.connect(_maybe_hide_mouse_cursor)
Ejemplo n.º 22
0
 def test_config_none(self, monkeypatch, env):
     """Test initializing with config path set to None."""
     args = types.SimpleNamespace(confdir='', datadir='', cachedir='',
                                  basedir=None)
     for k, v in env.items():
         monkeypatch.setenv(k, v)
     standarddir.init(args)
     config.init()
     assert not os.listdir(env['XDG_CONFIG_HOME'])
Ejemplo n.º 23
0
 def test_confdir_none(self, mocker):
     """Test --confdir with None given."""
     # patch makedirs to a noop so we don't really create a directory
     mocker.patch('qutebrowser.utils.standarddir.os.makedirs')
     args = types.SimpleNamespace(confdir=None,
                                  cachedir=None,
                                  datadir=None,
                                  basedir=None)
     standarddir.init(args)
     assert standarddir.config().split(os.sep)[-1] == 'qute_test'
Ejemplo n.º 24
0
 def test_config_none(self, monkeypatch, env, fake_args):
     """Test initializing with config path set to None."""
     fake_args.confdir = ''
     fake_args.datadir = ''
     fake_args.cachedir = ''
     fake_args.basedir = None
     for k, v in env.items():
         monkeypatch.setenv(k, v)
     standarddir.init(fake_args)
     config.init()
     assert not os.listdir(env['XDG_CONFIG_HOME'])
Ejemplo n.º 25
0
 def test_config_none(self, monkeypatch, env, fake_args):
     """Test initializing with config path set to None."""
     fake_args.confdir = ''
     fake_args.datadir = ''
     fake_args.cachedir = ''
     fake_args.basedir = None
     for k, v in env.items():
         monkeypatch.setenv(k, v)
     standarddir.init(fake_args)
     config.init()
     assert not os.listdir(env['XDG_CONFIG_HOME'])
Ejemplo n.º 26
0
def run(args):
    """Initialize everything and run the application."""
    if args.temp_basedir:
        args.basedir = tempfile.mkdtemp(prefix='qutebrowser-basedir-')

    log.init.debug("Main process PID: {}".format(os.getpid()))

    log.init.debug("Initializing directories...")
    standarddir.init(args)
    resources.preload()

    log.init.debug("Initializing config...")
    configinit.early_init(args)

    log.init.debug("Initializing application...")
    app = Application(args)
    objects.qapp = app
    app.setOrganizationName("qutebrowser")
    app.setApplicationName("qutebrowser")
    # Default DesktopFileName is org.qutebrowser.qutebrowser, set in `get_argparser()`
    app.setDesktopFileName(args.desktop_file_name)
    app.setApplicationVersion(qutebrowser.__version__)

    if args.version:
        print(version.version_info())
        sys.exit(usertypes.Exit.ok)

    quitter.init(args)
    crashsignal.init(q_app=app, args=args, quitter=quitter.instance)

    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)

    init(args=args)

    quitter.instance.shutting_down.connect(server.shutdown)
    server.got_args.connect(
        lambda args, target_arg, cwd:
        process_pos_args(args, cwd=cwd, via_ipc=True, target_arg=target_arg))

    ret = qt_mainloop()
    return ret
Ejemplo n.º 27
0
    def test_basedir(self, tmpdir, typ):
        """Test --basedir."""
        basedir = tmpdir / 'basedir'
        assert not basedir.exists()
        args = types.SimpleNamespace(basedir=str(basedir))
        standarddir.init(args)

        func = getattr(standarddir, typ)
        func()

        assert basedir.exists()

        if os.name == 'posix':
            assert basedir.stat().mode & 0o777 == 0o700
Ejemplo n.º 28
0
    def test_basedir(self, tmpdir, typ):
        """Test --basedir."""
        basedir = tmpdir / 'basedir'
        assert not basedir.exists()
        args = types.SimpleNamespace(basedir=str(basedir))
        standarddir.init(args)

        func = getattr(standarddir, typ)
        func()

        assert basedir.exists()

        if os.name == 'posix':
            assert basedir.stat().mode & 0o777 == 0o700
Ejemplo n.º 29
0
 def _init_modules(self):
     """Initialize all 'modules' which need to be initialized."""
     # pylint: disable=too-many-statements
     log.init.debug("Initializing save manager...")
     save_manager = savemanager.SaveManager(self)
     objreg.register('save-manager', save_manager)
     save_manager.add_saveable('window-geometry', self._save_geometry)
     save_manager.add_saveable('version', self._save_version)
     log.init.debug("Initializing network...")
     networkmanager.init()
     log.init.debug("Initializing readline-bridge...")
     readline_bridge = readline.ReadlineBridge()
     objreg.register('readline-bridge', readline_bridge)
     log.init.debug("Initializing directories...")
     standarddir.init(self._args)
     log.init.debug("Initializing config...")
     config.init(self)
     save_manager.init_autosave()
     log.init.debug("Initializing web history...")
     history.init(self)
     log.init.debug("Initializing crashlog...")
     self._handle_segfault()
     log.init.debug("Initializing sessions...")
     sessions.init(self)
     log.init.debug("Initializing js-bridge...")
     js_bridge = qutescheme.JSBridge(self)
     objreg.register('js-bridge', js_bridge)
     log.init.debug("Initializing websettings...")
     websettings.init()
     log.init.debug("Initializing adblock...")
     host_blocker = adblock.HostBlocker()
     host_blocker.read_hosts()
     objreg.register('host-blocker', host_blocker)
     log.init.debug("Initializing quickmarks...")
     quickmark_manager = quickmarks.QuickmarkManager(self)
     objreg.register('quickmark-manager', quickmark_manager)
     log.init.debug("Initializing proxy...")
     proxy.init()
     log.init.debug("Initializing cookies...")
     cookie_jar = cookies.CookieJar(self)
     objreg.register('cookie-jar', cookie_jar)
     log.init.debug("Initializing cache...")
     diskcache = cache.DiskCache(self)
     objreg.register('cache', diskcache)
     log.init.debug("Initializing completions...")
     completionmodels.init()
     log.init.debug("Misc initialization...")
     self.maybe_hide_mouse_cursor()
     objreg.get('config').changed.connect(self.maybe_hide_mouse_cursor)
def test_init(tmp_path, args_kind, fake_home_envvar):
    """Do some sanity checks for standarddir.init().

    Things like _init_cachedir_tag() are tested in more detail in other tests.
    """
    assert standarddir._locations == {}

    if args_kind == 'normal':
        args = types.SimpleNamespace(basedir=None)
    elif args_kind == 'basedir':
        args = types.SimpleNamespace(basedir=str(tmp_path))
    else:
        assert args_kind == 'none'
        args = None

    standarddir.init(args)

    assert standarddir._locations != {}
Ejemplo n.º 31
0
    def test_exists_race_condition(self, mocker, tmpdir, typ):
        """Make sure there can't be a TOCTOU issue when creating the file.

        See https://github.com/The-Compiler/qutebrowser/issues/942.
        """
        (tmpdir / typ).ensure(dir=True)

        m = mocker.patch('qutebrowser.utils.standarddir.os')
        m.makedirs = os.makedirs
        m.sep = os.sep
        m.path.join = os.path.join
        m.path.exists.return_value = False

        args = types.SimpleNamespace(basedir=str(tmpdir))
        standarddir.init(args)

        func = getattr(standarddir, typ)
        func()
Ejemplo n.º 32
0
    def test_exists_race_condition(self, mocker, tmpdir, typ):
        """Make sure there can't be a TOCTOU issue when creating the file.

        See https://github.com/The-Compiler/qutebrowser/issues/942.
        """
        (tmpdir / typ).ensure(dir=True)

        m = mocker.patch('qutebrowser.utils.standarddir.os')
        m.makedirs = os.makedirs
        m.sep = os.sep
        m.path.join = os.path.join
        m.path.exists.return_value = False

        args = types.SimpleNamespace(basedir=str(tmpdir))
        standarddir.init(args)

        func = getattr(standarddir, typ)
        func()
Ejemplo n.º 33
0
def test_init(tmpdir, monkeypatch, args_kind):
    """Do some sanity checks for standarddir.init().

    Things like _init_cachedir_tag() are tested in more detail in other tests.
    """
    assert standarddir._locations == {}

    monkeypatch.setenv('HOME', str(tmpdir))

    if args_kind == 'normal':
        args = types.SimpleNamespace(basedir=None)
    elif args_kind == 'basedir':
        args = types.SimpleNamespace(basedir=str(tmpdir))
    else:
        assert args_kind == 'none'
        args = None

    standarddir.init(args)

    assert standarddir._locations != {}
Ejemplo n.º 34
0
def main():
    if configdata.DATA is None:
        configdata.init()
    standarddir.init(None)

    parser = get_argparser()
    argv = sys.argv[1:]
    args = parser.parse_args(argv)
    languages = available_languages()
    if args.cmd == 'list':
        print_list(languages)
    elif args.cmd == 'update':
        update(languages)
    elif args.cmd == 'remove-old':
        remove_old(languages)
    elif not args.language:
        sys.exit('You must provide a list of languages to install.')
    else:
        try:
            install(filter_languages(languages, args.language))
        except InvalidLanguageError as e:
            print(e)
Ejemplo n.º 35
0
def main():
    if configdata.DATA is None:
        configdata.init()
    standarddir.init(None)

    parser = get_argparser()
    argv = sys.argv[1:]
    args = parser.parse_args(argv)
    languages = available_languages()
    if args.cmd == 'list':
        print_list(languages)
    elif args.cmd == 'update':
        update(languages)
    elif args.cmd == 'remove-old':
        remove_old(languages)
    elif not args.language:
        sys.exit('You must provide a list of languages to install.')
    else:
        try:
            install(filter_languages(languages, args.language))
        except InvalidLanguageError as e:
            print(e)
Ejemplo n.º 36
0
    def _init_modules(self):
        """Initialize all 'modules' which need to be initialized."""
        log.init.debug("Initializing readline-bridge...")
        readline_bridge = readline.ReadlineBridge()
        objreg.register('readline-bridge', readline_bridge)

        log.init.debug("Initializing directories...")
        standarddir.init()
        log.init.debug("Initializing config...")
        config.init(self._args)
        log.init.debug("Initializing crashlog...")
        self._handle_segfault()
        log.init.debug("Initializing js-bridge...")
        js_bridge = qutescheme.JSBridge(self)
        objreg.register('js-bridge', js_bridge)
        log.init.debug("Initializing websettings...")
        websettings.init()
        log.init.debug("Initializing adblock...")
        host_blocker = adblock.HostBlocker()
        host_blocker.read_hosts()
        objreg.register('host-blocker', host_blocker)
        log.init.debug("Initializing quickmarks...")
        quickmark_manager = quickmarks.QuickmarkManager()
        objreg.register('quickmark-manager', quickmark_manager)
        log.init.debug("Initializing proxy...")
        proxy.init()
        log.init.debug("Initializing cookies...")
        cookie_jar = cookies.CookieJar(self)
        objreg.register('cookie-jar', cookie_jar)
        log.init.debug("Initializing cache...")
        diskcache = cache.DiskCache(self)
        objreg.register('cache', diskcache)
        log.init.debug("Initializing main window...")
        win_id = mainwindow.MainWindow.spawn(
            False if self._args.nowindow else True)
        main_window = objreg.get('main-window', scope='window', window=win_id)
        self.setActiveWindow(main_window)
Ejemplo n.º 37
0
 def test_data_explicit(self, monkeypatch, tmpdir):
     """Test data dir with XDG_DATA_HOME explicitly set."""
     monkeypatch.setenv('XDG_DATA_HOME', str(tmpdir))
     standarddir.init(None)
     assert standarddir.data() == str(tmpdir / 'qutebrowser_test')
Ejemplo n.º 38
0
 def test_config_explicit(self, monkeypatch, tmpdir):
     """Test config dir with XDG_CONFIG_HOME explicitly set."""
     monkeypatch.setenv('XDG_CONFIG_HOME', str(tmpdir))
     standarddir.init(None)
     assert standarddir.config() == str(tmpdir / 'qutebrowser_test')
Ejemplo n.º 39
0
 def test_cache_explicit(self, monkeypatch, tmpdir):
     """Test cache dir with XDG_CACHE_HOME explicitly set."""
     monkeypatch.setenv('XDG_CACHE_HOME', str(tmpdir))
     standarddir.init(None)
     assert standarddir.cache() == str(tmpdir / 'qutebrowser_test')
Ejemplo n.º 40
0
 def test_config_explicit(self, monkeypatch, tmpdir):
     """Test config dir with XDG_CONFIG_HOME explicitly set."""
     monkeypatch.setenv('XDG_CONFIG_HOME', str(tmpdir))
     standarddir.init(None)
     assert standarddir.config() == str(tmpdir / 'qutebrowser_test')
Ejemplo n.º 41
0
 def test_cache_explicit(self, monkeypatch, tmpdir):
     """Test cache dir with XDG_CACHE_HOME explicitly set."""
     monkeypatch.setenv('XDG_CACHE_HOME', str(tmpdir))
     standarddir.init(None)
     assert standarddir.cache() == str(tmpdir / 'qutebrowser_test')
Ejemplo n.º 42
0
def reset_standarddir():
    standarddir.init(None)
Ejemplo n.º 43
0
def reset_standarddir():
    standarddir.init(None)
Ejemplo n.º 44
0
def reset_standarddir():
    """Clean up standarddir arguments before and after each test."""
    standarddir.init(None)
    yield
    standarddir.init(None)
Ejemplo n.º 45
0
def _init_modules(args, crash_handler):
    """Initialize all 'modules' which need to be initialized.

    Args:
        args: The argparse namespace.
        crash_handler: The CrashHandler instance.
    """
    # pylint: disable=too-many-statements
    log.init.debug("Initializing save manager...")
    save_manager = savemanager.SaveManager(qApp)
    objreg.register("save-manager", save_manager)
    save_manager.add_saveable("version", _save_version)
    log.init.debug("Initializing network...")
    networkmanager.init()
    log.init.debug("Initializing readline-bridge...")
    readline_bridge = readline.ReadlineBridge()
    objreg.register("readline-bridge", readline_bridge)
    log.init.debug("Initializing directories...")
    standarddir.init(args)
    log.init.debug("Initializing config...")
    config.init(qApp)
    save_manager.init_autosave()
    log.init.debug("Initializing web history...")
    history.init(qApp)
    log.init.debug("Initializing crashlog...")
    if not args.no_err_windows:
        crash_handler.handle_segfault()
    log.init.debug("Initializing sessions...")
    sessions.init(qApp)
    log.init.debug("Initializing js-bridge...")
    js_bridge = qutescheme.JSBridge(qApp)
    objreg.register("js-bridge", js_bridge)
    log.init.debug("Initializing websettings...")
    websettings.init()
    log.init.debug("Initializing adblock...")
    host_blocker = adblock.HostBlocker()
    host_blocker.read_hosts()
    objreg.register("host-blocker", host_blocker)
    log.init.debug("Initializing quickmarks...")
    quickmark_manager = urlmarks.QuickmarkManager(qApp)
    objreg.register("quickmark-manager", quickmark_manager)
    log.init.debug("Initializing bookmarks...")
    bookmark_manager = urlmarks.BookmarkManager(qApp)
    objreg.register("bookmark-manager", bookmark_manager)
    log.init.debug("Initializing proxy...")
    proxy.init()
    log.init.debug("Initializing cookies...")
    cookie_jar = cookies.CookieJar(qApp)
    objreg.register("cookie-jar", cookie_jar)
    log.init.debug("Initializing cache...")
    diskcache = cache.DiskCache(standarddir.cache(), parent=qApp)
    objreg.register("cache", diskcache)
    log.init.debug("Initializing completions...")
    completionmodels.init()
    log.init.debug("Misc initialization...")
    if config.get("ui", "hide-wayland-decoration"):
        os.environ["QT_WAYLAND_DISABLE_WINDOWDECORATION"] = "1"
    else:
        os.environ.pop("QT_WAYLAND_DISABLE_WINDOWDECORATION", None)
    _maybe_hide_mouse_cursor()
    objreg.get("config").changed.connect(_maybe_hide_mouse_cursor)
Ejemplo n.º 46
0
def _init_modules(args, crash_handler):
    """Initialize all 'modules' which need to be initialized.

    Args:
        args: The argparse namespace.
        crash_handler: The CrashHandler instance.
    """
    # pylint: disable=too-many-statements
    log.init.debug("Initializing save manager...")
    save_manager = savemanager.SaveManager(qApp)
    objreg.register('save-manager', save_manager)
    save_manager.add_saveable('version', _save_version)

    log.init.debug("Initializing network...")
    networkmanager.init()

    log.init.debug("Initializing readline-bridge...")
    readline_bridge = readline.ReadlineBridge()
    objreg.register('readline-bridge', readline_bridge)

    log.init.debug("Initializing directories...")
    standarddir.init(args)

    log.init.debug("Initializing config...")
    config.init(qApp)
    save_manager.init_autosave()

    log.init.debug("Initializing web history...")
    history.init(qApp)

    log.init.debug("Initializing crashlog...")
    if not args.no_err_windows:
        crash_handler.handle_segfault()

    log.init.debug("Initializing sessions...")
    sessions.init(qApp)

    log.init.debug("Initializing js-bridge...")
    js_bridge = webkitqutescheme.JSBridge(qApp)
    objreg.register('js-bridge', js_bridge)

    log.init.debug("Initializing websettings...")
    websettings.init()

    log.init.debug("Initializing adblock...")
    host_blocker = adblock.HostBlocker()
    host_blocker.read_hosts()
    objreg.register('host-blocker', host_blocker)

    log.init.debug("Initializing quickmarks...")
    quickmark_manager = urlmarks.QuickmarkManager(qApp)
    objreg.register('quickmark-manager', quickmark_manager)

    log.init.debug("Initializing bookmarks...")
    bookmark_manager = urlmarks.BookmarkManager(qApp)
    objreg.register('bookmark-manager', bookmark_manager)

    log.init.debug("Initializing proxy...")
    proxy.init()

    log.init.debug("Initializing cookies...")
    cookie_jar = cookies.CookieJar(qApp)
    ram_cookie_jar = cookies.RAMCookieJar(qApp)
    objreg.register('cookie-jar', cookie_jar)
    objreg.register('ram-cookie-jar', ram_cookie_jar)

    log.init.debug("Initializing cache...")
    diskcache = cache.DiskCache(standarddir.cache(), parent=qApp)
    objreg.register('cache', diskcache)

    log.init.debug("Initializing completions...")
    completionmodels.init()

    log.init.debug("Misc initialization...")
    if config.get('ui', 'hide-wayland-decoration'):
        os.environ['QT_WAYLAND_DISABLE_WINDOWDECORATION'] = '1'
    else:
        os.environ.pop('QT_WAYLAND_DISABLE_WINDOWDECORATION', None)
    temp_downloads = downloads.TempDownloadManager(qApp)
    objreg.register('temporary-downloads', temp_downloads)
    # Init backend-specific stuff
    browsertab.init(args)
Ejemplo n.º 47
0
 def test_confdir_none(self):
     """Test --confdir with None given."""
     args = types.SimpleNamespace(confdir=None, cachedir=None, datadir=None)
     standarddir.init(args)
     assert standarddir.config().split(os.sep)[-1] == 'qute_test'
Ejemplo n.º 48
0
def reset_standarddir(no_cachedir_tag):
    """Clean up standarddir arguments before and after each test."""
    standarddir.init(None)
    yield
    standarddir.init(None)
Ejemplo n.º 49
0
 def test_datadir(self, testcase):
     """Test --datadir."""
     args = types.SimpleNamespace(confdir=None, cachedir=None,
                                  datadir=testcase.arg, basedir=None)
     standarddir.init(args)
     assert standarddir.data() == testcase.expected
Ejemplo n.º 50
0
 def test_datadir(self, testcase):
     """Test --datadir."""
     args = types.SimpleNamespace(confdir=None, cachedir=None,
                                  datadir=testcase.arg, basedir=None)
     standarddir.init(args)
     assert standarddir.data() == testcase.expected
Ejemplo n.º 51
0
 def test_confdir_none(self):
     """Test --confdir with None given."""
     args = types.SimpleNamespace(confdir=None, cachedir=None, datadir=None)
     standarddir.init(args)
     assert standarddir.config().split(os.sep)[-1] == 'qutebrowser_test'