@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',
@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
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])
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:
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()
@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:
def __call__(self, args=None):
- logger.debug("Main:__call__()")
if args:
self.run(self.parse_args(args))
else:
@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(
@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",
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)
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)
'''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()
'''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()
'''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)
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]])
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
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
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
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]
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