Anonymous avatar Anonymous committed 0533fdf

Added logging

Comments (0)

Files changed (1)

 import sys
 import errno
 import shutil
+import logging
 import subprocess
-from optparse import OptionParser
+from optparse import OptionParser, Option as BaseOption
 from itertools import repeat
     If the return code is unequal to 0, an :exc:`SubprocessError` is raised.
+    if logging.getLogger().level < logging.WARNING:
+        stdout = sys.stdout
+    else:
+        stdout = subprocess.PIPE
     process = subprocess.Popen(
-        stdout=subprocess.PIPE,
+        stdout=stdout,
     if process.wait() != os.EX_OK:
         raise SubprocessError(args, process.returncode,
-    return
+    if process.stdout is not None:
+        return
 class SubprocessError(EnvironmentError):
     Downloads the interpreters defined in `interpreter_cfg` to
     `interpreter_dir` if they have not already been downloaded.
     for name, interpreter in interpreter_cfg.iteritems():
         target = os.path.join(interpreter_dir, name)
         method = interpreter['Source']['method']
+  'Cloning Repository of %s' % name)
             clone_repo(repository, source_target, method)
         except OSError as err:
             if err.errno != errno.EEXIST:
+'Finished Initializing')
 def update_hg_repo(repo):
 def update_interpreters(interpreter_cfg, interpreter_path):
     for interpreter_dir in os.listdir(interpreter_path):
         source_dir = os.path.join(interpreter_path, interpreter_dir, 'Source')
         if os.path.exists(source_dir):
             method = interpreter_cfg[interpreter_dir]['Source']['method']
+  '...%s' % interpreter_dir)
             update_repo(source_dir, method)
+'Finished Updating')
 def build_interpreters(interpreter_cfg, interpreter_path):
+'Building Interpreters')
     for name, config in interpreter_cfg.iteritems():
         cwd = os.path.join(interpreter_path, name, 'Source')
+'Building %s' % name)
         for command in config['Source']['commands']:
             call_subprocess(command, cwd=cwd)
+'Finished Building')
+class Option(BaseOption):
+    ACTIONS = BaseOption.ACTIONS + ('increase', 'decrease')
+    STORE_ACTIONS = BaseOption.STORE_ACTIONS + ('increase', 'decrease')
+    def take_action(self, action, dest, opt, value, values, parser):
+        if action == 'increase':
+            setattr(values, dest, values.ensure_value(dest, 0) + 1)
+        elif action == 'decrease':
+            setattr(values, dest, values.ensure_value(dest, 0) - 1)
+        else:
+            BaseOption.take_action(
+                self, action, dest, opt, value, values, parser
+            )
 def main(argv=sys.argv):
-    parser = OptionParser(usage='%prog [-ci]')
+    parser = OptionParser(usage='%prog [-ci]', option_class=Option)
         '-c', '--config',
         help='path to the interpreter location'
+    parser.add_option(
+        '-v', '--verbose',
+        action='decrease',
+        dest='verbosity',
+        default=3
+    )
+    parser.add_option(
+        '-q', '--quiet',
+        action='increase',
+        dest='verbosity',
+        default=3
+    )
     options, args = parser.parse_args(argv[1:])
+    logging.basicConfig(level=options.verbosity * 10)
     config = load_config(options.config)
     interpreters = config['interpreters']
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.