示例#1
0
文件: create.py 项目: justintoo/spack
def create(parser, args):
    # Gather information about the package to be created
    name = get_name(args)
    url = get_url(args)
    versions, guesser = get_versions(args, name)
    build_system = get_build_system(args, guesser)

    # Create the package template object
    PackageClass = templates[build_system]
    package = PackageClass(name, url, versions)
    tty.msg("Created template for {0} package".format(package.name))

    # Create a directory for the new package
    repo = get_repository(args, name)
    pkg_path = repo.filename_for_package_name(package.name)
    if os.path.exists(pkg_path) and not args.force:
        tty.die('{0} already exists.'.format(pkg_path),
                '  Try running `spack create --force` to overwrite it.')
    else:
        mkdirp(os.path.dirname(pkg_path))

    # Write the new package file
    package.write(pkg_path)
    tty.msg("Created package file: {0}".format(pkg_path))

    # Open up the new package file in your $EDITOR
    spack.editor(pkg_path)
示例#2
0
def edit_package(name, repo_path, namespace):
    """Opens the requested package file in your favorite $EDITOR.

    :param str name: The name of the package
    :param str repo_path: The path to the repository containing this package
    :param str namespace: A valid namespace registered with Spack
    """
    # Find the location of the package
    if repo_path:
        repo = Repo(repo_path)
    elif namespace:
        repo = spack.repo.get_repo(namespace)
    else:
        repo = spack.repo
    path = repo.filename_for_package_name(name)

    spec = Spec(name)
    if os.path.exists(path):
        if not os.path.isfile(path):
            tty.die("Something is wrong. '{0}' is not a file!".format(path))
        if not os.access(path, os.R_OK | os.W_OK):
            tty.die("Insufficient permissions on '%s'!" % path)
    else:
        tty.die("No package for '{0}' was found.".format(spec.name),
                "  Use `spack create` to create a new package")

    spack.editor(path)
