summaryrefslogtreecommitdiff
path: root/lib/spack/spack/cmd/edit.py
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2016-01-17 18:14:35 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2016-01-17 18:14:35 -0800
commit97b492756acce93dbd5f1c305504f07df7582ba0 (patch)
tree8e9bdf00af61e5778dedd3c36b97ab97dbfa34ed /lib/spack/spack/cmd/edit.py
parent5984bc2ad3b3d161ac8e8c37ec1dc3dfa9250241 (diff)
downloadspack-97b492756acce93dbd5f1c305504f07df7582ba0.tar.gz
spack-97b492756acce93dbd5f1c305504f07df7582ba0.tar.bz2
spack-97b492756acce93dbd5f1c305504f07df7582ba0.tar.xz
spack-97b492756acce93dbd5f1c305504f07df7582ba0.zip
Fix create, diy, edit, and repo commands to use multiple repos.
Diffstat (limited to 'lib/spack/spack/cmd/edit.py')
-rw-r--r--lib/spack/spack/cmd/edit.py35
1 files changed, 26 insertions, 9 deletions
diff --git a/lib/spack/spack/cmd/edit.py b/lib/spack/spack/cmd/edit.py
index e0688dc96b..a20e40df9b 100644
--- a/lib/spack/spack/cmd/edit.py
+++ b/lib/spack/spack/cmd/edit.py
@@ -30,6 +30,8 @@ from llnl.util.filesystem import mkdirp, join_path
import spack
import spack.cmd
+from spack.spec import Spec
+from spack.repository import Repo
from spack.util.naming import mod_to_class
description = "Open package files in $EDITOR"
@@ -53,9 +55,16 @@ class ${class_name}(Package):
""")
-def edit_package(name, force=False):
- path = spack.repo.filename_for_package_name(name)
+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)
@@ -63,13 +72,13 @@ def edit_package(name, force=False):
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." % name)
+ "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=name, class_name=mod_to_class(name)))
+ name=spec.name, class_name=mod_to_class(spec.name)))
spack.editor(path)
@@ -79,17 +88,25 @@ def setup_parser(subparser):
'-f', '--force', dest='force', action='store_true',
help="Open a new file in $EDITOR even if package doesn't exist.")
- filetypes = subparser.add_mutually_exclusive_group()
- filetypes.add_argument(
+ excl_args = subparser.add_mutually_exclusive_group()
+
+ # Various filetypes you can edit directly from the cmd line.
+ excl_args.add_argument(
'-c', '--command', dest='path', action='store_const',
const=spack.cmd.command_path, help="Edit the command with the supplied name.")
- filetypes.add_argument(
+ excl_args.add_argument(
'-t', '--test', dest='path', action='store_const',
const=spack.test_path, help="Edit the test with the supplied name.")
- filetypes.add_argument(
+ excl_args.add_argument(
'-m', '--module', dest='path', action='store_const',
const=spack.module_path, help="Edit the main spack module with the supplied name.")
+ # Options for editing packages
+ excl_args.add_argument(
+ '-r', '--repo', default=None, help="Path to repo to edit package in.")
+ excl_args.add_argument(
+ '-N', '--namespace', default=None, help="Namespace of package to edit.")
+
subparser.add_argument(
'name', nargs='?', default=None, help="name of package to edit")
@@ -107,7 +124,7 @@ def edit(parser, args):
spack.editor(path)
elif name:
- edit_package(name, args.force)
+ edit_package(name, args.repo, args.namespace, args.force)
else:
# By default open the directory where packages or commands live.
spack.editor(path)