• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python standarddir.config函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中qutebrowser.utils.standarddir.config函数的典型用法代码示例。如果您正苦于以下问题:Python config函数的具体用法?Python config怎么用?Python config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了config函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _init_lineparser

    def _init_lineparser(self):
        bookmarks_directory = os.path.join(standarddir.config(), 'bookmarks')
        os.makedirs(bookmarks_directory, exist_ok=True)

        bookmarks_subdir = os.path.join('bookmarks', 'urls')
        self._lineparser = lineparser.LineParser(
            standarddir.config(), bookmarks_subdir, parent=self)
开发者ID:mehak,项目名称:qutebrowser,代码行数:7,代码来源:urlmarks.py


示例2: _init_key_config

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)
开发者ID:LucasRMehl,项目名称:qutebrowser,代码行数:29,代码来源:config.py


示例3: __init__

    def __init__(self, parent=None):
        """Initialize and read quickmarks."""
        super().__init__(parent)

        self.marks = collections.OrderedDict()

        if standarddir.config() is None:
            self._lineparser = None
        else:
            self._lineparser = lineparser.LineParser(
                standarddir.config(), 'quickmarks', parent=self)
            for line in self._lineparser:
                if not line.strip():
                    # Ignore empty or whitespace-only lines.
                    continue
                try:
                    key, url = line.rsplit(maxsplit=1)
                except ValueError:
                    message.error('current', "Invalid quickmark '{}'".format(
                        line))
                else:
                    self.marks[key] = url
            filename = os.path.join(standarddir.config(), 'quickmarks')
            objreg.get('save-manager').add_saveable(
                'quickmark-manager', self.save, self.changed,
                filename=filename)
开发者ID:prodigeni,项目名称:qutebrowser,代码行数:26,代码来源:quickmarks.py


示例4: _init_lineparser

    def _init_lineparser(self):
        bookmarks_directory = os.path.join(standarddir.config(), 'bookmarks')
        if not os.path.isdir(bookmarks_directory):
            os.makedirs(bookmarks_directory)

        bookmarks_subdir = os.path.join('bookmarks', 'urls')
        self._lineparser = lineparser.LineParser(
            standarddir.config(), bookmarks_subdir, parent=self)
开发者ID:Liambeguin,项目名称:qutebrowser,代码行数:8,代码来源:urlmarks.py


示例5: validate

 def validate(self, value):
     if not value:
         if self._none_ok:
             return
         else:
             raise configexc.ValidationError(value, "may not be empty!")
     value = os.path.expanduser(value)
     value = os.path.expandvars(value)
     try:
         if not os.path.isabs(value):
             cfgdir = standarddir.config()
             if cfgdir is None:
                 raise configexc.ValidationError(
                     value, "must be an absolute path when not using a "
                     "config directory!")
             elif not os.path.isfile(os.path.join(cfgdir, value)):
                 raise configexc.ValidationError(
                     value, "must be a valid path relative to the config "
                     "directory!")
             else:
                 return
         elif not os.path.isfile(value):
             raise configexc.ValidationError(
                 value, "must be a valid file!")
     except UnicodeEncodeError as e:
         raise configexc.ValidationError(value, e)
开发者ID:jagajaga,项目名称:qutebrowser,代码行数:26,代码来源:configtypes.py


示例6: get_diff

def get_diff() -> str:
    """Get a HTML diff for the old config files."""
    old_conf_lines = []  # type: typing.MutableSequence[str]
    old_key_lines = []  # type: typing.MutableSequence[str]

    for filename, dest in [('qutebrowser.conf', old_conf_lines),
                           ('keys.conf', old_key_lines)]:
        path = os.path.join(standarddir.config(), filename)

        with open(path, 'r', encoding='utf-8') as f:
            for line in f:
                if not line.strip() or line.startswith('#'):
                    continue
                dest.append(line.rstrip())

    conf_delta = difflib.unified_diff(OLD_CONF.lstrip().splitlines(),
                                      old_conf_lines)
    key_delta = difflib.unified_diff(OLD_KEYS_CONF.lstrip().splitlines(),
                                     old_key_lines)

    conf_diff = '\n'.join(conf_delta)
    key_diff = '\n'.join(key_delta)

    # pylint: disable=no-member
    # WORKAROUND for https://bitbucket.org/logilab/pylint/issue/491/
    lexer = pygments.lexers.DiffLexer()
    formatter = pygments.formatters.HtmlFormatter(
        full=True, linenos='table',
        title='Diffing pre-1.0 default config with pre-1.0 modified config')
    # pylint: enable=no-member
    return pygments.highlight(conf_diff + key_diff, lexer, formatter)
开发者ID:The-Compiler,项目名称:qutebrowser,代码行数:31,代码来源:configdiff.py


示例7: _init_misc

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/qutebrowser/qutebrowser/issues/515

    path = os.path.join(standarddir.config(), 'qsettings')
    for fmt in [QSettings.NativeFormat, QSettings.IniFormat]:
        QSettings.setPath(fmt, QSettings.UserScope, path)