示例#3
0
文件: edit.py 项目: Exteris/spack
def edit_package(name, repo_path, namespace, force=False):
    if repo_path:
        repo = Repo(repo_path)
    elif namespace:
        repo = spack.repo.get_repo(namespace)
    else:
        repo = spack.repo
    path = repo.filename_for_package_name(name)

    spec = Spec(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 force:
        tty.die("No package '%s'.  Use spack create, or supply -f/--force "
                "to edit a new file." % spec.name)
    else:
        mkdirp(os.path.dirname(path))
        with open(path, "w") as pkg_file:
            pkg_file.write(
                package_template.substitute(
                    name=spec.name, class_name=mod_to_class(spec.name)))

    spack.editor(path)
示例#4
0
文件: edit.py 项目: boegel/spack
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)
示例#5
0
def edit_package(name, repo_path, namespace, force=False):
    if repo_path:
        repo = Repo(repo_path)
    elif namespace:
        repo = spack.repo.get_repo(namespace)
    else:
        repo = spack.repo
    path = repo.filename_for_package_name(name)

    spec = Spec(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 force:
        tty.die("No package '%s'.  Use spack create, or supply -f/--force "
                "to edit a new file." % spec.name)
    else:
        mkdirp(os.path.dirname(path))
        with open(path, "w") as pkg_file:
            pkg_file.write(
                package_template.substitute(name=spec.name,
                                            class_name=mod_to_class(
                                                spec.name)))

    spack.editor(path)
示例#6
0
def edit_package(name, repo_path, namespace):
    """Opens the requested package file in your favorite $EDITOR.

    Args:
        name (str): The name of the package
        repo_path (str): The path to the repository containing this package
        namespace (str): A valid namespace registered with Spack
    """
    # Find the location of the package
    if repo_path:
        repo = Repo(repo_path)
    elif namespace:
        repo = spack.repo.get_repo(namespace)
    else:
        repo = spack.repo
    path = repo.filename_for_package_name(name)

    spec = Spec(name)
    if os.path.exists(path):
        if not os.path.isfile(path):
            tty.die("Something is wrong. '{0}' is not a file!".format(path))
        if not os.access(path, os.R_OK | os.W_OK):
            tty.die("Insufficient permissions on '%s'!" % path)
    else:
        tty.die("No package for '{0}' was found.".format(spec.name),
                "  Use `spack create` to create a new package")

    spack.editor(path)
示例#7
0
def create(parser, args):
    # Gather information about the package to be created
    name = get_name(args)
    url = get_url(args)
    versions, guesser = get_versions(args, name)
    build_system = get_build_system(args, guesser)

    # Create the package template object
    PackageClass = templates[build_system]
    package = PackageClass(name, url, versions)
    tty.msg("Created template for {0} package".format(package.name))

    # Create a directory for the new package
    repo = get_repository(args, name)
    pkg_path = repo.filename_for_package_name(package.name)
    if os.path.exists(pkg_path) and not args.force:
        tty.die('{0} already exists.'.format(pkg_path),
                '  Try running `spack create --force` to overwrite it.')
    else:
        mkdirp(os.path.dirname(pkg_path))

    # Write the new package file
    package.write(pkg_path)
    tty.msg("Created package file: {0}".format(pkg_path))

    # Open up the new package file in your $EDITOR
    spack.editor(pkg_path)
示例#8
0
def create(parser, args):
    url = args.url
    if not url:
        setup_parser.subparser.print_help()
        return

    # Figure out a name and repo for the package.
    name, version = guess_name_and_version(url, args)
    spec = Spec(name)
    name = spec.name  # factors out namespace, if any
    repo = find_repository(spec, args)

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

    # Fetch tarballs (prompting user if necessary)
    versions, urls = fetch_tarballs(url, name, version)

    # Try to guess what configure system is used.
    guesser = ConfigureGuesser()
    ver_hash_tuples = spack.cmd.checksum.get_checksums(
        versions,
        urls,
        first_stage_function=guesser,
        keep_stage=args.keep_stage)

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

    # Prepend 'py-' to python package names, by convention.
    if guesser.build_system == 'python':
        name = 'py-%s' % name

    # Prepend 'r-' to R package names, by convention.
    if guesser.build_system == 'r':
        name = 'r-%s' % name

    # Create a directory for the new package.
    pkg_path = repo.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))

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

    # If everything checks out, go ahead and edit.
    spack.editor(pkg_path)
    tty.msg("Created package %s" % pkg_path)
示例#9
0
文件: create.py 项目: Exteris/spack
def create(parser, args):
    url = args.url
    if not url:
        setup_parser.subparser.print_help()
        return

    # Figure out a name and repo for the package.
    name, version = guess_name_and_version(url, args)
    spec = Spec(name)
    name = spec.name  # factors out namespace, if any
    repo = find_repository(spec, args)

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

    # Fetch tarballs (prompting user if necessary)
    versions, urls = fetch_tarballs(url, name, version)

    # Try to guess what configure system is used.
    guesser = ConfigureGuesser()
    ver_hash_tuples = spack.cmd.checksum.get_checksums(
        versions, urls,
        first_stage_function=guesser,
        keep_stage=args.keep_stage)

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

    # Prepend 'py-' to python package names, by convention.
    if guesser.build_system == 'python':
        name = 'py-%s' % name

    # Prepend 'r-' to R package names, by convention.
    if guesser.build_system == 'r':
        name = 'r-%s' % name

    # Create a directory for the new package.
    pkg_path = repo.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))

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

    # If everything checks out, go ahead and edit.
    spack.editor(pkg_path)
    tty.msg("Created package %s" % pkg_path)
