# HG changeset patch # User cmlenz # Date 1128368121 0 # Node ID 1aa624af9ebbd35f2fb31814b0c5f064d71e0f62 # Parent e75816cb2f452f850f5583ddcee5001e6eebee23 * Allowing specifying the main entry point of a module in ``. This can be used to execute Python scripts in modules that don't map to files on the file system. See #49. * Change namespace URI of xml tools from "x" to "xml". The namespace prefix should still be "x", though. * Fix mapping of slave version number to registration message. diff --git a/bitten/build/pythontools.py b/bitten/build/pythontools.py --- a/bitten/build/pythontools.py +++ b/bitten/build/pythontools.py @@ -55,21 +55,29 @@ if cmdline.returncode != 0: ctxt.error('distutils failed (%s)' % cmdline.returncode) -def exec_(ctxt, file_=None, module=None, output=None, args=None): +def exec_(ctxt, file_=None, module=None, function=None, output=None, args=None): """Execute a python script.""" assert file_ or module, 'Either "file" or "module" attribute required' + if function: + assert module and not file_, '"module" attribute required for use of ' \ + '"function" attribute' if module: - # Script specified as module name, need to resolve that to a file - try: - mod = __import__(module, globals(), locals(), []) - components = module.split('.') - for comp in components[1:]: - mod = getattr(mod, comp) - file_ = mod.__file__.replace('\\', '/') - except ImportError, e: - ctxt.error('Cannot execute Python module %s: %s' % (module, e)) - return + # Script specified as module name, need to resolve that to a file, + # or use the function name if provided + if function: + args = '-c "import sys; from %s import %s; %s(sys.argv)" %s' % ( + module, function, function, args) + else: + try: + mod = __import__(module, globals(), locals(), []) + components = module.split('.') + for comp in components[1:]: + mod = getattr(mod, comp) + file_ = mod.__file__.replace('\\', '/') + except ImportError, e: + ctxt.error('Cannot execute Python module %s: %s' % (module, e)) + return from bitten.build import shtools shtools.exec_(ctxt, executable=_python_path(ctxt), file_=file_, diff --git a/bitten/slave.py b/bitten/slave.py --- a/bitten/slave.py +++ b/bitten/slave.py @@ -84,7 +84,7 @@ self.config['machine'] ], xmlio.Element('os', family=self.config['family'], - version=self.config['release'])[ + version=self.config['version'])[ self.config['os'] ], ] diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -52,7 +52,7 @@ NS + 'python#pylint = bitten.build.pythontools:pylint', NS + 'python#trace = bitten.build.pythontools:trace', NS + 'python#unittest = bitten.build.pythontools:unittest', - NS + 'x#transform = bitten.build.xmltools:transform' + NS + 'xml#transform = bitten.build.xmltools:transform' ] }, test_suite='bitten.tests.suite', zip_safe=True