]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/command/__init__.py
Rewrite parametrize to use new parametrizeWithVars
[wizard.git] / wizard / command / __init__.py
index 3314ac0bbe8645ad5085b343ee9d27b185b20cca..5d77be38427ebce61fe24883f367fef24b240fb0 100644 (file)
@@ -12,6 +12,7 @@ import wizard
 from wizard import util
 
 logging_setup = False
+debug = True # This will get overwritten with the real value early on
 
 def boolish(val):
     """
@@ -127,77 +128,6 @@ def create_logdir(log_dir):
         #    # XXX: update last symlink
     os.chmod(log_dir, 0o777)
 
-class Report(object):
-    #: Set of indices that should be skipped
-    skip = None
-    #: Dict of append names to counts.  You should manually increment these as necessary
-    fails = None
-    #: Names of the files objects
-    names = None
-    def __init__(self, names, fobjs, skip, fails):
-        self.skip = skip
-        self.names = names
-        self.fails = fails
-        for name, fobj in zip(names, fobjs):
-            setattr(self, name, fobj)
-    def flush(self):
-        for n in self.names:
-            getattr(self, n).flush()
-
-def report_files(log_dir, names):
-    return [os.path.join(os.path.join(log_dir, "%s.txt" % x)) for x in names]
-
-def read_reports(log_dir, names):
-    """
-    Reads a number of reports files.  The return value is a :class:`Report`
-    object with attributes that are open file objects that correspond to ``names``.
-    """
-    return Report(names, [(os.path.exists(f) and open(f, "r") or cStringIO.StringIO()) for f in report_files(log_dir, names)], set(), {})
-
-def open_reports(log_dir, names=('warnings', 'errors'), redo=False, append_names=()):
-    """
-    Returns a :class:`Report` object configured appropriately for the
-    parameters passed.  This object has attributes names + append_names which
-    contain file objects opened as "w".  ``names`` report files are cleared unconditionally
-    when they are opened (i.e. are not preserved from run to run.)  ``append_names``
-    report files are not cleared unless ``redo`` is True, and persist over
-    runs: assuming the convention that [0001] is the index of the deployment,
-    the ``skip`` attribute on the returned report object contains indexes that
-    should be skipped.
-    """
-    skip = set()
-    fails = {}
-    if not redo:
-        rr = read_reports(log_dir, append_names)
-        def build_set(skip, fails, name, fobj):
-            lines = fobj.read().strip().splitlines()
-            skip |= set(int(l[1:5]) for l in lines)
-            fails[name] = len(lines)
-            fobj.close()
-        for name in append_names:
-            build_set(skip, fails, name, getattr(rr, name))
-    else:
-        names += append_names
-        for name in append_names:
-            fails[name] = 0
-        append_names = ()
-    files = report_files(log_dir, names)
-    append_files = report_files(log_dir, append_names)
-    # backup old reports
-    old_reports = os.path.join(log_dir, "old-reports")
-    rundir = os.path.join(old_reports, "run")
-    if not os.path.exists(old_reports):
-        os.mkdir(old_reports)
-    else:
-        util.safe_unlink(rundir)
-    for f in files:
-        if os.path.exists(f):
-            os.rename(f, rundir)
-    for f in append_files:
-        if os.path.exists(f):
-            shutil.copy(f, rundir)
-    return Report(names + append_names, [open(f, "w") for f in files] + [open(f, "a") for f in append_files], skip, fails)
-
 class NullLogHandler(logging.Handler):
     """Log handler that doesn't do anything"""
     def emit(self, record):
@@ -205,11 +135,18 @@ class NullLogHandler(logging.Handler):
 
 class WizardOptionParser(optparse.OptionParser):
     """Configures some default user-level options"""
+    store_help = False
     def __init__(self, *args, **kwargs):
         kwargs["add_help_option"] = False
+        if "store_help" in kwargs:
+            self.store_help = kwargs["store_help"]
+            del kwargs["store_help"]
         optparse.OptionParser.__init__(self, *args, **kwargs)
     def parse_all(self, *args, **kwargs):
-        self.add_option("-h", "--help", action="help", help=optparse.SUPPRESS_HELP)
+        if self.store_help:
+            self.add_option("-h", "--help", action="store_true", default=False, dest="help", help=optparse.SUPPRESS_HELP)
+        else:
+            self.add_option("-h", "--help", action="help", help=optparse.SUPPRESS_HELP)
         group = optparse.OptionGroup(self, "Common Options")
         group.add_option("-v", "--verbose", dest="verbose", action="store_true",
                 default=boolish(os.getenv("WIZARD_VERBOSE")), help="Turns on verbose output.  Envvar is WIZARD_VERBOSE")
@@ -222,6 +159,7 @@ class WizardOptionParser(optparse.OptionParser):
         self.add_option_group(group)
         options, numeric_args = self.parse_args(*args, **kwargs)
         setup_logger(options, numeric_args)
+        debug = options.debug
         # we're going to process the global --log-dir/--seen dependency here
         if hasattr(options, "seen") and hasattr(options, "log_dir"):
             if not options.seen and options.log_dir: