changeset 103:f1baf05a49dd

* Strip extra line separators from recipe command output on windows. Closes #25. * Fix logging in the `build.py` script, and provide command-line options to configure the logging
author cmlenz
date Wed, 20 Jul 2005 13:23:05 +0000
parents c6bc84b0b159
children 4bee62474361
files bitten/util/cmdline.py scripts/build.py
diffstat 2 files changed, 29 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/bitten/util/cmdline.py
+++ b/bitten/util/cmdline.py
@@ -74,7 +74,8 @@
             out_file.close()
             err_file.close()
             for out_line, err_line in self._combine(out_lines, err_lines):
-                yield out_line, err_line
+                yield out_line and out_line.rstrip(), \
+                      err_line and err_line.rstrip()
 
     else: # posix
 
--- a/scripts/build.py
+++ b/scripts/build.py
@@ -19,31 +19,47 @@
 #
 # Author: Christopher Lenz <cmlenz@gmx.de>
 
+import itertools
+import logging
 import sys
 
 from bitten.build import BuildError
 from bitten.recipe import Recipe
 
-def build():
-    step_id = None
-    if len(sys.argv) > 1:
-        step_id = sys.argv[1]
+def main():
+    from bitten import __version__ as VERSION
+    from optparse import OptionParser
 
+    parser = OptionParser(usage='usage: %prog [options] [step1] [step2] ...',
+                          version='%%prog %s' % VERSION)
+    parser.add_option('-v', '--verbose', action='store_const', dest='loglevel',
+                      const=logging.DEBUG, help='print as much as possible')
+    parser.add_option('-q', '--quiet', action='store_const', dest='loglevel',
+                      const=logging.ERROR, help='print as little as possible')
+    parser.set_defaults(loglevel=logging.INFO)
+    options, args = parser.parse_args()
+
+    log = logging.getLogger('bitten')
+    log.setLevel(options.loglevel)
+    handler = logging.StreamHandler()
+    handler.setLevel(options.loglevel)
+    formatter = logging.Formatter('[%(levelname)-8s] %(message)s')
+    handler.setFormatter(formatter)
+    log.addHandler(handler)
+
+    steps_to_run = dict([(step, False) for step in args])
     recipe = Recipe()
-    steps_run = []
     for step in recipe:
-        if not step_id or step.id == step_id:
+        if not steps_to_run or step.id in steps_to_run:
             print '-->', step.description or step.id
             step.execute(recipe.ctxt)
             print
-            steps_run.append(step.id)
-
-    if step_id and not step_id in steps_run:
-        raise BuildError, 'Recipe has no step named "%s"' % step_id
+            if step.id in steps_to_run:
+                steps_to_run[step.id] = True
 
 if __name__ == '__main__':
     try:
-        build()
+        main()
     except BuildError, e:
         print>>sys.stderr, 'FAILED: %s' % e
         sys.exit(-1)
Copyright (C) 2012-2017 Edgewall Software