From 7581ce568b0e8d50c9e0ea034e08ef8d456c7bf5 Mon Sep 17 00:00:00 2001 From: Brian Harring Date: Thu, 12 Jan 2006 11:16:49 +0000 Subject: don't inline code, do __name__=="__main__" so the module can be used instead of strictly called. svn path=/main/trunk/; revision=2560 --- bin/emaint | 95 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 48 insertions(+), 47 deletions(-) (limited to 'bin/emaint') diff --git a/bin/emaint b/bin/emaint index 34956926f..a3868772f 100755 --- a/bin/emaint +++ b/bin/emaint @@ -45,70 +45,71 @@ class WorldHandler(object): return errors +# this sucks, should track this in a different manner. modules = {"world" : WorldHandler} - module_names = modules.keys() module_names.sort() module_names.insert(0, "all") - -def exclusive(option, unused1, unused2, unused3, var=None): - if not var: - raise ValueError("var not specified to exclusive()") - if getattr(parser, var, ""): - raise OptionValueError("%s and %s are exclusive options" % (getattr(parser, var), option)) - setattr(parser, var, str(option)) +if __name__ == "__main__": + def exclusive(option, *args, **kw): + var = kw.get("var", None) + if var is None: + raise ValueError("var not specified to exclusive()") + if getattr(parser, var, ""): + raise OptionValueError("%s and %s are exclusive options" % (getattr(parser, var), option)) + setattr(parser, var, str(option)) -usage = "usage: emaint [options] " + " | ".join(module_names) + usage = "usage: emaint [options] " + " | ".join(module_names) -usage+= "\n\nCurrently emaint can only check and fix problems with one's world\n" -usage+= "file. Future versions will integrate other portage check-and-fix\n" -usage+= "tools and provide a single interface to system health checks." + usage+= "\n\nCurrently emaint can only check and fix problems with one's world\n" + usage+= "file. Future versions will integrate other portage check-and-fix\n" + usage+= "tools and provide a single interface to system health checks." -parser = OptionParser(usage=usage) -parser.add_option("-c", "--check", help="check for problems", - action="callback", callback=exclusive, callback_kwargs={"var":"action"}) -parser.add_option("-f", "--fix", help="attempt to fix problems", - action="callback", callback=exclusive, callback_kwargs={"var":"action"}) -parser.action = None + parser = OptionParser(usage=usage) + parser.add_option("-c", "--check", help="check for problems", + action="callback", callback=exclusive, callback_kwargs={"var":"action"}) + parser.add_option("-f", "--fix", help="attempt to fix problems", + action="callback", callback=exclusive, callback_kwargs={"var":"action"}) + parser.action = None -(options, args) = parser.parse_args() -if len(args) != 1: - parser.error("Incorrect number of arguments") -if args[0] not in module_names: - parser.error("%s target is not a known target" % args[0]) + (options, args) = parser.parse_args() + if len(args) != 1: + parser.error("Incorrect number of arguments") + if args[0] not in module_names: + parser.error("%s target is not a known target" % args[0]) -if parser.action: - action = parser.action -else: - print "Defaulting to --check" - action = "-c/--check" + if parser.action: + action = parser.action + else: + print "Defaulting to --check" + action = "-c/--check" -if args[0] == "all": - tasks = modules.values() -else: - tasks = [modules[args[0]]] + if args[0] == "all": + tasks = modules.values() + else: + tasks = [modules[args[0]]] -if action == "-c/--check": - status = "Checking %s for problems" - func = "check" -else: - status = "Attempting to fix %s" - func = "fix" + if action == "-c/--check": + status = "Checking %s for problems" + func = "check" + else: + status = "Attempting to fix %s" + func = "fix" -for task in tasks: - print status % task.name() - inst = task() - result = getattr(inst, func)() - if result: - print - print "\n".join(result) - print "\n" + for task in tasks: + print status % task.name() + inst = task() + result = getattr(inst, func)() + if result: + print + print "\n".join(result) + print "\n" -print "Finished" + print "Finished" -- cgit v1.2.3-1-g7c22