diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/docs/Makefile | 2 | ||||
-rw-r--r-- | lib/spack/external/argparse.py | 15 | ||||
-rw-r--r-- | lib/spack/spack/cmd/info.py | 92 | ||||
-rw-r--r-- | lib/spack/spack/cmd/package-list.py | 108 |
4 files changed, 129 insertions, 88 deletions
diff --git a/lib/spack/docs/Makefile b/lib/spack/docs/Makefile index e3068ea10c..a660e1255d 100644 --- a/lib/spack/docs/Makefile +++ b/lib/spack/docs/Makefile @@ -25,7 +25,7 @@ all: html # This autogenerates a package list. # package_list: - spack info -r > package_list.rst + spack package-list > package_list.rst # # This creates a git repository and commits generated html docs. diff --git a/lib/spack/external/argparse.py b/lib/spack/external/argparse.py index 42b64ee7be..394e5da152 100644 --- a/lib/spack/external/argparse.py +++ b/lib/spack/external/argparse.py @@ -1708,6 +1708,21 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): self._positionals._add_action(action) return action + + def get_subparser(self, name): + """Gets a subparser added with the supplied name. + This is an extension to the standard argparse API. + """ + subpasrsers_actions = [ + action for action in self._actions + if isinstance(action, _SubParsersAction)] + for action in subpasrsers_actions: + for choice, subparser in action.choices.items(): + if choice == name: + return subparser + return None + + def _get_optional_actions(self): return [action for action in self._actions diff --git a/lib/spack/spack/cmd/info.py b/lib/spack/spack/cmd/info.py index 29568b8c5d..3e4ff627d5 100644 --- a/lib/spack/spack/cmd/info.py +++ b/lib/spack/spack/cmd/info.py @@ -22,94 +22,18 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## -import re -import textwrap -from StringIO import StringIO from llnl.util.tty.colify import * import spack import spack.fetch_strategy as fs description = "Get detailed information on a particular package" -def setup_parser(subparser): - subparser.add_argument('-r', '--rst', action='store_true', - help="List all packages in reStructured text, for docs.") - subparser.add_argument('name', metavar="PACKAGE", nargs='?', help="name of packages to get info on") - - -def format_doc(pkg, **kwargs): - """Wrap doc string at 72 characters and format nicely""" - indent = kwargs.get('indent', 0) - - if not pkg.__doc__: - return "" - - doc = re.sub(r'\s+', ' ', pkg.__doc__) - lines = textwrap.wrap(doc, 72) - results = StringIO() - for line in lines: - results.write((" " * indent) + line + "\n") - return results.getvalue() - - -def github_url(pkg): - """Link to a package file on github.""" - return ("https://github.com/scalability-llnl/spack/blob/master/var/spack/packages/%s/package.py" % - pkg.name) - - -def rst_table(elts): - """Print out a RST-style table.""" - cols = StringIO() - ncol, widths = colify(elts, output=cols, tty=True) - header = " ".join("=" * (w-1) for w in widths) - return "%s\n%s%s" % (header, cols.getvalue(), header) - -def info_rst(): - """Print out information on all packages in restructured text.""" - pkgs = sorted(spack.db.all_packages(), key=lambda s:s.name.lower()) - - print "Package List" - print "==================" - - print "This is a list of things you can install using Spack. It is" - print "automatically generated based on the packages in the latest Spack" - print "release." - print - - print "Spack currently has %d mainline packages:" % len(pkgs) - print - print rst_table("`%s`_" % p.name for p in pkgs) - print - print "-----" - - # Output some text for each package. - for pkg in pkgs: - print - print ".. _%s:" % pkg.name - print - print pkg.name - print "-" * len(pkg.name) - print "Links" - print " * `Homepage <%s>`__" % pkg.homepage - print " * `%s/package.py <%s>`__" % (pkg.name, github_url(pkg)) - print - if pkg.versions: - print "Versions:" - print " " + ", ".join(str(v) for v in reversed(sorted(pkg.versions))) - if pkg.dependencies: - print "Dependencies" - print " " + ", ".join("`%s`_" % d if d != "mpi" else d - for d in pkg.dependencies) - print - print "Description" - print format_doc(pkg, indent=2) - print - print "-----" +def setup_parser(subparser): + subparser.add_argument('name', metavar="PACKAGE", help="Name of package to get info for.") -def info_text(pkg): +def print_text_info(pkg): """Print out a plain text description of a package.""" print "Package: ", pkg.name print "Homepage: ", pkg.homepage @@ -150,11 +74,5 @@ def info_text(pkg): def info(parser, args): - if args.rst: - info_rst() - - else: - if not args.name: - tty.die("You must supply a package name.") - pkg = spack.db.get(args.name) - info_text(pkg) + pkg = spack.db.get(args.name) + print_text_info(pkg) diff --git a/lib/spack/spack/cmd/package-list.py b/lib/spack/spack/cmd/package-list.py new file mode 100644 index 0000000000..aa576bddc2 --- /dev/null +++ b/lib/spack/spack/cmd/package-list.py @@ -0,0 +1,108 @@ +############################################################################## +# Copyright (c) 2013, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# +# This file is part of Spack. +# Written by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. +# LLNL-CODE-647188 +# +# For details, see https://scalability-llnl.github.io/spack +# Please also see the LICENSE file for our notice and the LGPL. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License (as published by +# the Free Software Foundation) version 2.1 dated February 1999. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and +# conditions of the GNU General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +############################################################################## +import re +import textwrap +from StringIO import StringIO +import llnl.util.tty as tty +from llnl.util.tty.colify import * +import spack + +description = "Print a list of all packages in reStructuredText." + + +def format_doc(pkg, **kwargs): + """Wrap doc string at 72 characters and format nicely""" + indent = kwargs.get('indent', 0) + + if not pkg.__doc__: + return "" + + doc = re.sub(r'\s+', ' ', pkg.__doc__) + lines = textwrap.wrap(doc, 72) + results = StringIO() + for line in lines: + results.write((" " * indent) + line + "\n") + return results.getvalue() + + +def github_url(pkg): + """Link to a package file on github.""" + return ("https://github.com/scalability-llnl/spack/blob/master/var/spack/packages/%s/package.py" % + pkg.name) + + +def rst_table(elts): + """Print out a RST-style table.""" + cols = StringIO() + ncol, widths = colify(elts, output=cols, tty=True) + header = " ".join("=" * (w-1) for w in widths) + return "%s\n%s%s" % (header, cols.getvalue(), header) + + +def print_rst_package_list(): + """Print out information on all packages in restructured text.""" + pkgs = sorted(spack.db.all_packages(), key=lambda s:s.name.lower()) + + print "Package List" + print "==================" + + print "This is a list of things you can install using Spack. It is" + print "automatically generated based on the packages in the latest Spack" + print "release." + print + + print "Spack currently has %d mainline packages:" % len(pkgs) + print + print rst_table("`%s`_" % p.name for p in pkgs) + print + print "-----" + + # Output some text for each package. + for pkg in pkgs: + print + print ".. _%s:" % pkg.name + print + print pkg.name + print "-" * len(pkg.name) + print "Links" + print " * `Homepage <%s>`__" % pkg.homepage + print " * `%s/package.py <%s>`__" % (pkg.name, github_url(pkg)) + print + if pkg.versions: + print "Versions:" + print " " + ", ".join(str(v) for v in reversed(sorted(pkg.versions))) + if pkg.dependencies: + print "Dependencies" + print " " + ", ".join("`%s`_" % d if d != "mpi" else d + for d in pkg.dependencies) + print + print "Description" + print format_doc(pkg, indent=2) + print + print "-----" + + +def package_list(parser, args): + print_rst_package_list() |