[yt-svn] commit/yt: MatthewTurk: Add the ability to add aliases for functions. Turns out I had been modifying

Bitbucket commits-noreply at bitbucket.org
Thu Feb 16 11:37:46 PST 2012


1 new commit in yt:


https://bitbucket.org/yt_analysis/yt/changeset/1813cc76ec98/
changeset:   1813cc76ec98
branch:      yt
user:        MatthewTurk
date:        2012-02-16 20:37:16
summary:     Add the ability to add aliases for functions.  Turns out I had been modifying
state inside _add_arg, but that's fixed now.
affected #:  1 file

diff -r edab16cb41c9df3919691687f993e6b4adfe576b -r 1813cc76ec989338de44f8470cceb939e8fef777 yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -47,10 +47,11 @@
 def _add_arg(sc, arg):
     if isinstance(arg, types.StringTypes):
         arg = _common_options[arg].copy()
+    argc = dict(arg.items())
     argnames = []
-    if "short" in arg: argnames.append(arg.pop('short'))
-    if "long" in arg: argnames.append(arg.pop('long'))
-    sc.add_argument(*argnames, **arg)
+    if "short" in argc: argnames.append(argc.pop('short'))
+    if "long" in argc: argnames.append(argc.pop('long'))
+    sc.add_argument(*argnames, **argc)
 
 class YTCommand(object):
     args = ()
@@ -63,12 +64,14 @@
         def __init__(cls, name, b, d):
             type.__init__(cls, name, b, d)
             if cls.name is not None:
-                sc = subparsers.add_parser(cls.name,
-                    description = cls.description,
-                    help = cls.description)
-                sc.set_defaults(func=cls.run)
-                for arg in cls.args:
-                    _add_arg(sc, arg)
+                names = ensure_list(cls.name)
+                for name in names:
+                    sc = subparsers.add_parser(name,
+                        description = cls.description,
+                        help = cls.description)
+                    sc.set_defaults(func=cls.run)
+                    for arg in cls.args:
+                        _add_arg(sc, arg)
 
     @classmethod
     def run(cls, args):
@@ -1243,6 +1246,7 @@
         rpdb.run_rpdb(int(task))
 
 class YTGUICmd(YTCommand):
+    name = ["serve", "reason"]
     args = (
             dict(short="-o", long="--open-browser", action="store_true",
                  default = False, dest='open_browser',
@@ -1311,12 +1315,6 @@
         uuid_serve_functions(open_browser=args.open_browser,
                     port=int(args.port), repl=hr)
 
-class YTServeCmd(YTGUICmd):
-    name = "serve"
-
-class YTReasonCmd(YTGUICmd):
-    name = "reason"
-
 class YTStatsCmd(YTCommand):
     args = ('outputfn','bn','skip','pf', 'field',
             dict(long="--max", action="store_true", default=False,

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list