Add debug option and update logging

This commit is contained in:
James Slagle 2013-08-20 07:54:47 -04:00
parent b866b47e1f
commit 3937dfd0f5
3 changed files with 11 additions and 5 deletions

View File

@ -36,7 +36,10 @@ def load_args():
'-k', '--hook', nargs='+', required=True,
help=("hook(s) to execute for each element"))
parser.add_argument(
'-d', '--dry-run', action='store_true',
'-d', '--debug', action='store_true',
help=("Debugging output"))
parser.add_argument(
'--dry-run', action='store_true',
help=("Dry run only, don't actually modify system, prints out "
"what would have been run."))
return parser.parse_args()
@ -58,7 +61,8 @@ def main():
set_environment()
logging.basicConfig(level=logging.DEBUG,
format="%(levelname)s:%(asctime)s:%(name)s:%(message)s")
em = manager.ElementManager(args.element, args.hook, args.element_path, args.dry_run)
em = manager.ElementManager(args.element, args.hook, args.element_path,
args.dry_run, args.debug)
em.run()

View File

@ -52,7 +52,7 @@ class ElementManager(object):
if self.element_paths is None:
raise Exception
logging.debug('manager initialized with elements path: %s' %
logging.info('manager initialized with elements path: %s' %
self.element_paths)
self.load_elements()
@ -62,6 +62,7 @@ class ElementManager(object):
def run(self):
"""Apply the elements by running each specified hook."""
for hook in self.hooks:
logging.info("running hook: %s" % hook)
self.run_hook(hook)
def load_elements(self):
@ -118,6 +119,7 @@ class ElementManager(object):
scripts = [os.path.abspath(os.path.join(hook_dir, s)) for s in scripts]
for script in scripts:
logging.info("running script: %s" % script)
if not self.dry_run:
# environment must be preseverd so that the variables set
# earlier in os.environ are available in the scripts.

View File

@ -22,7 +22,7 @@ import sys
def call(*args, **kwargs):
"""Call out to run a command via subprocess."""
logging.debug('executing command: %s' % args)
logging.info('executing command: %s' % args)
# all output to stdout/stderr for now.
p = subprocess.Popen(*args,
stdout=sys.stdout,
@ -31,5 +31,5 @@ def call(*args, **kwargs):
**kwargs)
rc = p.wait()
logging.debug(' exited with code: %s' % rc)
logging.info(' exited with code: %s' % rc)
return rc