示例#10
0
def create(parser, args):
    url = args.url
    if not url:
        setup_parser.subparser.print_help()
        return

    # Figure out a name and repo for the package.
    name, version = guess_name_and_version(url, args)
    spec = Spec(name)
    name = spec.name.lower()  # factors out namespace, if any
    repo = find_repository(spec, args)

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

    # Fetch tarballs (prompting user if necessary)
    versions, urls = fetch_tarballs(url, name, version)

    # Try to guess what build system is used.
    guesser = BuildSystemGuesser()
    ver_hash_tuples = spack.cmd.checksum.get_checksums(
        versions, urls,
        first_stage_function=guesser,
        keep_stage=args.keep_stage)

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

    guess = guesser.make_guess(name, url, ver_hash_tuples)

    # Create a directory for the new package.
    pkg_path = repo.filename_for_package_name(guess.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))

    # Write out a template for the file
    with open(pkg_path, "w") as pkg_file:
        pkg_file.write(
            package_template.substitute(
                name=guess.name,
                class_name=guess.class_name,
                base_class_name=guess.base_class_name,
                url=guess.url,
                versions=guess.versions,
                dependencies=guess.dependencies,
                body=guess.body
            )
        )

    # If everything checks out, go ahead and edit.
    spack.editor(pkg_path)
    tty.msg("Created package %s" % pkg_path)
示例#11
0
文件: edit.py 项目: Exteris/spack
def edit(parser, args):
    name = args.name

    path = spack.packages_path
    if args.path:
        path = args.path
        if name:
            path = join_path(path, name + ".py")
            if not args.force and not os.path.exists(path):
                tty.die("No command named '%s'." % name)
        spack.editor(path)

    elif name:
        edit_package(name, args.repo, args.namespace, args.force)
    else:
        # By default open the directory where packages or commands live.
        spack.editor(path)
示例#12
0
def edit(parser, args):
    name = args.name

    path = spack.packages_path
    if args.path:
        path = args.path
        if name:
            path = join_path(path, name + ".py")
            if not args.force and not os.path.exists(path):
                tty.die("No command named '%s'." % name)
        spack.editor(path)

    elif name:
        edit_package(name, args.repo, args.namespace, args.force)
    else:
        # By default open the directory where packages or commands live.
        spack.editor(path)
示例#13
0
def edit(parser, args):
    name = args.name

    # By default, edit package files
    path = spack.packages_path

    # If `--command`, `--test`, or `--module` is chosen, edit those instead
    if args.path:
        path = args.path
        if name:
            path = join_path(path, name + ".py")
            if not os.path.exists(path):
                tty.die("No command for '{0}' was found.".format(name))
        spack.editor(path)
    elif name:
        edit_package(name, args.repo, args.namespace)
    else:
        # By default open the directory where packages live
        spack.editor(path)
示例#14
0
def edit(parser, args):
    name = args.name

    # By default, edit package files
    path = spack.packages_path

    # If `--command`, `--test`, or `--module` is chosen, edit those instead
    if args.path:
        path = args.path
        if name:
            path = join_path(path, name + ".py")
            if not os.path.exists(path):
                tty.die("No command for '{0}' was found.".format(name))
        spack.editor(path)
    elif name:
        edit_package(name, args.repo, args.namespace)
    else:
        # By default open the directory where packages live
        spack.editor(path)
示例#15
0
文件: edit.py 项目: jgalarowicz/spack
def edit(parser, args):
    name = args.name

    if args.edit_command:
        if not name:
            path = spack.cmd.command_path
        else:
            path = join_path(spack.cmd.command_path, name + ".py")
            if not os.path.exists(path):
                tty.die("No command named '%s'." % name)
        spack.editor(path)

    else:
        # By default open the directory where packages or commands live.
        if not name:
            path = spack.packages_path
            spack.editor(path)
        else:
            edit_package(name, args.force)
