summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2015-08-18 11:29:46 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-08-19 18:05:48 +0100
commit5807ab32667a9f88f629c33f57c621e38fd3b910 (patch)
tree15578a63139bdc95f2155359b63926c1516b9cd0 /bitbake/lib
parent9b05ef581c73a06894b2970d97e897c59f9fc5b9 (diff)
downloadpoky-5807ab32667a9f88f629c33f57c621e38fd3b910.tar.gz
bitbake: lib/bb/main: consolidate UI/server extension listing and loading
Provide us with a means of showing the list of UIs / server choices for the command line help, and do the processing in one place for both. (Bitbake rev: 24035c1daad5a904c3372d21d44191ee8182338f) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rwxr-xr-xbitbake/lib/bb/main.py85
1 files changed, 54 insertions, 31 deletions
diff --git a/bitbake/lib/bb/main.py b/bitbake/lib/bb/main.py
index 4d77408f6a..c98cf444b0 100755
--- a/bitbake/lib/bb/main.py
+++ b/bitbake/lib/bb/main.py
@@ -41,22 +41,44 @@ logger = logging.getLogger("BitBake")
41class BBMainException(Exception): 41class BBMainException(Exception):
42 pass 42 pass
43 43
44def get_ui(config): 44def list_extension_modules(pkg, checkattr):
45 if not config.ui: 45 """
46 # modify 'ui' attribute because it is also read by cooker 46 Lists extension modules in a specific Python package
47 config.ui = os.environ.get('BITBAKE_UI', 'knotty') 47 (e.g. UIs, servers)
48 48 Parameters:
49 interface = config.ui 49 pkg: previously imported Python package to list
50 50 checkattr: attribute to look for in module to determine if it's valid
51 as the type of extension you are looking for
52 """
53 import pkgutil
54 pkgdir = os.path.dirname(pkg.__file__)
55
56 modules = []
57 for _, modulename, _ in pkgutil.iter_modules([pkgdir]):
58 if os.path.isdir(os.path.join(pkgdir, modulename)):
59 # ignore directories
60 continue
61 try:
62 module = __import__(pkg.__name__, fromlist=[modulename])
63 except (ImportError, SystemExit):
64 # If we can't import it, it's not valid
65 continue
66 module_if = getattr(module, modulename)
67 if getattr(module_if, 'hidden_extension', False):
68 continue
69 if not checkattr or hasattr(module_if, checkattr):
70 modules.append(modulename)
71 return modules
72
73def import_extension_module(pkg, modulename):
51 try: 74 try:
52 # Dynamically load the UI based on the ui name. Although we 75 # Dynamically load the UI based on the ui name. Although we
53 # suggest a fixed set this allows you to have flexibility in which 76 # suggest a fixed set this allows you to have flexibility in which
54 # ones are available. 77 # ones are available.
55 module = __import__("bb.ui", fromlist = [interface]) 78 module = __import__(pkg.__name__, fromlist = [modulename])
56 return getattr(module, interface) 79 return getattr(module, modulename)
57 except AttributeError: 80 except AttributeError:
58 raise BBMainException("FATAL: Invalid user interface '%s' specified.\n" 81 raise BBMainException("FATAL: Unable to import extension module %s from %s" % (modulename, pkg.__name__))
59 "Valid interfaces: depexp, goggle, ncurses, hob, knotty [default]." % interface)
60 82
61 83
62# Display bitbake/OE warnings via the BitBake.Warnings logger, ignoring others""" 84# Display bitbake/OE warnings via the BitBake.Warnings logger, ignoring others"""
@@ -146,11 +168,25 @@ class BitBakeConfigParameters(cookerdata.ConfigParameters):
146 parser.add_option("-P", "--profile", help = "Profile the command and save reports.", 168 parser.add_option("-P", "--profile", help = "Profile the command and save reports.",
147 action = "store_true", dest = "profile", default = False) 169 action = "store_true", dest = "profile", default = False)
148 170
149 parser.add_option("-u", "--ui", help = "The user interface to use (e.g. knotty, hob, depexp).", 171 def present_options(optionlist):
150 action = "store", dest = "ui") 172 if len(optionlist) > 1:
151 173 return ' or '.join([', '.join(optionlist[:-1]), optionlist[-1]])
152 parser.add_option("-t", "--servertype", help = "Choose which server to use, process or xmlrpc.", 174 else:
153 action = "store", dest = "servertype") 175 return optionlist[0]
176
177 env_ui = os.environ.get('BITBAKE_UI', None)
178 valid_uis = list_extension_modules(bb.ui, 'main')
179 default_ui = env_ui or 'knotty'
180 if env_ui and not env_ui in valid_uis:
181 raise BBMainException('Invalid UI "%s" specified in BITBAKE_UI environment variable - valid choices: %s' % (env_ui, present_options(valid_uis)))
182 elif not default_ui in valid_uis:
183 raise BBMainException('Default UI "%s" could not be found')
184 parser.add_option("-u", "--ui", help = "The user interface to use (%s - default %%default)." % present_options(valid_uis),
185 action="store", dest="ui", type="choice", choices=valid_uis, default=default_ui)
186
187 valid_server_types = list_extension_modules(bb.server, 'BitBakeServer')
188 parser.add_option("-t", "--servertype", help = "Choose which server type to use (%s - default %%default)." % present_options(valid_server_types),
189 action = "store", dest = "servertype", default = "process")
154 190
155 parser.add_option("", "--token", help = "Specify the connection token to be used when connecting to a remote server.", 191 parser.add_option("", "--token", help = "Specify the connection token to be used when connecting to a remote server.",
156 action = "store", dest = "xmlrpctoken") 192 action = "store", dest = "xmlrpctoken")
@@ -279,21 +315,8 @@ def bitbake_main(configParams, configuration):
279 315
280 configuration.setConfigParameters(configParams) 316 configuration.setConfigParameters(configParams)
281 317
282 ui_module = get_ui(configParams) 318 ui_module = import_extension_module(bb.ui, configParams.ui)
283 319 servermodule = import_extension_module(bb.server, configParams.servertype)
284 # Server type can be xmlrpc or process currently, if nothing is specified,
285 # the default server is process
286 if configParams.servertype:
287 server_type = configParams.servertype
288 else:
289 server_type = 'process'
290
291 try:
292 module = __import__("bb.server", fromlist = [server_type])
293 servermodule = getattr(module, server_type)
294 except AttributeError:
295 raise BBMainException("FATAL: Invalid server type '%s' specified.\n"
296 "Valid interfaces: xmlrpc, process [default]." % server_type)
297 320
298 if configParams.server_only: 321 if configParams.server_only:
299 if configParams.servertype != "xmlrpc": 322 if configParams.servertype != "xmlrpc":