Exemple #1
0
    def find_configs():
        # Handle Windows specifically
        if "APPDATA" in os.environ:
            win_path = os.path.join(os.environ["APPDATA"], "weblate.ini")
            if os.path.exists(win_path):
                yield win_path

        # Generic XDG paths
        yield from load_config_paths("weblate")
        yield from load_config_paths("weblate.ini")
Exemple #2
0
 def get_config_files(self, app):
     config_files = []
     for path in reversed(list(load_config_paths(app.name))):
         self._add_config_file(config_files, path, app.name)
         for plugin in app.plugins.enabled:
             self._add_config_file(config_files, path, plugin.__name__)
     self._add_config_file(config_files, '.', 'local')
     return config_files
Exemple #3
0
 def get_config_files(self, app):
     config_files = []
     for path in reversed(list(load_config_paths(app.name))):
         self._add_config_file(config_files, path, app.name)
         for plugin in app.plugins.enabled:
             self._add_config_file(config_files, path, plugin.__name__)
     self._add_config_file(config_files, '.', 'local')
     return config_files
Exemple #4
0
    def load(self, path=None):
        """Load configuration from XDG paths."""
        if path is None:
            path = load_config_paths('weblate')
        self.read(path)

        # Try reading from current dir
        cwd = os.path.abspath('.')
        prev = None
        while cwd != prev:
            conf_name = os.path.join(cwd, '.weblate')
            if os.path.exists(conf_name):
                self.read(conf_name)
                break
            prev = cwd
            cwd = os.path.dirname(cwd)
Exemple #5
0
    def load(self, path=None):
        """Load configuration from XDG paths."""
        if path is None:
            path = load_config_paths("weblate")
        self.read(path)

        # Try reading from current dir
        cwd = os.path.abspath(".")
        prev = None
        while cwd != prev:
            conf_name = os.path.join(cwd, ".weblate")
            if os.path.exists(conf_name):
                self.read(conf_name)
                break
            prev = cwd
            cwd = os.path.dirname(cwd)
Exemple #6
0
def get_path(pname='default', sufx='.conf'):
    # yield system-wide profile first
    yield os.path.join('/etc', __LowerName__ + sufx)
    # search for profiles other than system-wide one only if NOT running as
    # root (uid=0)
    if os.getuid() > 0:
        if settings.keys().count('profile'):
            pname = settings['profile']
        if os.path.dirname(pname):
            if os.path.basename(pname):
                yield pname
        else:
            if pname.endswith(sufx):
                pname = pname[:-len(sufx)]
            xdg_paths = list(load_config_paths(__LowerName__))
            xdg_paths.reverse()
            for directory in xdg_paths:
                yield os.path.join(directory, pname + sufx)
Exemple #7
0
def get_path(pname='default', sufx='.conf'):
    # yield system-wide profile first
    yield os.path.join('/etc', __LowerName__ + sufx)
    # search for profiles other than system-wide one only if NOT running as
    # root (uid=0)
    if os.getuid() > 0:
        if settings.keys().count('profile'):
            pname = settings['profile']
        if os.path.dirname(pname):
            if os.path.basename(pname):
                yield pname
        else:
            if pname.endswith(sufx):
                pname = pname[:-len(sufx)]
            xdg_paths = list(load_config_paths(__LowerName__))
            xdg_paths.reverse()
            for directory in xdg_paths:
                yield os.path.join(directory, pname + sufx)
Exemple #8
0
def setdefault_from_config(args):
    config = {}
    for f in load_config_paths('python-magnatune', 'config.ini'):
        logger.debug('Reading form config file: %s', f)
        parser = configparser.ConfigParser()
        try:
            parser.read(f)
            for option, value in parser['magnatune'].items():
                if option not in AUTHORIZED_OPTIONS:
                    logger.warning('Option "%s" in config file %s will be ignored', option, f)
                else:
                    config.setdefault(option, value)
        except configparser.Error as e:
            logger.warning("Error while reading the config file %s, ignoring :\n%s", f, e)

    for k, v in AUTHORIZED_OPTIONS.items():
        config.setdefault(k, v)

    return {key: config.get(key) if value is None else value
            for key, value in vars(args).items()}
Exemple #9
0
def parse_args():
    parser = argparse.ArgumentParser('i3hub')
    parser.add_argument('--load', action='append', default=[])
    data_dirs = list(
            list(load_config_paths('i3hub')) + list(load_data_paths('i3hub')))
    extension_path = ':'.join('{}/extensions'.format(p) for p in data_dirs)
    parser.add_argument('--extension-path', default=extension_path)
    config_candidates = list(c for c in
            (os.path.join(p, 'i3hub.cfg') for p in data_dirs)
            if os.path.exists(c))
    if not config_candidates:
        config_candidates.append('{}/i3hub/i3hub.cfg'.format(xdg_config_home))
    parser.add_argument('-c', '--config', default=config_candidates[0])
    extra_config_dirs = reversed(list(d for d in
            (os.path.join(p, 'config.d') for p in data_dirs)
            if os.path.isdir(d)))
    parser.add_argument('--extra-config-dirs',
            default=':'.join(extra_config_dirs))
    parser.add_argument('--run-as-status', default=False, action='store_true')
    parser.add_argument('--log-file', default=None)
    return parser.parse_args()
Exemple #10
0
def open_matching_files(
    glob: str,
    *,
    search_path_seq: Optional[Sequence[Path]] = None,
    encoding: str = "utf-8",
) -> Iterator[TextIO]:
    """Open (configuration) files matching a glob in searched directories.

    Keyword arguments:
        glob: The glob describing the files to open.
        search_path_seq: File system directories that are searched for the files to open.
            Defaults to XDG configuration search path (env:`XDG_CONFIG_DIRS`).
        encoding: Expected file encoding.

    Yields:
        Open streams for found files. It is the caller responsibility to close them.
    """

    if search_path_seq is None:
        search_path_seq = list(map(Path, load_config_paths(RESOURCE_ID)))

    match_iter = chain.from_iterable(
        directory.glob(glob) for directory in search_path_seq)
    yield from (match.open(encoding=encoding) for match in match_iter)
Exemple #11
0
 def load(self):
     """
     Loads configuration from XDG paths.
     """
     self.read(load_config_paths('suseapi'))
Exemple #12
0
 def load(self):
     """
     Loads configuration from XDG paths.
     """
     self.read(load_config_paths('suseapi'))
Exemple #13
0
from xdg.BaseDirectory import load_config_paths

CONFIGURATION = ConfigParser()
RESOURCE_NAME = 'video699'
DEFAULT_CONFIGURATION_FILE_PATHNAME = os.path.join(
    os.path.dirname(__file__),
    'configuration',
    'default.ini',
)
WORKING_DIRECTORY_CONFIGURATION_FILE_PATHNAME = os.path.join(
    '.',
    '{}.ini'.format(RESOURCE_NAME),
)
CONFIGURATION_FILE_PATHNAMES = list(
    chain((WORKING_DIRECTORY_CONFIGURATION_FILE_PATHNAME, ),
          reversed(list(load_config_paths(RESOURCE_NAME))),
          (DEFAULT_CONFIGURATION_FILE_PATHNAME, )))
LOGGER = getLogger(__name__)


def get_configuration():
    """Returns the package configuration.

    Returns
    -------
    configuration : ConfigParser
        The package configuration.
    """
    return CONFIGURATION

Exemple #14
0
 def load(self, path=None):
     """Load configuration from XDG paths."""
     if path is None:
         path = load_config_paths('odorik')
     self.read(path)