# HG changeset patch # User cmlenz # Date 1119010258 0 # Node ID 07053ecfb1243ab1c1fb4b36dcc7ee86a5ec1f28 # Parent c668a9386194f8a7874ff17df0644bd4a35a151d Cleanup package namespace a bit. diff --git a/bitten/recipe/__init__.py b/bitten/build/__init__.py rename from bitten/recipe/__init__.py rename to bitten/build/__init__.py --- a/bitten/recipe/__init__.py +++ b/bitten/build/__init__.py @@ -17,5 +17,3 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # Author: Christopher Lenz - -from bitten.recipe.api import * \ No newline at end of file diff --git a/bitten/recipe/ctools.py b/bitten/build/ctools.py rename from bitten/recipe/ctools.py rename to bitten/build/ctools.py diff --git a/bitten/recipe/pythontools.py b/bitten/build/pythontools.py rename from bitten/recipe/pythontools.py rename to bitten/build/pythontools.py diff --git a/bitten/recipe.py b/bitten/recipe.py new file mode 100644 --- /dev/null +++ b/bitten/recipe.py @@ -0,0 +1,83 @@ +# -*- coding: iso8859-1 -*- +# +# Copyright (C) 2005 Christopher Lenz +# +# Bitten is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# Trac is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# Author: Christopher Lenz + +import os.path +from xml.dom import minidom + +from bitten import BuildError + +__all__ = ['Recipe'] + + +class Step(object): + """Represents a single step of a build recipe. + + Iterate over an object of this class to get the commands to execute, and + their keyword arguments. + """ + + def __init__(self, node): + self._node = node + self.id = node.getAttribute('id') + self.description = node.getAttribute('description') + + def __iter__(self): + for child in [c for c in self._node.childNodes if c.nodeType == 1]: + if child.namespaceURI: + # Commands + yield self._translate(child) + elif child.tagName == 'reports': + # Reports + for child in [c for c in child.childNodes if c.nodeType == 1]: + yield self._translate(child) + else: + raise BuildError, "Unknown element <%s>" % child.tagName + + def _translate(self, node): + if not node.namespaceURI.startswith('bitten:'): + # Ignore elements in a foreign namespace + return None + + module = __import__(node.namespaceURI[7:], globals(), locals(), + node.localName) + func = getattr(module, node.localName) + attrs = {} + for name, value in node.attributes.items(): + attrs[name.encode()] = value.encode() + return func, attrs + + +class Recipe(object): + """Represents a build recipe. + + Iterate over this object to get the individual build steps in the order they + have been defined in the recipe file.""" + + def __init__(self, filename='recipe.xml', basedir=os.getcwd()): + self.filename = filename + self.basedir = basedir + self.path = os.path.join(basedir, filename) + self.root = minidom.parse(self.path).documentElement + self.description = self.root.getAttribute('description') + + def __iter__(self): + """Provide an iterator over the individual steps of the recipe.""" + for child in self.root.getElementsByTagName('step'): + yield Step(child) diff --git a/bitten/recipe/api.py b/bitten/recipe/api.py deleted file mode 100644 --- a/bitten/recipe/api.py +++ /dev/null @@ -1,83 +0,0 @@ -# -*- coding: iso8859-1 -*- -# -# Copyright (C) 2005 Christopher Lenz -# -# Bitten is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# Trac is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# Author: Christopher Lenz - -import os.path -from xml.dom import minidom - -from bitten import BuildError - -__all__ = ['Recipe'] - - -class Step(object): - """Represents a single step of a build recipe. - - Iterate over an object of this class to get the commands to execute, and - their keyword arguments. - """ - - def __init__(self, node): - self._node = node - self.id = node.getAttribute('id') - self.description = node.getAttribute('description') - - def __iter__(self): - for child in [c for c in self._node.childNodes if c.nodeType == 1]: - if child.namespaceURI: - # Commands - yield self._translate(child) - elif child.tagName == 'reports': - # Reports - for child in [c for c in child.childNodes if c.nodeType == 1]: - yield self._translate(child) - else: - raise BuildError, "Unknown element <%s>" % child.tagName - - def _translate(self, node): - if not node.namespaceURI.startswith('bitten:'): - # Ignore elements in a foreign namespace - return None - - module = __import__(node.namespaceURI[7:], globals(), locals(), - node.localName) - func = getattr(module, node.localName) - attrs = {} - for name, value in node.attributes.items(): - attrs[name.encode()] = value.encode() - return func, attrs - - -class Recipe(object): - """Represents a build recipe. - - Iterate over this object to get the individual build steps in the order they - have been defined in the recipe file.""" - - def __init__(self, filename='recipe.xml', basedir=os.getcwd()): - self.filename = filename - self.basedir = basedir - self.path = os.path.join(basedir, filename) - self.root = minidom.parse(self.path).documentElement - self.description = self.root.getAttribute('description') - - def __iter__(self): - """Provide an iterator over the individual steps of the recipe.""" - for child in self.root.getElementsByTagName('step'): - yield Step(child) diff --git a/bitten/recipe/tests/__init__.py b/bitten/recipe/tests/__init__.py deleted file mode 100644 --- a/bitten/recipe/tests/__init__.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: iso8859-1 -*- -# -# Copyright (C) 2005 Christopher Lenz -# -# Bitten is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# Trac is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# Author: Christopher Lenz - -import unittest - -from bitten.recipe.tests import api - -def suite(): - suite = unittest.TestSuite() - suite.addTest(api.suite()) - return suite diff --git a/bitten/recipe/tests/api.py b/bitten/recipe/tests/api.py deleted file mode 100644 --- a/bitten/recipe/tests/api.py +++ /dev/null @@ -1,47 +0,0 @@ -# -*- coding: iso8859-1 -*- -# -# Copyright (C) 2005 Christopher Lenz -# -# Bitten is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# Trac is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# Author: Christopher Lenz - -import os -import os.path -import tempfile -import unittest - -from bitten.recipe import Recipe - - -class RecipeTestCase(unittest.TestCase): - - def setUp(self): - self.temp_dir = tempfile.gettempdir() - self.recipe_xml = open(os.path.join(self.temp_dir, 'recipe.xml'), 'w') - - def tearDown(self): - os.unlink(os.path.join(self.temp_dir, 'recipe.xml')) - - def testDescription(self): - self.recipe_xml.write('' - '' - '') - self.recipe_xml.close() - recipe = Recipe(basedir=self.temp_dir) - self.assertEqual('test', recipe.description) - -def suite(): - return unittest.makeSuite(RecipeTestCase, 'test') diff --git a/bitten/tests/__init__.py b/bitten/tests/__init__.py --- a/bitten/tests/__init__.py +++ b/bitten/tests/__init__.py @@ -20,7 +20,7 @@ import unittest -from bitten.recipe import tests as recipe +from bitten.tests import recipe from bitten.util import tests as util def suite(): diff --git a/bitten/tests/recipe.py b/bitten/tests/recipe.py new file mode 100644 --- /dev/null +++ b/bitten/tests/recipe.py @@ -0,0 +1,47 @@ +# -*- coding: iso8859-1 -*- +# +# Copyright (C) 2005 Christopher Lenz +# +# Bitten is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# Trac is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# Author: Christopher Lenz + +import os +import os.path +import tempfile +import unittest + +from bitten.recipe import Recipe + + +class RecipeTestCase(unittest.TestCase): + + def setUp(self): + self.temp_dir = tempfile.gettempdir() + self.recipe_xml = open(os.path.join(self.temp_dir, 'recipe.xml'), 'w') + + def tearDown(self): + os.unlink(os.path.join(self.temp_dir, 'recipe.xml')) + + def testDescription(self): + self.recipe_xml.write('' + '' + '') + self.recipe_xml.close() + recipe = Recipe(basedir=self.temp_dir) + self.assertEqual('test', recipe.description) + +def suite(): + return unittest.makeSuite(RecipeTestCase, 'test') diff --git a/recipe.xml b/recipe.xml --- a/recipe.xml +++ b/recipe.xml @@ -1,7 +1,7 @@ + xmlns:c="bitten:bitten.build.ctools" + xmlns:python="bitten:bitten.build.pythontools"> diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -25,6 +25,6 @@ from bitten.setuptools.testrunner import unittest setup(name='bitten', version=VERSION, - packages=['bitten', 'bitten.recipe', 'bitten.setuptools', 'bitten.util'], + packages=['bitten', 'bitten.build', 'bitten.setuptools', 'bitten.util'], author="Christopher Lenz", author_email="cmlenz@gmx.de", url="http://bitten.cmlenz.net/", cmdclass={'unittest': unittest})