Exemplo n.º 1
0
def _init_misc():
    """Initialize misc. config-related files."""
    save_manager = objreg.get('save-manager')
    state_config = ini.ReadWriteConfigParser(standarddir.data(), 'state')
    for sect in ['general', 'geometry']:
        try:
            state_config.add_section(sect)
        except configparser.DuplicateSectionError:
            pass
    # See commit a98060e020a4ba83b663813a4b9404edb47f28ad.
    state_config['general'].pop('fooled', None)
    objreg.register('state-config', state_config)
    save_manager.add_saveable('state-config', state_config.save)

    # We need to import this here because lineparser needs config.
    from qutebrowser.misc import lineparser
    command_history = lineparser.LimitLineParser(
        standarddir.data(),
        'cmd-history',
        limit=('completion', 'cmd-history-max-items'),
        parent=objreg.get('config'))
    objreg.register('command-history', command_history)
    save_manager.add_saveable('command-history', command_history.save,
                              command_history.changed)

    # Set the QSettings path to something like
    # ~/.config/qutebrowser/qsettings/qutebrowser/qutebrowser.conf so it
    # doesn't overwrite our config.
    #
    # This fixes one of the corruption issues here:
    # https://github.com/The-Compiler/qutebrowser/issues/515

    path = os.path.join(standarddir.config(), 'qsettings')
    for fmt in [QSettings.NativeFormat, QSettings.IniFormat]:
        QSettings.setPath(fmt, QSettings.UserScope, path)
Exemplo n.º 2
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)