Ejemplo n.º 1
0
def checksum(parser, args):
    # get the package we're going to generate checksums for
    pkg = packages.get(args.package)

    # If the user asked for specific versions, use those.
    versions = [ver(v) for v in args.versions]

    if not all(type(v) == Version for v in versions):
        tty.die("Cannot generate checksums for version lists or " +
                "version ranges.  Use unambiguous versions.")

    if not versions:
        versions = pkg.fetch_available_versions()
        if not versions:
            tty.die("Could not fetch any available versions for %s." % pkg.name)

    versions = list(reversed(versions))
    urls = [pkg.url_for_version(v) for v in versions]


    tty.msg("Found %s versions of %s." % (len(urls), pkg.name),
            *spack.cmd.elide_list(
            ["%-10s%s" % (v,u) for v, u in zip(versions, urls)]))
    print
    archives_to_fetch = tty.get_number(
        "How many would you like to checksum?", default=5, abort='q')

    if not archives_to_fetch:
        tty.msg("Aborted.")
        return

    version_hashes = get_checksums(
        versions[:archives_to_fetch], urls[:archives_to_fetch])

    if not version_hashes:
        tty.die("Could not fetch any available versions for %s." % pkg.name)

    dict_string = ["    '%s' : '%s'," % (v, h) for v, h in version_hashes]
    dict_string = ['{'] + dict_string + ["}"]

    tty.msg("Checksummed new versions of %s:" % pkg.name, *dict_string)
Ejemplo n.º 2
0
def create(parser, args):
    url = args.url

    # Try to deduce name and version of the new package from the URL
    name, version = spack.url.parse_name_and_version(url)
    if not name:
        tty.msg("Couldn't guess a name for this package.")
        while not name:
            new_name = raw_input("Name: ")
            if packages.valid_name(name):
                name = new_name
            else:
                print "Package name can only contain A-Z, a-z, 0-9, '_' and '-'"

    if not version:
        tty.die("Couldn't guess a version string from %s." % url)

    tty.msg("Creating template for package %s" % name)

    pkg_path = packages.filename_for_package_name(name)
    if os.path.exists(pkg_path) and not args.force:
        tty.die("%s already exists." % pkg_path)

    class_name = packages.class_name_for_package_name(name)
    versions = list(reversed(spack.package.find_versions_of_archive(url)))

    archives_to_fetch = 1
    if not versions:
        # If the fetch failed for some reason, revert to what the user provided
        versions = [version]
        urls = [url]
    else:
        urls = [spack.url.substitute_version(url, v) for v in versions]
        if len(urls) > 1:
            tty.msg("Found %s versions of %s." % (len(urls), name),
                    *spack.cmd.elide_list(
                    ["%-10s%s" % (v,u) for v, u in zip(versions, urls)]))
            print
            archives_to_fetch = tty.get_number(
                "Include how many checksums in the package file?",
                default=5, abort='q')

            if not archives_to_fetch:
                tty.msg("Aborted.")
                return

    guesser = ConfigureGuesser()
    ver_hash_tuples = spack.cmd.checksum.get_checksums(
        versions[:archives_to_fetch], urls[:archives_to_fetch],
        first_stage_function=guesser)

    if not ver_hash_tuples:
        tty.die("Could not fetch any tarballs for %s." % name)

    # Write out a template for the file
    with closing(open(pkg_path, "w")) as pkg_file:
        pkg_file.write(
            package_template.substitute(
                name=name,
                configure=guesser.configure,
                class_name=class_name,
                url=url,
                versions=make_version_dict(ver_hash_tuples)))

    # If everything checks out, go ahead and edit.
    spack.editor(pkg_path)
    tty.msg("Created package %s." % pkg_path)