开发者ID:phansch,项目名称:qutebrowser,代码行数:34,代码来源:config.py


示例8: run_async

def run_async(tab, cmd, *args, win_id, env, verbose=False):
    """Run a userscript after dumping page html/source.

    Raises:
        UnsupportedError if userscripts are not supported on the current
        platform.
        NotFoundError if the command could not be found.

    Args:
        tab: The WebKitTab/WebEngineTab to get the source from.
        cmd: The userscript binary to run.
        *args: The arguments to pass to the userscript.
        win_id: The window id the userscript is executed in.
        env: A dictionary of variables to add to the process environment.
        verbose: Show notifications when the command started/exited.
    """
    tabbed_browser = objreg.get('tabbed-browser', scope='window',
                                window=win_id)
    commandrunner = runners.CommandRunner(win_id, parent=tabbed_browser)

    if os.name == 'posix':
        runner = _POSIXUserscriptRunner(tabbed_browser)
    elif os.name == 'nt':  # pragma: no cover
        runner = _WindowsUserscriptRunner(tabbed_browser)
    else:  # pragma: no cover
        raise UnsupportedError

    runner.got_cmd.connect(
        lambda cmd:
        log.commands.debug("Got userscript command: {}".format(cmd)))
    runner.got_cmd.connect(commandrunner.run_safely)
    user_agent = config.get('network', 'user-agent')
    if user_agent is not None:
        env['QUTE_USER_AGENT'] = user_agent
    config_dir = standarddir.config()
    if config_dir is not None:
        env['QUTE_CONFIG_DIR'] = config_dir
    data_dir = standarddir.data()
    if data_dir is not None:
        env['QUTE_DATA_DIR'] = data_dir
    download_dir = downloads.download_dir()
    if download_dir is not None:
        env['QUTE_DOWNLOAD_DIR'] = download_dir
    cmd_path = os.path.expanduser(cmd)

    # if cmd is not given as an absolute path, look it up
    # ~/.local/share/qutebrowser/userscripts (or $XDG_DATA_DIR)
    if not os.path.isabs(cmd_path):
        log.misc.debug("{} is no absolute path".format(cmd_path))
        cmd_path = _lookup_path(cmd)
    elif not os.path.exists(cmd_path):
        raise NotFoundError(cmd_path)
    log.misc.debug("Userscript to run: {}".format(cmd_path))

    runner.finished.connect(commandrunner.deleteLater)
    runner.finished.connect(runner.deleteLater)

    runner.prepare_run(cmd_path, *args, env=env, verbose=verbose)
    tab.dump_async(runner.store_html)
    tab.dump_async(runner.store_text, plain=True)
开发者ID:EliteTK,项目名称:qutebrowser,代码行数:60,代码来源:userscripts.py


示例9: test_config

 def test_config(self):
     """Test config dir with XDG_CONFIG_HOME not set."""
     env = {'HOME': self.temp_dir, 'XDG_CONFIG_HOME': None}
     with helpers.environ_set_temp(env):
         standarddir.init(None)
         expected = os.path.join(self.temp_dir, '.config', 'qutebrowser')
         self.assertEqual(standarddir.config(), expected)
开发者ID:JIVS,项目名称:qutebrowser,代码行数:7,代码来源:test_standarddir.py


示例10: test_config

 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)
开发者ID:tharugrim,项目名称:qutebrowser,代码行数:7,代码来源:test_standarddir.py


示例11: test_fake_mac_config

def test_fake_mac_config(tmpdir, monkeypatch):
    """Test standardir.config on a fake Mac."""
    monkeypatch.setattr(sys, 'platform', 'darwin')
    monkeypatch.setenv('HOME', str(tmpdir))
    expected = str(tmpdir) + '/.qute_test'  # always with /
    standarddir._init_config(args=None)
    assert standarddir.config() == expected
开发者ID:swalladge,项目名称:qutebrowser,代码行数:7,代码来源:test_standarddir.py


示例12: test_confdir_none

 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'
开发者ID:Dietr1ch,项目名称:qutebrowser,代码行数:8,代码来源:test_standarddir.py


示例13: test_basedir_relative

 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')
开发者ID:Dietr1ch,项目名称:qutebrowser,代码行数:8,代码来源:test_standarddir.py


示例14: _path_info

def _path_info():
    """Get info about important path names.

    Return:
        A dictionary of descriptive to actual path names.
    """
    info = {
        'config': standarddir.config(),
        'data': standarddir.data(),
        'cache': standarddir.cache(),
        'runtime': standarddir.runtime(),
    }
    if standarddir.config() != standarddir.config(auto=True):
        info['auto config'] = standarddir.config(auto=True)
    if standarddir.data() != standarddir.data(system=True):
        info['system data'] = standarddir.data(system=True)
    return info
