diff options
author | Ric Holland <richard.holland@codethink.co.uk> | 2013-03-08 15:30:51 +0000 |
---|---|---|
committer | Ric Holland <richard.holland@codethink.co.uk> | 2013-03-08 15:30:51 +0000 |
commit | 177405915072deebff194e5ed20182a641416155 (patch) | |
tree | bfabb38a95cbfae2f96bdad1673166fe41365f48 | |
parent | f624dc956fcb059273edcffdde2d942be2124914 (diff) | |
download | morph-177405915072deebff194e5ed20182a641416155.tar.gz |
Change morph to reduce loogign of the environment
Added function log_dict_diff to identify and record changes in dicts
to the debug log
This new function was then implemented in app.py to log changes in the
environment
-rwxr-xr-x | morphlib/app.py | 5 | ||||
-rw-r--r-- | morphlib/util.py | 17 |
2 files changed, 20 insertions, 2 deletions
diff --git a/morphlib/app.py b/morphlib/app.py index 21e18e32..87710ee5 100755 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -395,8 +395,9 @@ class Morph(cliapp.Application): chatty=True) # Log the environment. - for name in kwargs['env']: - logging.debug('environment: %s=%s' % (name, kwargs['env'][name])) + prev = getattr(self, 'prev_env', {}) + morphlib.util.log_dict_diff(kwargs['env'], prev) + self.prev_env = kwargs['env'] # run the command line return cliapp.Application.runcmd(self, argv, *args, **kwargs) diff --git a/morphlib/util.py b/morphlib/util.py index c832a141..5aa00293 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -16,6 +16,7 @@ import re import morphlib +import logging '''Utility functions for morph.''' @@ -170,6 +171,22 @@ def new_repo_caches(app): # pragma: no cover return lrc, rrc +def log_dict_diff(cur, pre): + '''Log the differences between two dicts to debug log''' + dictA = cur + dictB = pre + for key in dictA.keys(): + if key not in dictB: + logging.debug("New environment: %s = %s" % (key, dictA[key])) + elif dictA[key] != dictB[key]: + logging.debug( + "Environment changed: %(key)s = %(valA)s to %(key)s = %(valB)s" + % {"key": key, "valA": dictA[key], "valB": dictB[key]}) + for key in dictB.keys(): + if key not in dictA: + logging.debug("Environment removed: %s = %s" % (key, dictB[key])) + + # This acquired from rdiff-backup which is GPLv2+ and a patch from 2011 # which has not yet been merged, combined with a tad of tidying from us. def copyfileobj(inputfp, outputfp, blocksize=1024*1024): # pragma: no cover |