From a35a3b9db04a9b4d3759bdce14619f4e2b6edce2 Mon Sep 17 00:00:00 2001 From: Brian Dolbec Date: Sat, 22 Jun 2013 12:29:02 -0700 Subject: [PATCH] Unify logger message identification --- gkeyldap/cli.py | 34 ++++++++++++++++++++++------------ gkeys/cli.py | 31 +++++++++++++++---------------- gkeys/config.py | 2 +- gkeys/seed.py | 12 ++++++------ 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/gkeyldap/cli.py b/gkeyldap/cli.py index ccc9159..21e551f 100644 --- a/gkeyldap/cli.py +++ b/gkeyldap/cli.py @@ -46,7 +46,7 @@ class Main(object): @param args: list @returns argparse.Namespace object ''' - logger.debug('args: %s' % args) + logger.debug('MAIN: parse_args; args: %s' % args) actions = ['ldapsearch', 'updateseeds'] parser = argparse.ArgumentParser( prog='gkeys', @@ -83,17 +83,18 @@ class Main(object): @param args: list or argparse.Namespace object ''' if not args: - logger.error("Main.run() invalid args argument passed in") + logger.error("Main: run; invalid args argument passed in") if isinstance(args, list): args = self.parse_args(args) if args.config: - logger.debug("Found alternate config request: %s" % args.config) + logger.debug("Main: run; Found alternate config request: %s" + % args.config) self.config.defaults['config'] = args.config # now make it load the config file self.config.read_config() func = getattr(self, '_action_%s' % args.action) - logger.debug('Found action: %s' % args.action) + logger.debug('Main: run; Found action: %s' % args.action) results = func(args) return results @@ -103,7 +104,7 @@ class Main(object): if not l.connect(): print("Aborting Search...Connection failed") return False - logging.debug("args = %s" % str(args)) + logger.debug("MAIN: _action_ldapsearch; args = %s" % str(args)) x, target, search_field = self.get_args(args) results = l.search(target, search_field) devs = l.result2dict(results, gkey2ldap_map[x]) @@ -121,19 +122,26 @@ class Main(object): return False results = l.search('*', UID) info = l.result2dict(results, 'uid') - logger.debug("_action_updateseeds, got results :) converted to info") + logger.debug( + "MAIN: _action_updateseeds; got results :) converted to info") if not self.create_seedfile(info): logger.error("Dev seed file update failure: " "Original seed file is intact & untouched.") old = self.config['dev-seedfile'] + '.old' try: if os.path.exists(old): - logger.debug("Removing 'old' seed file: %s" % old) + logger.debug( + "MAIN: _action_updateseeds; Removing 'old' seed file: %s" + % old) os.unlink(old) if os.path.exists(self.config['dev-seedfile']): - logger.debug("Renaming current seed file to: %s" % old) + logger.debug( + "MAIN: _action_updateseeds; Renaming current seed file to: " + "%s" % old) os.rename(self.config['dev-seedfile'], old) - logger.debug("Renaming 'new' seed file to: %s" % self.config['dev-seedfile'])) + logger.debug( + "MAIN: _action_updateseeds; Renaming '.new' seed file to: %s" + % self.config['dev-seedfile']) os.rename(self.config['dev-seedfile'] + '.new', self.config['dev-seedfile']) except IOError: @@ -150,12 +158,14 @@ class Main(object): for dev in sorted(devs): if devs[dev]['gentooStatus'][0] not in ['active']: continue - #logger.debug("create_seedfile, dev = %s, %s" % (str(dev), str(devs[dev]))) + #logger.debug("create_seedfile, dev = " + # "%s, %s" % (str(dev), str(devs[dev]))) new_gkey = GKEY._make(self.build_gkeylist(devs[dev])) self.seeds.add(new_gkey) count += 1 print("Total number of seeds created:", count) - logger.debug("MAIN: create_seedfile; seeds created...saving file: %s" % filename) + logger.debug("MAIN: create_seedfile; seeds created...saving file: %s" + % filename) return self.seeds.save() @@ -193,7 +203,7 @@ class Main(object): @staticmethod def build_gkeylist(info): keyinfo = [] - #logger.debug("build_gkeylist, info = %s" % str(info)) + #logger.debug("MAIN: build_gkeylist; info = %s" % str(info)) for x in GKEY._fields: field = gkey2ldap_map[x] if not field: diff --git a/gkeys/cli.py b/gkeys/cli.py index 133a14f..b9846d9 100644 --- a/gkeys/cli.py +++ b/gkeys/cli.py @@ -41,7 +41,6 @@ class Main(object): def __call__(self, args=None): - logger.debug("Main:__call__()") if args: self.run(self.parse_args(args)) else: @@ -54,7 +53,7 @@ class Main(object): @param args: list @returns argparse.Namespace object ''' - logger.debug('args: %s' % args) + logger.debug('MAIN: parse_args; args: %s' % args) actions = ['listseed', 'addseed', 'removeseed', 'moveseed', 'listkey', 'addkey', 'removekey', 'movekey'] parser = argparse.ArgumentParser( @@ -98,17 +97,17 @@ class Main(object): @param args: list or argparse.Namespace object ''' if not args: - logger.error("Main.run() invalid args argument passed in") + logger.error("Main: run; invalid args argument passed in") if isinstance(args, list): args = self.parse_args(args) if args.config: - logger.debug("Found alternate config request: %s" % args.config) + logger.debug("Main: run; Found alternate config request: %s" % args.config) self.config.defaults['config'] = args.config # now make it load the config file self.config.read_config() func = getattr(self, '_action_%s' % args.action) - logger.debug('Found action: %s' % args.action) + logger.debug('Main: run; Found action: %s' % args.action) results = func(args) if not results: print("No results found. Check your configuration and that the", @@ -149,7 +148,7 @@ class Main(object): if not filename: return None filepath = self.config.get_key(filename + "-seedfile") - logger.debug("_load_seeds(); seeds filepath to load: " + logger.debug("MAIN: _load_seeds; seeds filepath to load: " "%s" % filepath) seeds = Seeds() seeds.load(filepath) @@ -159,7 +158,7 @@ class Main(object): def _action_listseed(self, args): '''Action listseed method''' kwargs = self.build_gkeydict(args) - logger.debug("_action_listseed(); kwargs: %s" % str(kwargs)) + logger.debug("MAIN: _action_listseed; kwargs: %s" % str(kwargs)) seeds = self._load_seeds(args.seeds) if seeds: results = seeds.list(**kwargs) @@ -171,11 +170,11 @@ class Main(object): '''Action addseed method''' parts = self.build_gkeylist(args) gkey = GKEY._make(parts) - logger.debug("_action_addseed(); new gkey: %s" % str(gkey)) + logger.debug("MAIN: _action_addseed; new gkey: %s" % str(gkey)) seeds = self._load_seeds(args.seeds) gkeys = self._action_listseed(args) if len(gkeys) == 0: - logger.debug("_action_addkey(); now adding gkey: %s" % str(gkey)) + logger.debug("MAIN: _action_addkey; now adding gkey: %s" % str(gkey)) success = seeds.add(gkey) if success: success = seeds.save() @@ -191,11 +190,11 @@ class Main(object): '''Action removeseed method''' parts = self.build_gkeylist(args) searchkey = GKEY._make(parts) - logger.debug("_action_removeseed(); gkey: %s" % str(searchkey)) + logger.debug("MAIN: _action_removeseed; gkey: %s" % str(searchkey)) seeds = self._load_seeds(args.seeds) gkeys = self._action_listseed(args) if len(gkeys) == 1: - logger.debug("_action_removeseed(); now deleting gkey: %s" % str(gkeys[0])) + logger.debug("MAIN: _action_removeseed; now deleting gkey: %s" % str(gkeys[0])) success = seeds.delete(gkeys[0]) if success: success = seeds.save() @@ -213,7 +212,7 @@ class Main(object): '''Action moveseed method''' parts = self.build_gkeylist(args) searchkey = GKEY._make(parts) - logger.debug("_action_moveseed(); gkey: %s" % str(searchkey)) + logger.debug("MAIN: _action_moveseed; gkey: %s" % str(searchkey)) seeds = self._load_seeds(args.seeds) kwargs = self.build_gkeydict(args) sourcekeys = seeds.list(**kwargs) @@ -221,15 +220,15 @@ class Main(object): destkeys = dest.list(**kwargs) messages = [] if len(sourcekeys) == 1 and destkeys == []: - logger.debug("_action_moveseed(); now adding destination gkey: %s" + logger.debug("MAIN: _action_moveseed; now adding destination gkey: %s" % str(sourcekeys[0])) success = dest.add(sourcekeys[0]) - logger.debug("_action_moveseed(); success: %s" %str(success)) - logger.debug("_action_moveseed(); now deleting sourcekey: %s" % str(sourcekeys[0])) + logger.debug("MAIN: _action_moveseed; success: %s" %str(success)) + logger.debug("MAIN: _action_moveseed; now deleting sourcekey: %s" % str(sourcekeys[0])) success = seeds.delete(sourcekeys[0]) if success: success = dest.save() - logger.debug("_action_moveseed(); destination saved... %s" %str(success)) + logger.debug("MAIN: _action_moveseed; destination saved... %s" %str(success)) success = seeds.save() messages.extend(["Successfully Moved %s seed: %s" % (args.seeds, str(success)), sourcekeys[0]]) diff --git a/gkeys/config.py b/gkeys/config.py index 3da1c21..f775d23 100644 --- a/gkeys/config.py +++ b/gkeys/config.py @@ -86,7 +86,7 @@ class GKeysConfig(GPGConfig): return self.options[key] elif key in self.defaults: return self.defaults[key] - logger.error("GKeysConfig: _get_(); didn't find :", key) + logger.error("GKeysConfig: _get_; didn't find :", key) return None diff --git a/gkeys/seed.py b/gkeys/seed.py index 4b4710a..fc71551 100644 --- a/gkeys/seed.py +++ b/gkeys/seed.py @@ -39,7 +39,7 @@ class Seeds(object): if filename: self.filename = filename if not self.filename: - logger.debug("Seed.load() Not a valid filename: '%s'" % str(self.filename)) + logger.debug("Seed: load; Not a valid filename: '%s'" % str(self.filename)) return False logger.debug("Seeds: Begin loading seed file %s" % self.filename) seedlines = None @@ -57,7 +57,7 @@ class Seeds(object): self.seeds.append(GKEY._make(parts)) except Exception as err: self._error(err) - logger.debug("Completed loading seed file %s" % self.filename) + logger.debug("Seed: load; Completed loading seed file %s" % self.filename) return True @@ -66,9 +66,9 @@ class Seeds(object): if filename: self.filename = filename if not self.filename: - logger.debug("Seed.load() Not a valid filename: '%s'" % str(self.filename)) + logger.debug("Seed: save; Not a valid filename: '%s'" % str(self.filename)) return False - logger.debug("Begin saving seed file %s" % self.filename) + logger.debug("Seed: save; Begin saving seed file %s" % self.filename) try: with open(self.filename, 'w') as seedfile: seedlines = [x.value_string(self.separator) for x in self.seeds] @@ -141,8 +141,8 @@ class Seeds(object): def _error(self, err): '''Class error logging function''' - logger.error("Error processing seed file %s" % self.filename) - logger.error("Error was: %s" % str(err)) + logger.error("Seed: Error processing seed file %s" % self.filename) + logger.error("Seed: Error was: %s" % str(err)) @staticmethod -- 2.26.2