changeset 244:1aa624af9ebb

* Allowing specifying the main entry point of a module in `<python:exec>`. 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.
author cmlenz
date Mon, 03 Oct 2005 19:35:21 +0000
parents e75816cb2f45
children a22ec8fce6c9
files bitten/build/pythontools.py bitten/slave.py setup.py
diffstat 3 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- 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_,
--- 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']
             ],
         ]
--- 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
Copyright (C) 2012-2017 Edgewall Software