示例#16
0
文件: licensing.py 项目: rorist/spack
def set_up_license(pkg):
    """Prompt the user, letting them know that a license is required.

    For packages that rely on license files, a global license file is
    created and opened for editing.

    For packages that rely on environment variables to point to a
    license, a warning message is printed.

    For all other packages, documentation on how to set up a license
    is printed."""

    # If the license can be stored in a file, create one
    if pkg.license_files:
        license_path = pkg.global_license_file
        if not os.path.exists(license_path):
            # Create a new license file
            write_license_file(pkg, license_path)
            # Open up file in user's favorite $EDITOR for editing
            spack.editor(license_path)
            tty.msg("Added global license file %s" % license_path)
        else:
            # Use already existing license file
            tty.msg("Found already existing license %s" % license_path)

    # If not a file, what about an environment variable?
    elif pkg.license_vars:
        tty.warn("A license is required to use %s. Please set %s to the "
                 "full pathname to the license file, or port@host if you"
                 " store your license keys on a dedicated license server" %
                 (pkg.name, ' or '.join(pkg.license_vars)))

    # If not a file or variable, suggest a website for further info
    elif pkg.license_url:
        tty.warn("A license is required to use %s. See %s for details" %
                 (pkg.name, pkg.license_url))

    # If all else fails, you're on your own
    else:
        tty.warn("A license is required to use %s" % pkg.name)
示例#17
0
def edit(parser, args):
    name = args.name

    # By default, edit package files
    path = spack.packages_path

    # If `--command`, `--test`, or `--module` is chosen, edit those instead
    if args.path:
        path = args.path
        if name:
            # convert command names to python module name
            if path == spack.cmd.command_path:
                name = spack.cmd.python_name(name)

            path = os.path.join(path, name)
            if not os.path.exists(path):
                files = glob.glob(path + '*')
                blacklist = ['.pyc', '~']  # blacklist binaries and backups
                files = list(
                    filter(lambda x: all(s not in x for s in blacklist),
                           files))
                if len(files) > 1:
                    m = 'Multiple files exist with the name {0}.'.format(name)
                    m += ' Please specify a suffix. Files are:\n\n'
                    for f in files:
                        m += '        ' + os.path.basename(f) + '\n'
                    tty.die(m)
                if not files:
                    tty.die("No file for '{0}' was found in {1}".format(
                        name, path))
                path = files[0]  # already confirmed only one entry in files

        spack.editor(path)
    elif name:
        edit_package(name, args.repo, args.namespace)
    else:
        # By default open the directory where packages live
        spack.editor(path)
示例#18
0
def edit(parser, args):
    name = args.name

    if args.edit_command:
        if not name:
            path = spack.cmd.command_path
        else:
            path = join_path(spack.cmd.command_path, name + ".py")
            if not os.path.exists(path):
                tty.die("No command named '%s'." % name)

    else:
        # By default open the directory where packages or commands live.
        if not name:
            path = spack.packages_path
        else:
            path = spack.db.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:
                mkdirp(os.path.dirname(path))
                with closing(open(path, "w")) as pkg_file:
                    pkg_file.write(
                        package_template.substitute(
                            name=name, class_name=mod_to_class(name)))

    # If everything checks out, go ahead and edit.
    spack.editor(path)
示例#19
0
文件: create.py 项目: dshrader/spack
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.")
        name = get_name()

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

    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 = 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, keep_stage=args.keep_stage
    )

    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=mod_to_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)
示例#20
0
            default=5,
            abort='q')

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

    guesser = ConfigureGuesser()
    ver_hash_tuples = spack.cmd.checksum.get_checksums(
        versions.keys()[:archives_to_fetch],
        [versions[v] for v in versions.keys()[:archives_to_fetch]],
        first_stage_function=guesser,
        keep_stage=args.keep_stage)

    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=mod_to_class(name),
                url=url,
                versions=make_version_calls(ver_hash_tuples)))

    # If everything checks out, go ahead and edit.
    spack.editor(pkg_path)
    tty.msg("Created package %s." % pkg_path)
示例#21
0
文件: create.py 项目: jprotze/spack
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)
示例#22
0
文件: create.py 项目: trws/spack
        first_stage_function=guesser,
        keep_stage=args.keep_stage)

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

    # Prepend 'py-' to python package names, by convention.
    if guesser.build_system == 'python':
        name = 'py-%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))

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

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