Exemple #1
0
def edit(parser, args):
    name = args.name

    # By default open the directory where packages live.
    if not name:
        path = spack.packages_path
    else:
        path = packages.filename_for_package_name(name)

        if os.path.exists(path):
            if not os.path.isfile(path):
                tty.die("Something's wrong.  '%s' is not a file!" % path)
            if not os.access(path, os.R_OK|os.W_OK):
                tty.die("Insufficient permissions on '%s'!" % path)
        elif not args.force:
            tty.die("No package '%s'.  Use spack create, or supply -f/--force "
                    "to edit a new file." % name)
        else:
            class_name = packages.class_name_for_package_name(name)

            with closing(open(path, "w")) as pkg_file:
                pkg_file.write(
                    package_template.substitute(name=name, class_name=class_name))

    # If everything checks out, go ahead and edit.
    spack.editor(path)
Exemple #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)