Example #1
0
def defaults(key=None, value=None):
    """ Default pillar values """
    from os.path import join
    try:
        _init_spack()
        from spack.cmd import default_list_scope as dls
        from spack.repository import canonicalize_path
    except ImportError:
        dls = "spack"

        def canonicalize_path(x):
            from os.path import expanduser, expandvars, abspath
            return abspath(expanduser(expandvars(x)))

    if key is not None and value is not None:
        return value
    home = __grains__['userhome']
    config_dir = join(home, '.spack')
    repo_prefix = join(home, '.spack_repos')
    values = {
        'directory': spack_directory(),
        'config_dir':
            __salt__['pillar.get']('spack:config_location', config_dir),
        'repo_prefix':
            __salt__['pillar.get']('spack:repo_prefix', repo_prefix),
        'scope':
            __salt__['pillar.get']('spack:default_config_location', dls)
    }
    values['config_dir'] = canonicalize_path(values['config_dir'])
    values['repo_prefix'] = canonicalize_path(values['repo_prefix'])
    return values[key] if key is not None else values
Example #2
0
def defaults(key=None, value=None):
    """ Default pillar values """
    from os.path import join
    try:
        _init_spack()
        from spack.cmd import default_list_scope as dls
        from spack.repository import canonicalize_path
    except ImportError:
        dls = "spack"

        def canonicalize_path(x):
            from os.path import expanduser, expandvars, abspath
            return abspath(expanduser(expandvars(x)))

    if key is not None and value is not None:
        return value
    home = __grains__['userhome']
    config_dir = join(home, '.spack')
    repo_prefix = join(home, '.spack_repos')
    values = {
        'directory': spack_directory(),
        'config_dir': __salt__['pillar.get']('spack:config_location',
                                             config_dir),
        'repo_prefix': __salt__['pillar.get']('spack:repo_prefix',
                                              repo_prefix),
        'scope': __salt__['pillar.get']('spack:default_config_location', dls)
    }
    values['config_dir'] = canonicalize_path(values['config_dir'])
    values['repo_prefix'] = canonicalize_path(values['repo_prefix'])
    return values[key] if key is not None else values
Example #3
0
def repo_remove(args):
    """Remove a repository from Spack's configuration."""
    repos = spack.config.get_config('repos', args.scope)
    path_or_namespace = args.path_or_namespace

    # If the argument is a path, remove that repository from config.
    canon_path = canonicalize_path(path_or_namespace)
    for repo_path in repos:
        repo_canon_path = canonicalize_path(repo_path)
        if canon_path == repo_canon_path:
            repos.remove(repo_path)
            spack.config.update_config('repos', repos, args.scope)
            tty.msg("Removed repository %s" % repo_path)
            return

    # If it is a namespace, remove corresponding repo
    for path in repos:
        try:
            repo = Repo(path)
            if repo.namespace == path_or_namespace:
                repos.remove(path)
                spack.config.update_config('repos', repos, args.scope)
                tty.msg("Removed repository %s with namespace '%s'." %
                        (repo.root, repo.namespace))
                return
        except RepoError:
            continue

    tty.die("No repository with path or namespace: %s" % path_or_namespace)
Example #4
0
def repo_add(args):
    """Add a package source to Spack's configuration."""
    path = args.path

    # real_path is absolute and handles substitution.
    canon_path = canonicalize_path(path)

    # check if the path exists
    if not os.path.exists(canon_path):
        tty.die("No such file or directory: %s" % path)

    # Make sure the path is a directory.
    if not os.path.isdir(canon_path):
        tty.die("Not a Spack repository: %s" % path)

    # Make sure it's actually a spack repository by constructing it.
    repo = Repo(canon_path)

    # If that succeeds, finally add it to the configuration.
    repos = spack.config.get_config('repos', args.scope)
    if not repos:
        repos = []

    if repo.root in repos or path in repos:
        tty.die("Repository is already registered with Spack: %s" % path)

    repos.insert(0, canon_path)
    spack.config.update_config('repos', repos, args.scope)
    tty.msg("Added repo with namespace '%s'." % repo.namespace)
Example #5
0
def repo_path(path="", prefix=None):
    _init_spack()
    from os.path import join
    from spack.repository import canonicalize_path

    if len(path) == 0:
        path = defaults('repo_prefix', prefix)
    elif path[0] not in ['/', '$', '~']:
        path = join(defaults('repo_prefix', prefix), path)
    return canonicalize_path(path)
Example #6
0
def repo_path(path="", prefix=None):
    _init_spack()
    from os.path import join
    from spack.repository import canonicalize_path

    if len(path) == 0:
        path = defaults('repo_prefix', prefix)
    elif path[0] not in ['/', '$', '~']:
        path = join(defaults('repo_prefix', prefix), path)
    return canonicalize_path(path)