예제 #1
0
def load_remotes(extra_path=None, load_user=True):
    """Load the YAML remotes file, which sort of combines the Accounts file with part of the
    remotes sections from the main config

    :return: An `AttrDict`
    """

    from os.path import getmtime

    try:
        remotes_file = find_config_file(REMOTES_FILE,
                                        extra_path=extra_path,
                                        load_user=load_user)
    except ConfigurationError:
        remotes_file = None

    if remotes_file is not None and os.path.exists(remotes_file):
        config = AttrDict()
        config.update_yaml(remotes_file)

        if not 'remotes' in config:
            config.remotes = AttrDict()

        config.remotes.loaded = [remotes_file, getmtime(remotes_file)]

        return config
    else:
        return None
예제 #2
0
def load_accounts(extra_path=None, load_user=True):
    """Load the yaml account files

    :param load_user:
    :return: An `AttrDict`
    """

    from os.path import getmtime

    try:
        accts_file = find_config_file(ACCOUNTS_FILE,
                                      extra_path=extra_path,
                                      load_user=load_user)
    except ConfigurationError:
        accts_file = None

    if accts_file is not None and os.path.exists(accts_file):
        config = AttrDict()
        config.update_yaml(accts_file)

        if not 'accounts' in config:
            config.remotes = AttrDict()

        config.accounts.loaded = [accts_file, getmtime(accts_file)]
        return config
    else:
        return None
예제 #3
0
파일: __init__.py 프로젝트: kball/ambry
def default_bundle_config():
    '''Return the default bundle config file as an AttrDict'''

    import os
    from ambry.util import AttrDict

    config = AttrDict()
    f = os.path.join(os.path.dirname(os.path.realpath(__file__)),'bundle.yaml')

    config.update_yaml(f)

    return config
예제 #4
0
파일: __init__.py 프로젝트: Gudinya/ambry
def default_bundle_config():
    """Return the default bundle config file as an AttrDict."""

    import os
    from ambry.util import AttrDict

    config = AttrDict()
    f = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     'bundle.yaml')

    config.update_yaml(f)

    return config
예제 #5
0
파일: filesystem.py 프로젝트: kball/ambry
    def load_yaml(self,*args):
        """Load a yaml file from the bundle file system. Arguments are passed to self.path()
        And if the first path element is not absolute, pre-pends the bundle path. 

        Returns an AttrDict of the results. 
        
        This will load yaml files the same way as RunConfig files. 
        
        """
        from ambry.util import AttrDict
        
        f = self.path(*args)
        
        ad = AttrDict()
        ad.update_yaml(f)
        
        return ad
예제 #6
0
    def load_yaml(self, *args):
        """Load a yaml file from the bundle file system. Arguments are passed to self.path()
        And if the first path element is not absolute, pre-pends the bundle path.

        Returns an AttrDict of the results.

        This will load yaml files the same way as RunConfig files.

        """
        from ambry.util import AttrDict

        f = self.path(*args)

        ad = AttrDict()
        ad.update_yaml(f)

        return ad
예제 #7
0
파일: run.py 프로젝트: Gudinya/ambry
    def __init__(self, path=None):
        """Create a new RunConfig object.

        Arguments
        path -- If present, a yaml file to load last, overwriting earlier values.
          If it is an array, load only the files in the array.

        """

        config = AttrDict()
        config['loaded'] = []

        if not path:
            pass

        if isinstance(path, (list, tuple, set)):
            files = path
        else:
            files = [
                RunConfig.ROOT_CONFIG,
                path if path else RunConfig.USER_CONFIG,
                RunConfig.USER_ACCOUNTS,
                RunConfig.DIR_CONFIG]

        loaded = False

        for f in files:

            if f is not None and os.path.exists(f):
                try:
                    loaded = True

                    config.loaded.append(f)
                    config.update_yaml(f)
                except TypeError:
                    pass  # Empty files will produce a type error

        if not loaded:
            raise ConfigurationError(
                "Failed to load any config from: {}".format(files))

        object.__setattr__(self, 'config', config)
        object.__setattr__(self, 'files', files)
예제 #8
0
파일: run.py 프로젝트: Gudinya/ambry
    def __init__(self, path=None):
        """Create a new RunConfig object.

        Arguments
        path -- If present, a yaml file to load last, overwriting earlier values.
          If it is an array, load only the files in the array.

        """

        config = AttrDict()
        config['loaded'] = []

        if not path:
            pass

        if isinstance(path, (list, tuple, set)):
            files = path
        else:
            files = [
                RunConfig.ROOT_CONFIG, path if path else RunConfig.USER_CONFIG,
                RunConfig.USER_ACCOUNTS, RunConfig.DIR_CONFIG
            ]

        loaded = False

        for f in files:

            if f is not None and os.path.exists(f):
                try:
                    loaded = True

                    config.loaded.append(f)
                    config.update_yaml(f)
                except TypeError:
                    pass  # Empty files will produce a type error

        if not loaded:
            raise ConfigurationError(
                "Failed to load any config from: {}".format(files))

        object.__setattr__(self, 'config', config)
        object.__setattr__(self, 'files', files)
예제 #9
0
def load_config(path=None, load_user=True):
    """
    Load configuration information from a config directory. Tries directories in this order:

    - A path provided as an argument
    - A path specified by the AMBRY_CONFIG environmenal variable
    - ambry in a path specified by the VIRTUAL_ENV environmental variable
    - /etc/ambry
    - ~/ambry

    :param path: An iterable of additional paths to load.
    :return: An `AttrDict` of configuration information
    """

    from os.path import getmtime

    config = AttrDict()

    if not path:
        path = ROOT_DIR

    config_file = find_config_file(CONFIG_FILE,
                                   extra_path=path,
                                   load_user=load_user)

    if os.path.exists(config_file):

        config.update_yaml(config_file)
        config.loaded = [config_file, getmtime(config_file)]

    else:
        # Probably never get here, since the find_config_dir would have thrown a ConfigurationError
        config = AttrDict()
        config.loaded = [None, 0]

    return config