summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2014-10-07 23:52:32 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2014-10-08 03:08:40 -0700
commit319b37af0ea84a6ba88d9a6b3a71f17b35c7f0f5 (patch)
treeadb86e7d280cb3df5996478ed4960abdfaf2b47c /lib
parentff546358f3395efb6ec8999804b79cea85cf7fa9 (diff)
downloadspack-319b37af0ea84a6ba88d9a6b3a71f17b35c7f0f5.tar.gz
spack-319b37af0ea84a6ba88d9a6b3a71f17b35c7f0f5.tar.bz2
spack-319b37af0ea84a6ba88d9a6b3a71f17b35c7f0f5.tar.xz
spack-319b37af0ea84a6ba88d9a6b3a71f17b35c7f0f5.zip
Add spack edit -c option to edit commands.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/edit.py49
1 files changed, 31 insertions, 18 deletions
diff --git a/lib/spack/spack/cmd/edit.py b/lib/spack/spack/cmd/edit.py
index 3647186a3c..842dcd7faf 100644
--- a/lib/spack/spack/cmd/edit.py
+++ b/lib/spack/spack/cmd/edit.py
@@ -27,9 +27,10 @@ import string
from contextlib import closing
import llnl.util.tty as tty
-from llnl.util.filesystem import mkdirp
+from llnl.util.filesystem import mkdirp, join_path
import spack
+import spack.cmd
from spack.util.naming import mod_to_class
description = "Open package files in $EDITOR"
@@ -58,31 +59,43 @@ def setup_parser(subparser):
'-f', '--force', dest='force', action='store_true',
help="Open a new file in $EDITOR even if package doesn't exist.")
subparser.add_argument(
+ '-c', '--command', dest='edit_command', action='store_true',
+ help="Edit the command with the supplied name instead of a package.")
+ subparser.add_argument(
'name', nargs='?', default=None, help="name of package to edit")
def edit(parser, args):
name = args.name
- # By default open the directory where packages live.
- if not name:
- path = spack.packages_path
+ 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:
- 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)
+ # By default open the directory where packages or commands live.
+ if not name:
+ path = spack.packages_path
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)))
+ 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)