]> scripts.mit.edu Git - wizard.git/commitdiff
Move a bunch of summary items to full class commands.
authorEdward Z. Yang <ezyang@mit.edu>
Fri, 31 Jul 2009 03:49:27 +0000 (23:49 -0400)
committerEdward Z. Yang <ezyang@mit.edu>
Fri, 31 Jul 2009 03:49:27 +0000 (23:49 -0400)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
bin/wizard
wizard/command/errors.py [moved from wizard/command/summary/list_errors.py with 81% similarity]
wizard/command/list.py [new file with mode: 0644]
wizard/command/summary/__init__.py
wizard/command/summary/count_exists.py [deleted file]
wizard/command/summary/list.py [deleted file]
wizard/command/summary/version.py
wizard/deploy.py
wizard/util.py

index 795adad34e1ecf6d4d52e48f546797a90fa7a1e7..95ad1725ff9fcec3c7b3a4954d95c92e9a60f8a2 100755 (executable)
@@ -15,7 +15,9 @@ def main():
 Wizard is a Git-based autoinstall management system for scripts.
 
 Its commands are:
+    errors          Lists all broken autoinstall metadata
     info            Reports information about an autoinstall
+    list            Lists autoinstalls, with optional filtering
     massmigrate     Performs mass migration of autoinstalls of an application
     migrate         Migrate autoinstalls from old format to Git-based format
     summary         Generate statistics (see help for subcommands)
similarity index 81%
rename from wizard/command/summary/list_errors.py
rename to wizard/command/errors.py
index 7a6702fc253a620f5709c342024e71bf3d3210a3..5250254c2e191348e6c2f4e72a5a4717598a2aeb 100644 (file)
@@ -1,11 +1,10 @@
 import logging
 
 from wizard import deploy, command
-from wizard.command import summary
 
 def main(argv, baton):
     options, show = parse_args(argv, baton)
-    for e in summary.parse_install_lines(show, options, True):
+    for e in deploy.parse_install_lines(show, options, True):
         if not isinstance(e, deploy.Error):
             if isinstance(e, Exception):
                 raise e
@@ -16,7 +15,7 @@ def main(argv, baton):
             print e.location
 
 def parse_args(argv, baton):
-    usage = """usage: %prog summary list-errors [ARGS]
+    usage = """usage: %prog errors [ARGS]
 
 Lists all errors that occurred while parsing the versions
 directory."""
diff --git a/wizard/command/list.py b/wizard/command/list.py
new file mode 100644 (file)
index 0000000..d96f12e
--- /dev/null
@@ -0,0 +1,42 @@
+import logging
+import traceback
+import os.path
+
+from wizard import command, deploy
+
+def main(argv, baton):
+    options, show = parse_args(argv, baton)
+    errors = 0
+    for d in deploy.parse_install_lines(show, options, True):
+        if isinstance(d, Exception):
+            errors += 1
+        if options.exists and not os.path.exists(os.path.join(d.location, options.exists)):
+            continue
+        print d.location
+    if errors:
+        logging.warning("%d errors, see wizard errors for details" % errors)
+
+def parse_args(argv, baton):
+    usage = """usage: %prog list [ARGS] [APP[-VERSION]]
+
+Lists the locations of all autoinstalls, optionally
+filtered on parameters such as application name and version.
+
+Examples:
+    %prog list
+        List all autoinstalls
+    %prog list --exists php.ini
+        List all autoinstalls with php.ini
+    %prog list mediawiki
+        List only MediaWiki autoinstalls
+    %prog list mediawiki-1.11.0
+        List only Mediawiki 1.11.0 autoinstalls"""
+    parser = command.WizardOptionParser(usage)
+    parser.add_option("-e", "--exists", dest="exists",
+            help="only print deployment if FILE exists", metavar="FILE")
+    baton.push(parser, "versions_path")
+    options, args = parser.parse_all(argv)
+    if len(args) > 1:
+        parser.error("too many arguments")
+    return options, args
+
index 7284f8c3faa977c299b1fc8f0c5f900ffdac7567..f47c61a782adfed0dbf3347997cc0b690c9df0df 100644 (file)
@@ -12,9 +12,6 @@ Scans all of the collected data from parallel-find.pl, and
 calculates interesting information about them.
 
 Its subcommands are:
-    count-exists    Counts how many autoinstalls contain a file
-    list            Prints the locations of all autoinstalls
-    list-errors     Prints all errors that occurred during parsing
     version         Breakdown of autoinstalls by version (default)
 
 Use %prog summary SUBCOMMAND --help for more information."""
