Mercurial > hg > autobot
diff autobot/projects/__init__.py @ 59:e66165f2f31b
complete automagic imports
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 10 Jan 2011 22:40:18 -0800 |
parents | f586e28ff3d7 |
children | f8dccf3377d9 |
line wrap: on
line diff
--- a/autobot/projects/__init__.py Mon Jan 10 15:38:09 2011 -0800 +++ b/autobot/projects/__init__.py Mon Jan 10 22:40:18 2011 -0800 @@ -10,19 +10,33 @@ * autobot [TODO] """ +import imp import os - +from buildbot.process.factory import BuildFactory from logparser import TestLogParserFactory from mozmill import TestMozmillFactory -# TODO: import these automagically: -# requires non-zipped eggs + +# available factories:: +# import these automagically: requires non-zipped eggs +factories = {} +descriptions = {} here = os.path.dirname(os.path.abspath(__file__)) packages = [os.path.join(here, path) for path in os.listdir(here) if os.path.isdir(os.path.join(here, path))] -packages = [package for package in packages +packages = [os.path.basename(package) for package in packages if os.path.exists(os.path.join(package, '__init__.py'))] +for package in packages: + try: + module = imp.load_package('autobot.projects.'+package, imp.find_module(package, [here])[1]) + except: + continue + for attr in dir(module): + try: + _obj = getattr(module, attr) + if issubclass(_obj, BuildFactory) and _obj.__module__.startswith('autobot.projects.'): + factories[package] = _obj + descriptions[package] = (getattr(_obj, '__doc__', attr) or attr).strip() + except TypeError: + continue -# available factories -factories = {'logparser': TestLogParserFactory, - 'mozmill': TestMozmillFactory }