summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Harring <ferringb@gentoo.org>2006-01-12 11:16:49 +0000
committerBrian Harring <ferringb@gentoo.org>2006-01-12 11:16:49 +0000
commit7581ce568b0e8d50c9e0ea034e08ef8d456c7bf5 (patch)
tree06dc710cee1c4bd2e86c2491dc8090347db07bf4
parentc86bd1dfba4420775577b6c797a8dc4d0da4d3e9 (diff)
downloadportage-7581ce568b0e8d50c9e0ea034e08ef8d456c7bf5.tar.gz
portage-7581ce568b0e8d50c9e0ea034e08ef8d456c7bf5.tar.bz2
portage-7581ce568b0e8d50c9e0ea034e08ef8d456c7bf5.zip
don't inline code, do __name__=="__main__" so the module can be used instead of strictly called.
svn path=/main/trunk/; revision=2560
-rwxr-xr-xbin/emaint95
1 files changed, 48 insertions, 47 deletions
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"