Python appdirs.user_config_dir() Examples
The following are 30
code examples of appdirs.user_config_dir().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
appdirs
, or try the search function
.
Example #1
Source File: functions.py From genomepy with MIT License | 6 votes |
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}")
Example #2
Source File: dna.py From Dollynator with GNU Lesser General Public License v3.0 | 6 votes |
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']
Example #3
Source File: app.py From oneview-redfish-toolkit with Apache License 2.0 | 6 votes |
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
Example #4
Source File: configuration.py From pennylane with Apache License 2.0 | 6 votes |
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.")
Example #5
Source File: conf.py From lbry-sdk with MIT License | 6 votes |
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
Example #6
Source File: qtable.py From Dollynator with GNU Lesser General Public License v3.0 | 6 votes |
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']
Example #7
Source File: qtable.py From Dollynator with GNU Lesser General Public License v3.0 | 6 votes |
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)
Example #8
Source File: config.py From ChemDataExtractor with MIT License | 6 votes |
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)
Example #9
Source File: settings.py From clay with GNU General Public License v3.0 | 6 votes |
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('{}')
Example #10
Source File: mpv.py From trakt-scrobbler with GNU General Public License v2.0 | 6 votes |
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") }
Example #11
Source File: setup.py From counterparty-cli with MIT License | 6 votes |
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
Example #12
Source File: setup.py From counterparty-cli with MIT License | 6 votes |
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)
Example #13
Source File: cloudomate_controller.py From Dollynator with GNU Lesser General Public License v3.0 | 6 votes |
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
Example #14
Source File: 10_functions_test.py From genomepy with MIT License | 5 votes |
def test_generate_env(): # already used, but we had to install a genome first to test it config_dir = str(user_config_dir("genomepy")) path = os.path.join(config_dir, "exports.txt") if os.path.exists(path): os.unlink(path) assert not os.path.exists(path) # give file path my_path = "~/exports.txt" genomepy.functions.generate_env(my_path) assert os.path.exists(os.path.expanduser(my_path)) os.unlink(os.path.expanduser(my_path)) # give file name my_file = os.path.join(config_dir, "my_exports.txt") genomepy.functions.generate_env("my_exports.txt") assert os.path.exists(my_file) os.unlink(os.path.expanduser(my_file)) # give nothing genomepy.functions.generate_env() assert os.path.exists(path) with open(path) as f: exports = [] for line in f.readlines(): vals = line.strip() exports.append(vals) assert any([x for x in exports if x.startswith("export MY_GENOME")]) os.unlink(path)
Example #15
Source File: config.py From pymzn with MIT License | 5 votes |
def _cfg_file(self): try: import appdirs return os.path.join(appdirs.user_config_dir(__name__), 'config.yml') except ImportError: return None
Example #16
Source File: functions.py From genomepy with MIT License | 5 votes |
def generate_env(fname=None): """Generate file with exports. By default this is .config/genomepy/exports.txt. An alternative file name or file path is accepted too. Parameters ---------- fname: str, optional Absolute path or name of the output file. """ path_name = os.path.expanduser(str(fname)) if fname and os.path.exists(os.path.dirname(path_name)): absname = os.path.abspath(path_name) else: config_dir = user_config_dir("genomepy") if not os.path.exists(config_dir): manage_config("generate") name = "exports.txt" if fname is None else fname absname = os.path.join(config_dir, name) with open(absname, "w") as fout: for env in generate_exports(): fout.write(f"{env}\n")
Example #17
Source File: docker_config.py From android-emulator-container-scripts with Apache License 2.0 | 5 votes |
def __init__(self): cfg_dir = user_config_dir("emu-docker", "Google") if not os.path.exists(cfg_dir): os.makedirs(cfg_dir) self.cfg_file = os.path.join(cfg_dir, "goole-emu-docker.config") self.cfg = ConfigParser() self._load_config()
Example #18
Source File: util.py From oneview-redfish-toolkit with Apache License 2.0 | 5 votes |
def get_user_directory(): return appdirs.user_config_dir(CFG_DIR_NAME)
Example #19
Source File: hostdb.py From amt with Apache License 2.0 | 5 votes |
def __init__(self): self.confdir = appdirs.user_config_dir(appname, appauthor) self.confname = os.path.join(self.confdir, 'hosts.cfg') self.config = configparser.ConfigParser() self.config.read(self.confname)
Example #20
Source File: dirs.py From aw-core with Mozilla Public License 2.0 | 5 votes |
def get_config_dir(module_name: Optional[str]) -> str: config_dir = appdirs.user_config_dir("activitywatch") return os.path.join(config_dir, module_name) if module_name else config_dir
Example #21
Source File: sr_cfg2.py From sarracenia with GNU General Public License v2.0 | 5 votes |
def __init__(self,logger,user_config_dir,parent=None): self.bindings = [] self.__broker = None self.__post_broker = None sr_cfg2.logger = logger if sr_cfg2.credentials is None: sr_cfg2.credentials=sr_credentials(sr_cfg2.logger) sr_cfg2.credentials.read( user_config_dir + os.sep + "credentials.conf" ) # FIXME... Linux only for now, no appdirs self.directory = None if parent is None: self.env = copy.deepcopy(os.environ) self.exchanges = [] self.filename = None self.flatten = '/' self.hostname = socket.getfqdn() self.masks = [] self.mirror = False self.strip = 0 self.pstrip = False self.randid = "%04x" % random.randint(0,65536) self.tls_rigour = 'normal' self.topic_prefix = 'v02.post' self.users = {}
Example #22
Source File: sr_config.py From sarracenia with GNU General Public License v2.0 | 5 votes |
def find_conf_file(self,name): # check in user program configs for p in self.programs: f = self.find_file_in_dir( self.user_config_dir +os.sep+ p, name) if f : return f # check in user plugin configs f = self.find_file_in_dir( self.user_config_dir +os.sep+ 'plugins', name, recursive=True) if f : return f # check in user general configs f = self.find_file_in_dir( self.user_config_dir, name ) if f : return f # check in package plugins f = self.find_file_in_dir( self.package_dir +os.sep+ 'plugins', name, recursive=True) if f : return f # check in package examples for p in self.programs: f = self.find_file_in_dir( self.package_dir +os.sep+ 'examples' +os.sep+ p , name) if f : return f # not found return None
Example #23
Source File: sr_config.py From sarracenia with GNU General Public License v2.0 | 5 votes |
def general(self): self.logger.debug("sr_config general") # read in provided credentials credent = self.user_config_dir + os.sep + 'credentials.conf' self.cache_url = {} self.credentials = sr_credentials(self.logger) self.credentials.read(credent) defconf = self.user_config_dir + os.sep + 'default.conf' self.logger.debug("defconf = %s\n" % defconf) if os.path.isfile(defconf) : config_dir = self.config_dir self.config_dir = '' self.config(defconf) self.config_dir = config_dir adminconf = self.user_config_dir + os.sep + 'admin.conf' self.logger.debug("adminconf = %s\n" % adminconf) if os.path.isfile(adminconf) : config_dir = self.config_dir self.config_dir = '' self.config(adminconf) self.config_dir = config_dir if os.path.isfile(self.prog_config): config_dir = self.config_dir self.config_dir = '' self.config(self.prog_config) self.config_dir = config_dir
Example #24
Source File: sr.py From sarracenia with GNU General Public License v2.0 | 5 votes |
def save_configs(self,savename): """ DEVELOPER only... copy configuration to an alternate tree """ os.chdir(self.user_config_dir) other_config_dir = appdirs.user_config_dir(savename, self.appauthor) if not os.path.exists(other_config_dir): os.mkdir(other_config_dir) for f in [ 'default.conf', 'admin.conf' ]: to = other_config_dir + os.sep + f print( 'save_configs copying: %s %s' % ( f , to ) ) shutil.copyfile( f, to ) self._cleanse_credentials(other_config_dir + os.sep + 'credentials.conf') for c in self.components: if os.path.isdir(c): os.chdir(c) other_c_dir= other_config_dir + os.sep + c if not os.path.exists(other_c_dir): os.mkdir(other_c_dir) self.states[c] = {} for cfg in os.listdir(): to=other_c_dir + os.sep + cfg print( 'save_configs copying: %s %s' % ( cfg , to ) ) shutil.copyfile( cfg, to ) os.chdir('..')
Example #25
Source File: sr.py From sarracenia with GNU General Public License v2.0 | 5 votes |
def appname(self,n): self.__appname = n self.user_config_dir = appdirs.user_config_dir(self.appname, self.appauthor) self.user_cache_dir = appdirs.user_cache_dir(self.appname, self.appauthor)
Example #26
Source File: milc.py From qmk_cli with MIT License | 5 votes |
def find_config_file(self): """Locate the config file. """ if self.config_file: return self.config_file if '--config-file' in sys.argv: return Path(sys.argv[sys.argv.index('--config-file') + 1]).expanduser().resolve() filedir = user_config_dir(appname='qmk', appauthor='QMK') filename = '%s.ini' % self.prog_name return Path(filedir) / filename
Example #27
Source File: config.py From Paradrop with Apache License 2.0 | 5 votes |
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)
Example #28
Source File: config.py From numismatic with MIT License | 5 votes |
def read_config(): '''Reads the current configuration''' config = ConfigParser() for config_file in [Path(__file__).parent / 'numismatic.ini', Path(user_config_dir()) / 'numismatic.ini']: if config_file.exists(): config.read(config_file) return config # we instantiate one copy of the config at import time to keep a consistent # configuration state across the application.
Example #29
Source File: config.py From Paradrop with Apache License 2.0 | 5 votes |
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()
Example #30
Source File: settings.py From python-netsurv with MIT License | 5 votes |
def from_path(path): computed_settings = default.copy() isort_defaults = ['~/.isort.cfg'] if appdirs: isort_defaults = [appdirs.user_config_dir('isort.cfg')] + isort_defaults _update_settings_with_config(path, '.editorconfig', ['~/.editorconfig'], ('*', '*.py', '**.py'), computed_settings) _update_settings_with_config(path, 'pyproject.toml', [], ('tool.isort', ), computed_settings) _update_settings_with_config(path, '.isort.cfg', isort_defaults, ('settings', 'isort'), computed_settings) _update_settings_with_config(path, 'setup.cfg', [], ('isort', 'tool:isort'), computed_settings) _update_settings_with_config(path, 'tox.ini', [], ('isort', 'tool:isort'), computed_settings) return computed_settings