当前位置: 首页>>代码示例>>Python>>正文


Python appdirs.user_config_dir方法代码示例

本文整理汇总了Python中appdirs.user_config_dir方法的典型用法代码示例。如果您正苦于以下问题:Python appdirs.user_config_dir方法的具体用法?Python appdirs.user_config_dir怎么用?Python appdirs.user_config_dir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在appdirs的用法示例。


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

示例1: read_player_cfg

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_config_dir [as 别名]
def read_player_cfg(cls, auto_keys=None):
        if sys.platform == "darwin":
            conf_path = Path.home() / ".config" / "mpv" / "mpv.conf"
        else:
            conf_path = (
                Path(appdirs.user_config_dir("mpv", roaming=True, appauthor=False))
                / "mpv.conf"
            )
        mpv_conf = ConfigParser(
            allow_no_value=True, strict=False, inline_comment_prefixes="#"
        )
        mpv_conf.optionxform = lambda option: option
        mpv_conf.read_string("[root]\n" + conf_path.read_text())
        return {
            "ipc_path": lambda: mpv_conf.get("root", "input-ipc-server")
        } 
开发者ID:iamkroot,项目名称:trakt-scrobbler,代码行数:18,代码来源:mpv.py

示例2: manage_config

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_config_dir [as 别名]
def manage_config(cmd):
    """Manage genomepy config file."""
    if cmd == "file":
        print(config.config_file)
    elif cmd == "show":
        with open(config.config_file) as f:
            print(f.read())
    elif cmd == "generate":
        config_dir = user_config_dir("genomepy")
        if not os.path.exists(config_dir):
            mkdir_p(config_dir)

        new_config = os.path.join(config_dir, "genomepy.yaml")
        # existing config must be removed before norns picks up the default again
        if os.path.exists(new_config):
            os.unlink(new_config)
        default_config = norns.config(
            "genomepy", default="cfg/default.yaml"
        ).config_file
        with open(new_config, "w") as fout, open(default_config) as fin:
            fout.write(fin.read())
        config.config_file = new_config
        print(f"Created config file {new_config}")
    else:
        raise ValueError(f"Invalid config command: {cmd}") 
开发者ID:vanheeringen-lab,项目名称:genomepy,代码行数:27,代码来源:functions.py

示例3: read_dictionary

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_config_dir [as 别名]
def read_dictionary(self, providers=None):
        """
        Reads DNA configuration from file if the file exists, otherwise creates new DNA configuration with
        the providers given.
        :param providers: dictionary of providers to include in DNA.
        """
        config_dir = user_config_dir()
        filename = os.path.join(config_dir, 'DNA.json')

        if not os.path.exists(filename):
            self.dictionary = self.create_initial_dict(providers)
            self.write_dictionary()
        else:
            with open(filename) as json_file:
                data = json.load(json_file)
                self.dictionary = data
        self.vps = self.dictionary['VPS'] 
开发者ID:Tribler,项目名称:Dollynator,代码行数:19,代码来源:dna.py

示例4: read_dictionary

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_config_dir [as 别名]
def read_dictionary(self, providers=None):

        config_dir = user_config_dir()
        filename = os.path.join(config_dir, 'QTable.json')

        if not os.path.exists(filename):
            # TODO: check if it will not affect anything
            self.self_state = VPSState(provider="blueangelhost", option="Basic Plan")
            self.init_qtable_and_environment(providers)
            self.create_initial_tree()
            self.write_dictionary()
        else:
            with open(filename) as json_file:
                data_encoded = json.load(json_file)
                data = jsonpickle.decode(data_encoded)
                self.environment = data['environment']
                self.qtable = data['qtable']
                self.providers_offers = data['providers_offers']
                self.self_state = data['self_state']
                self.tree = data['tree'] 
开发者ID:Tribler,项目名称:Dollynator,代码行数:22,代码来源:qtable.py

示例5: create_child_qtable

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_config_dir [as 别名]
def create_child_qtable(self, provider, option, transaction_hash, child_index):
        """
        Creates the QTable configuration for the child agent. This is done by copying the own QTable configuration and including the new host provider, the parent name and the transaction hash.
        :param provider: the name the child tree name.
        :param transaction_hash: the transaction hash the child is bought with.
        """

        next_state = VPSState(provider=provider, option=option)
        tree = self.tree + "." + str(child_index)
        dictionary = {
            "environment": self.environment,
            "qtable": self.qtable,
            "providers_offers": self.providers_offers,
            "self_state": next_state,
            "transaction_hash": transaction_hash,
            "tree": tree
        }

        filename = os.path.join(user_config_dir(), 'Child_QTable.json')
        with open(filename, 'w') as json_file:
            encoded_dictionary = jsonpickle.encode(dictionary)
            json.dump(encoded_dictionary, json_file) 
开发者ID:Tribler,项目名称:Dollynator,代码行数:24,代码来源:qtable.py

示例6: child_account

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_config_dir [as 别名]
def child_account(index=None):
    """
    This method returns the configuration for a certain child number.
    :param index: The number of the child
    :type index: Integer
    :return: configuration of the child
    :rtype: Settings
    """
    if index > -1:
        account = AccountSettings()
        account.read_settings(
            os.path.join(user_config_dir(), 'child_config' + str(index) + '.cfg'))
    else:
        account = AccountSettings()
        account.read_settings(
            os.path.join(user_config_dir(), 'child_config' + str(PlebNetConfig().get("child_index")) + '.cfg'))
    return account 
开发者ID:Tribler,项目名称:Dollynator,代码行数:19,代码来源:cloudomate_controller.py

示例7: __init__

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_config_dir [as 别名]
def __init__(self, path=None):
        """

        :param string path: (Optional) Path to config file location.
        """
        self._path = path
        self._data = {}

        # Use CHEMDATAEXTRACTOR_CONFIG environment variable if set
        if not self._path:
            self._path = os.environ.get('CHEMDATAEXTRACTOR_CONFIG')
        # Use OS-dependent config directory given by appdirs
        if not self._path:
            self._path = os.path.join(appdirs.user_config_dir('ChemDataExtractor'), 'chemdataextractor.yml')
        if os.path.isfile(self.path):
            with io.open(self.path, encoding='utf8') as f:
                self._data = yaml.safe_load(f) 
开发者ID:mcs07,项目名称:ChemDataExtractor,代码行数:19,代码来源:config.py

示例8: get_linux_directories

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_config_dir [as 别名]
def get_linux_directories() -> typing.Tuple[str, str, str]:
    try:
        with open(os.path.join(user_config_dir(), 'user-dirs.dirs'), 'r') as xdg:
            down_dir = re.search(r'XDG_DOWNLOAD_DIR=(.+)', xdg.read())
        if down_dir:
            down_dir = re.sub(r'\$HOME', os.getenv('HOME') or os.path.expanduser("~/"), down_dir.group(1))
            download_dir = re.sub('\"', '', down_dir)
    except OSError:
        download_dir = os.getenv('XDG_DOWNLOAD_DIR')
    if not download_dir:
        download_dir = os.path.expanduser('~/Downloads')

    # old
    data_dir = os.path.expanduser('~/.lbrynet')
    lbryum_dir = os.path.expanduser('~/.lbryum')
    if os.path.isdir(data_dir) or os.path.isdir(lbryum_dir):
        return data_dir, lbryum_dir, download_dir

    # new
    return user_data_dir('lbry/lbrynet'), user_data_dir('lbry/lbryum'), download_dir 
开发者ID:lbryio,项目名称:lbry-sdk,代码行数:22,代码来源:conf.py

示例9: __init__

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_config_dir [as 别名]
def __init__(self, name):
        # Look for an existing configuration file
        self._config = {}
        self._filepath = None
        self._name = name
        self._user_config_dir = user_config_dir("pennylane", "Xanadu")
        self._env_config_dir = os.environ.get("PENNYLANE_CONF", "")

        # search the current directory the directory under environment
        # variable PENNYLANE_CONF, and default user config directory, in that order.
        directories = [os.curdir, self._env_config_dir, self._user_config_dir, ""]
        for idx, directory in enumerate(directories):
            try:
                self._filepath = os.path.join(directory, self._name)
                self.load(self._filepath)
                break
            except FileNotFoundError:
                if idx == len(directories) - 1:
                    log.info("No PennyLane configuration file found.") 
开发者ID:XanaduAI,项目名称:pennylane,代码行数:21,代码来源:configuration.py

示例10: check_if_pid_exists

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_config_dir [as 别名]
def check_if_pid_exists():
    is_pid_alive = False
    cfg_dir = appdirs.user_config_dir(CFG_DIR_NAME)
    pid_file_path = os.path.join(cfg_dir, PID_FILE_NAME)
    if not os.path.isfile(pid_file_path):
        is_pid_alive = False
    else:
        pid_file = open(pid_file_path, 'r')
        pid = pid_file.read()
        # Check if process is already running or not
        try:
            # Sending signal 0 to a pid will raise an OSError exception
            # if the pid is not running.
            os.kill(int(pid), 0)
        except OSError:
            is_pid_alive = False
        else:
            is_pid_alive = True
    return is_pid_alive 
