コード例 #1
0
ファイル: config.py プロジェクト: xManusx/qutebrowser
def _init_key_config(parent):
    """Initialize the key config.

    Args:
        parent: The parent to use for the KeyConfigParser.
    """
    args = objreg.get('args')
    try:
        key_config = keyconf.KeyConfigParser(standarddir.config(),
                                             'keys.conf',
                                             args.relaxed_config,
                                             parent=parent)
    except (keyconf.KeyConfigError, UnicodeDecodeError) as e:
        log.init.exception(e)
        errstr = "Error while reading key config:\n"
        if e.lineno is not None:
            errstr += "In line {}: ".format(e.lineno)
        error.handle_fatal_exc(e,
                               args,
                               "Error while reading key config!",
                               pre_text=errstr)
        # We didn't really initialize much so far, so we just quit hard.
        sys.exit(usertypes.Exit.err_key_config)
    else:
        objreg.register('key-config', key_config)
        if standarddir.config() is not None:
            save_manager = objreg.get('save-manager')
            filename = os.path.join(standarddir.config(), 'keys.conf')
            save_manager.add_saveable('key-config',
                                      key_config.save,
                                      key_config.config_dirty,
                                      config_opt=('general',
                                                  'auto-save-config'),
                                      filename=filename,
                                      dirty=key_config.is_dirty)
コード例 #2
0
ファイル: test_config.py プロジェクト: djfinlay/qutebrowser
 def test_default_key_config(self):
     """Test validating of the default key config."""
     # We import qutebrowser.app so the cmdutils.register decorators run.
     import qutebrowser.app
     conf = keyconf.KeyConfigParser(None, None)
     runner = runners.CommandRunner(win_id=0)
     for sectname in configdata.KEY_DATA:
         for cmd in conf.get_bindings_for(sectname).values():
             runner.parse(cmd, aliases=False)
コード例 #3
0
 def test_default_key_config(self, tmpdir):
     """Test validating of the default key config."""
     # We import qutebrowser.app so the cmdutils.register decorators run.
     import qutebrowser.app  # pylint: disable=unused-variable
     conf = keyconf.KeyConfigParser(str(tmpdir), 'keys.conf')
     runner = runners.CommandRunner(win_id=0)
     for sectname in configdata.KEY_DATA:
         for cmd in conf.get_bindings_for(sectname).values():
             runner.parse(cmd)
コード例 #4
0
def init(args):
    """Initialize the config.

    Args:
        args: The argparse namespace.
    """
    confdir = standarddir.get(QStandardPaths.ConfigLocation, args)
    try:
        app = objreg.get('app')
        config_obj = ConfigManager(confdir, 'qutebrowser.conf', app)
    except (configexc.Error, configparser.Error) as e:
        log.init.exception(e)
        errstr = "Error while reading config:"
        try:
            errstr += "\n\n{} -> {}:".format(
                e.section, e.option)  # pylint: disable=no-member
        except AttributeError:
            pass
        errstr += "\n{}".format(e)
        msgbox = QMessageBox(QMessageBox.Critical,
                             "Error while reading config!", errstr)
        msgbox.exec_()
        # We didn't really initialize much so far, so we just quit hard.
        sys.exit(1)
    else:
        objreg.register('config', config_obj)
    try:
        key_config = keyconf.KeyConfigParser(confdir, 'keys.conf')
    except keyconf.KeyConfigError as e:
        log.init.exception(e)
        errstr = "Error while reading key config:\n"
        if e.lineno is not None:
            errstr += "In line {}: ".format(e.lineno)
        errstr += str(e)
        msgbox = QMessageBox(QMessageBox.Critical,
                             "Error while reading key config!", errstr)
        msgbox.exec_()
        # We didn't really initialize much so far, so we just quit hard.
        sys.exit(1)
    else:
        objreg.register('key-config', key_config)

    datadir = standarddir.get(QStandardPaths.DataLocation, args)
    state_config = ini.ReadWriteConfigParser(datadir, 'state')
    objreg.register('state-config', state_config)
    # We need to import this here because lineparser needs config.
    from qutebrowser.config.parsers import line
    command_history = line.LineConfigParser(datadir, 'cmd-history',
                                            ('completion', 'history-length'))
    objreg.register('command-history', command_history)
コード例 #5
0
ファイル: test_config.py プロジェクト: djfinlay/qutebrowser
    def test_cmd_binding(self, cmdline_test):
        """Test various command bindings.

        See https://github.com/The-Compiler/qutebrowser/issues/615

        Args:
            cmdline_test: A pytest fixture which provides testcases.
        """
        kcp = keyconf.KeyConfigParser(None, None)
        kcp._cur_section = 'normal'
        if cmdline_test.valid:
            kcp._read_command(cmdline_test.cmd)
        else:
            with pytest.raises(keyconf.KeyConfigError):
                kcp._read_command(cmdline_test.cmd)
コード例 #6
0
    def test_cmd_binding(self, cmdline_test, config_stub, tmpdir):
        """Test various command bindings.

        See https://github.com/The-Compiler/qutebrowser/issues/615

        Args:
            cmdline_test: A pytest fixture which provides testcases.
        """
        config_stub.data = {'aliases': []}
        kcp = keyconf.KeyConfigParser(str(tmpdir), 'keys.conf')
        kcp._cur_section = 'normal'
        if cmdline_test.valid:
            kcp._read_command(cmdline_test.cmd)
        else:
            with pytest.raises(keyconf.KeyConfigError):
                kcp._read_command(cmdline_test.cmd)