开发者ID:nanjekyejoannah,项目名称:qutebrowser,代码行数:17,代码来源:version.py


示例15: transform

 def transform(self, value):
     if not value:
         return None
     value = os.path.expanduser(value)
     value = os.path.expandvars(value)
     if not os.path.isabs(value):
         value = os.path.join(standarddir.config(), value)
     return value
开发者ID:phansch,项目名称:qutebrowser,代码行数:8,代码来源:configtypes.py


示例16: __init__

    def __init__(self, parent: QObject = None) -> None:
        super().__init__(parent)
        self._filename = os.path.join(standarddir.config(auto=True),
                                      'autoconfig.yml')
        self._dirty = False

        self._values = {}  # type: typing.Dict[str, configutils.Values]
        for name, opt in configdata.DATA.items():
            self._values[name] = configutils.Values(opt)
开发者ID:fiete201,项目名称:qutebrowser,代码行数:9,代码来源:configfiles.py


示例17: __init__

    def __init__(self, parent=None):
        super().__init__(parent)
        self._filename = os.path.join(standarddir.config(auto=True),
                                      'autoconfig.yml')
        self._dirty = None

        self._values = {}
        for name, opt in configdata.DATA.items():
            self._values[name] = configutils.Values(opt)
开发者ID:mehak,项目名称:qutebrowser,代码行数:9,代码来源:configfiles.py


示例18: transform

 def transform(self, value):
     if not value:
         return None
     value = os.path.expanduser(value)
     value = os.path.expandvars(value)
     if not os.path.isabs(value):
         cfgdir = standarddir.config()
         assert cfgdir is not None
         value = os.path.join(cfgdir, value)
     return value
开发者ID:torsava,项目名称:qutebrowser,代码行数:10,代码来源:configtypes.py


示例19: _init_main_config

def _init_main_config(parent=None):
    """Initialize the main config.

    Args:
        parent: The parent to pass to ConfigManager.
    """
    args = objreg.get('args')
    config_obj = ConfigManager(parent=parent)
    try:
        config_obj.read(standarddir.config(), 'qutebrowser.conf',
                        relaxed=args.relaxed_config)
    except (configexc.Error, configparser.Error, UnicodeDecodeError) as e:
        log.init.exception(e)
        errstr = "Error while reading config:"
        try:
            errstr += "\n\n{} -> {}:".format(
                e.section, e.option)
        except AttributeError:
            pass
        errstr += "\n"
        error.handle_fatal_exc(e, args, "Error while reading config!",
                               pre_text=errstr)
        # We didn't really initialize much so far, so we just quit hard.
        sys.exit(usertypes.Exit.err_config)
    else:
        objreg.register('config', config_obj)
        if standarddir.config() is not None:
            filename = os.path.join(standarddir.config(), 'qutebrowser.conf')
            save_manager = objreg.get('save-manager')
            save_manager.add_saveable(
                'config', config_obj.save, config_obj.changed,
                config_opt=('general', 'auto-save-config'), filename=filename)
            for sect in config_obj.sections.values():
                for opt in sect.values.values():
                    if opt.values['conf'] is None:
                        # Option added to built-in defaults but not in user's
                        # config yet
                        save_manager.save('config', explicit=True, force=True)
                        return
开发者ID:LucasRMehl,项目名称:qutebrowser,代码行数:39,代码来源:config.py


示例20: config_write_py

    def config_write_py(self, filename: str = None,
                        force: bool = False, defaults: bool = False) -> None:
        """Write the current configuration to a config.py file.

        Args:
            filename: The file to write to, or None for the default config.py.
            force: Force overwriting existing files.
            defaults: Write the defaults instead of values configured via :set.
        """
        if filename is None:
            filename = os.path.join(standarddir.config(), 'config.py')
        else:
            if not os.path.isabs(filename):
                filename = os.path.join(standarddir.config(), filename)
            filename = os.path.expanduser(filename)

        if os.path.exists(filename) and not force:
            raise cmdutils.CommandError("{} already exists - use --force to "
                                        "overwrite!".format(filename))

        options = []  # type: typing.List
        if defaults:
            options = [(None, opt, opt.default)
                       for _name, opt in sorted(configdata.DATA.items())]
            bindings = dict(configdata.DATA['bindings.default'].default)
            commented = True
        else:
            for values in self._config:
                for scoped in values:
                    options.append((scoped.pattern, values.opt, scoped.value))
            bindings = dict(self._config.get_mutable_obj('bindings.commands'))
            commented = False

        writer = configfiles.ConfigPyWriter(options, bindings,
                                            commented=commented)
        try:
            writer.write(filename)
        except OSError as e:
            raise cmdutils.CommandError(str(e))
开发者ID:fiete201,项目名称:qutebrowser,代码行数:39,代码来源:configcommands.py



注:本文中的qutebrowser.utils.standarddir.config函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python standarddir.data函数代码示例发布时间:2022-05-26
下一篇:
Python standarddir.cache函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap