當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。