Exemplo n.º 1
0
    if not valid_module_name(name):
        tty.die("Package name can only contain A-Z, a-z, 0-9, '_' and '-'")

    tty.msg("This looks like a URL for %s version %s." % (name, version))
    tty.msg("Creating template for package %s" % name)

    # Create a directory for the new package.
    pkg_path = spack.db.filename_for_package_name(name)
    if os.path.exists(pkg_path) and not args.force:
        tty.die("%s already exists." % pkg_path)
    else:
        mkdirp(os.path.dirname(pkg_path))

    versions = spack.package.find_versions_of_archive(url)
    rkeys = sorted(versions.keys(), reverse=True)
    versions = OrderedDict(zip(rkeys, (versions[v] for v in rkeys)))

    archives_to_fetch = 1
    if not versions:
        # If the fetch failed for some reason, revert to what the user provided
        versions = {version: url}
    elif len(versions) > 1:
        tty.msg(
            "Found %s versions of %s:" % (len(versions), name),
            *spack.cmd.elide_list(
                ["%-10s%s" % (v, u) for v, u in versions.iteritems()]))
        print
        archives_to_fetch = tty.get_number(
            "Include how many checksums in the package file?",
            default=5,
            abort='q')
Exemplo n.º 2
0
from external.ordereddict import OrderedDict
from llnl.util.lang import memoized
import spack.error

__all__ = [
    'SpackConfigParser', 'get_config', 'SpackConfigurationError',
    'InvalidConfigurationScopeError', 'InvalidSectionNameError',
    'ReadOnlySpackConfigError', 'ConfigParserError', 'NoOptionError',
    'NoSectionError']

_named_section_re = r'([^ ]+) "([^"]+)"'

"""Names of scopes and their corresponding configuration files."""
_scopes = OrderedDict({
    'site' : os.path.join(spack.etc_path, 'spackconfig'),
    'user' : os.path.expanduser('~/.spackconfig')
})

_field_regex = r'^([\w-]*)'        \
               r'(?:\.(.*(?=.)))?' \
               r'(?:\.([\w-]+))?$'

_section_regex = r'^([\w-]*)\s*' \
                 r'\"([^"]*\)\"$'


# Cache of configs -- we memoize this for performance.
_config = {}

def get_config(scope=None, **kwargs):
    """Get a Spack configuration object, which can be used to set options.