@@ -46,40 +43,3 @@ Use %prog summary SUBCOMMAND --help for more information."""
         parser.error("invalid action")
     command_module.main(rest_argv, baton)
 
-## -- some generic helper stuff --
-
-def parse_install_lines(show, options, yield_errors = False):
-    if not show: show = deploy.applications()
-    show = frozenset(show)
-    for line in deploy.getInstallLines(options.versions_path):
-        # construction
-        try:
-            d = deploy.Deployment.parse(line)
-            name = d.application.name
-        except deploy.NoSuchApplication as e:
-            if yield_errors:
-                yield e
-            continue
-        except deploy.Error:
-            # we consider this a worse error
-            logging.warning("Error with '%s'" % line.rstrip())
-            continue
-        # filter
-        if name + "-" + str(d.version) in show or name in show:
-            pass
-        else:
-            continue
-        # yield
-        yield d
-
-class Counter(object):
-    def __init__(self):
-        self.dict = {}
-    def count(self, value):
-        self.dict.setdefault(value, 0)
-        self.dict[value] += 1
-    def __getitem__(self, key):
-        return self.dict[key]
-    def __iter__(self):
-        return self.dict.__iter__()
-
diff --git a/wizard/command/summary/count_exists.py b/wizard/command/summary/count_exists.py
deleted file mode 100644 (file)
index e9f6eea..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-import os
-
-from wizard import command
-from wizard.command import summary
-
-def main(argv, baton):
-    options, args = parse_args(argv, baton)
-    value = args[0]
-    show = args[1:]
-    for d in summary.parse_install_lines(show, options):
-        if os.path.exists(d.location + "/" + value):
-            print d.location
-
-def parse_args(argv, baton):
-    usage = """usage: %prog summary count-exists [ARGS] FILE [APP[-VERSION]]
-
-Lists all autoinstalls that contain FILE in their
-working copy.
-
-Examples:
-    %prog summary count-exists php.ini
-        Finds all autoinstalls that contain php.ini files"""
-    parser = command.WizardOptionParser(usage)
-    baton.push(parser, "versions_path")
-    options, args = parser.parse_all(argv)
-    if len(args) > 1:
-        parser.error("too many arguments")
-    if not args:
-        parser.error("need to specify FILE")
-    return options, args
-
diff --git a/wizard/command/summary/list.py b/wizard/command/summary/list.py
deleted file mode 100644 (file)
index 7d3feb1..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-import logging
-import traceback
-
-from wizard import command
-from wizard.command import summary
-
-def main(argv, baton):
-    options, show = parse_args(argv, baton)
-    errors = 0
-    for d in summary.parse_install_lines(show, options, True):
-        if isinstance(d, Exception):
-            errors += 1
-        print d.location
-    if errors:
-        logging.warning("%d errors, see wizard summary list-errors for details" % errors)
-
-def parse_args(argv, baton):
-    usage = """usage: %prog summary list [ARGS] [APP[-VERSION]]
-
-Lists the locations of all autoinstalls, optionally
-filtered on application name and version.
-
-Examples:
-    %prog summary list
-        List all autoinstalls
-    %prog summary list mediawiki
-        List only MediaWiki autoinstalls
-    %prog summary list mediawiki-1.11.0
-        List only Mediawiki 1.11.0 autoinstalls"""
-    parser = command.WizardOptionParser(usage)
-    baton.push(parser, "versions_path")
-    options, args = parser.parse_all(argv)
-    if len(args) > 1:
-        parser.error("too many arguments")
-    return options, args
-
index 09d17ee92fa279d3cf654d17395947d2d33384d0..2dc29c834eefc14d44be3fc8ad277c9b429ff9de 100644 (file)
@@ -1,15 +1,14 @@
 import math
 
-from wizard import command
-from wizard.command import summary
+from wizard import command, deploy, util
 
 def main(argv, baton):
     options, show = parse_args(argv, baton)
     HISTOGRAM_WIDTH = 30
     show = set()
-    c_version = summary.Counter()
-    c_application = summary.Counter()
-    for d in summary.parse_install_lines(show, options):
+    c_version = util.Counter()
+    c_application = util.Counter()
+    for d in deploy.parse_install_lines(show, options):
         version = d.app_version
         c_version.count(version)
         c_application.count(version.application)
index 5b4ae3d14b8ae6264df32bf69eda5a24f156451b..e6f591872a38378797c89508605a4c33be9c7016 100644 (file)
@@ -15,6 +15,30 @@ def getInstallLines(vs):
         return fileinput.input([vs])
     return fileinput.input([vs + "/" + f for f in os.listdir(vs)])
 
+def parse_install_lines(show, options, yield_errors = False):
+    if not show: show = applications()
+    show = frozenset(show)
+    for line in getInstallLines(options.versions_path):
+        # construction
+        try:
+            d = Deployment.parse(line)
+            name = d.application.name
+        except deploy.NoSuchApplication as e:
+            if yield_errors:
+                yield e
+            continue
+        except deploy.Error:
+            # we consider this a worse error
+            logging.warning("Error with '%s'" % line.rstrip())
+            continue
+        # filter
+        if name + "-" + str(d.version) in show or name in show:
+            pass
+        else:
+            continue
+        # yield
+        yield d
+
 ## -- Model Objects --
 
 class Deployment(object):
index 08a6a66c0941efd123e4206a424a6820ff450bba..2588d173bba79bd185ee82f18ef62fbeb95b2a1d 100644 (file)
@@ -17,6 +17,17 @@ class ChangeDirectory(object):
     def __exit__(self, *args):
         os.chdir(self.olddir)
 
+class Counter(object):
+    def __init__(self):
+        self.dict = {}
+    def count(self, value):
+        self.dict.setdefault(value, 0)
+        self.dict[value] += 1
+    def __getitem__(self, key):
+        return self.dict[key]
+    def __iter__(self):
+        return self.dict.__iter__()
+
 def dictmap(f, d):
     """A map function for dictionaries.  Does not allow changing keys, only
     values"""