开发者ID:HewlettPackard,项目名称:oneview-redfish-toolkit,代码行数:21,代码来源:app.py

示例11: _ensure_directories

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_config_dir [as 别名]
def _ensure_directories(self):
        """
        Create config dir, config file & cache dir if they do not exist yet.
        """
        self._config_dir = appdirs.user_config_dir('clay', 'Clay')
        self._config_file_path = os.path.join(self._config_dir, 'config.yaml')
        self._colours_file_path = os.path.join(self._config_dir, 'colours.yaml')

        try:
            os.makedirs(self._config_dir)
        except OSError as error:
            if error.errno != errno.EEXIST:
                raise

        self._cache_dir = appdirs.user_cache_dir('clay', 'Clay')
        try:
            os.makedirs(self._cache_dir)
        except OSError as error:
            if error.errno != errno.EEXIST:
                raise

        if not os.path.exists(self._config_file_path):
            with open(self._config_file_path, 'w') as settings_file:
                settings_file.write('{}') 
开发者ID:and3rson,项目名称:clay,代码行数:26,代码来源:settings.py

示例12: extract_old_config

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_config_dir [as 别名]
def extract_old_config():
    old_config = {}

    old_appdir = appdirs.user_config_dir(appauthor='Counterparty', appname='counterpartyd', roaming=True)
    old_configfile = os.path.join(old_appdir, 'counterpartyd.conf')

    if os.path.exists(old_configfile):
        configfile = configparser.SafeConfigParser(allow_no_value=True, inline_comment_prefixes=('#', ';'))
        configfile.read(old_configfile)
        if 'Default' in configfile:
            for key in configfile['Default']:
                new_key = key.replace('backend-rpc-', 'backend-')
                new_key = new_key.replace('blockchain-service-name', 'backend-name')
                new_value = configfile['Default'][key].replace('jmcorgan', 'addrindex')
                old_config[new_key] = new_value

    return old_config 
开发者ID:CounterpartyXCP,项目名称:counterparty-cli,代码行数:19,代码来源:setup.py

示例13: generate_config_files

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_config_dir [as 别名]
def generate_config_files():
    from counterpartycli.server import CONFIG_ARGS as SERVER_CONFIG_ARGS
    from counterpartycli.client import CONFIG_ARGS as CLIENT_CONFIG_ARGS
    from counterpartylib.lib import config, util

    configdir = appdirs.user_config_dir(appauthor=config.XCP_NAME, appname=config.APP_NAME, roaming=True)

    server_configfile = os.path.join(configdir, 'server.conf')
    if not os.path.exists(server_configfile):
        # extract known configuration
        server_known_config = get_server_known_config()
        generate_config_file(server_configfile, SERVER_CONFIG_ARGS, server_known_config)

        client_configfile = os.path.join(configdir, 'client.conf')
        if not os.path.exists(client_configfile):
            client_known_config = server_to_client_config(server_known_config)
            generate_config_file(client_configfile, CLIENT_CONFIG_ARGS, client_known_config) 
开发者ID:CounterpartyXCP,项目名称:counterparty-cli,代码行数:19,代码来源:setup.py

示例14: save

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_config_dir [as 别名]
def save(self):
        """
        Save the configuration file.
        """
        config_dir = appdirs.user_config_dir('pdtools', 'paradrop')
        path = os.path.join(config_dir, 'config.yaml')

        if not os.path.exists(config_dir):
            os.makedirs(config_dir)

        with open(path, 'w') as output:
            yaml.safe_dump(self.data, output, default_flow_style=False) 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:14,代码来源:config.py

示例15: load

# 需要导入模块: import appdirs [as 别名]
# 或者: from appdirs import user_config_dir [as 别名]
def load(cls):
        """
        Load the configuration file.

        Returns an empty PdconfConfig object if the file could not be read.
        """
        config_dir = appdirs.user_config_dir('pdtools', 'paradrop')
        path = os.path.join(config_dir, 'config.yaml')

        try:
            with open(path, 'r') as source:
                config = yaml.safe_load(source)
                return cls(config)
        except:
            return cls() 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:17,代码来源:config.py


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