[Treepkg-commits] r38 - in trunk: test treepkg
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Apr 1 14:30:40 CEST 2008
Author: bh
Date: 2008-04-01 14:30:39 +0200 (Tue, 01 Apr 2008)
New Revision: 38
Modified:
trunk/test/test_packager.py
trunk/treepkg/packager.py
Log:
Add a smarter way to load the packager modules: Add the function
treepkg.packager.import_packager_module and use it to load the packager
modules. Also add corresponding tests.
Modified: trunk/test/test_packager.py
===================================================================
--- trunk/test/test_packager.py 2008-03-20 20:21:34 UTC (rev 37)
+++ trunk/test/test_packager.py 2008-04-01 12:30:39 UTC (rev 38)
@@ -1,4 +1,4 @@
-# Copyright (C) 2007 by Intevation GmbH
+# Copyright (C) 2007, 2008 by Intevation GmbH
# Authors:
# Bernhard Herzog <bh at intevation.de>
#
@@ -14,7 +14,7 @@
from treepkg.run import call
from treepkg.cmdexpand import cmdexpand
from treepkg.util import writefile
-from treepkg.packager import PackagerGroup
+from treepkg.packager import PackagerGroup, import_packager_module
import treepkg.subversion as subversion
import treepkg
@@ -344,3 +344,32 @@
[os.path.join(srcdir, filename)
for filename in ["test_1.0-1_i386.changes",
"test_1.0-1_i386.deb"]])
+
+
+class TestImportPackagerModule(unittest.TestCase, FileTestMixin):
+
+ files = [("treepkg_importtest",
+ [("__init__.py", ""),
+ ("withtrack.py", "\n".join(["class PackageTrack:",
+ " pass",
+ ""])),
+ ("notrack.py", "\n".join(["class SourcePackager:",
+ " pass",
+ ""]))])]
+
+ def setUp(self):
+ self.directory = self.create_temp_dir(self.id())
+ self.create_files(self.directory, self.files)
+ self.old_path = sys.path
+ sys.path = [self.directory] + sys.path
+
+ def tearDown(self):
+ sys.path = self.old_path
+
+ def test_import_with_track(self):
+ module = import_packager_module("treepkg_importtest.withtrack")
+ self.failUnless(hasattr(module, "PackageTrack"))
+
+ def test_import_without_track(self):
+ module = import_packager_module("treepkg_importtest.notrack")
+ self.failUnless(hasattr(module, "PackageTrack"))
Modified: trunk/treepkg/packager.py
===================================================================
--- trunk/treepkg/packager.py 2008-03-20 20:21:34 UTC (rev 37)
+++ trunk/treepkg/packager.py 2008-04-01 12:30:39 UTC (rev 38)
@@ -13,6 +13,7 @@
import logging
import shutil
import datetime
+import new
import util
import subversion
@@ -395,8 +396,28 @@
for revision in self.get_revision_numbers()]
+def import_packager_module(packager_class):
+ """Import the packager module named by packager_class.
+
+ The packager_class must be the full absolute module name for the
+ packager. The module must either contain a class called
+ 'PackageTrack' or a class called called 'SourcePackager'. If it
+ doesn't have a 'PackageTrack' class, a 'PackageTrack' class and a
+ 'RevisionPackager' class will be created the latter of which will
+ use the module's 'SourcePackager' class as source_packager_cls.
+ """
+ module = util.import_dotted_name(packager_class)
+ if not hasattr(module, "PackageTrack"):
+ module.RevisionPackager \
+ = new.classobj("RevisionPackager", (RevisionPackager,),
+ dict(source_packager_cls=module.SourcePackager))
+ module.PackageTrack \
+ = new.classobj("PackageTrack", (PackageTrack,),
+ dict(revision_packager_cls=module.RevisionPackager))
+ return module
+
def create_package_track(packager_class, **kw):
- module = util.import_dotted_name(packager_class)
+ module = import_packager_module(packager_class)
return module.PackageTrack(**kw)
More information about the Treepkg-commits
mailing list