diff treepkg/packager.py @ 125:34e08d52956e

Make the import_packager_module function more flexible. The modules may now also define a RevisionPackager and a BinaryPackager. See the docstring for details of the new rules. Also add some more tests.
author Bernhard Herzog <bh@intevation.de>
date Thu, 22 May 2008 18:12:30 +0000
parents 312949e7628d
children 5155b4f9443d
line wrap: on
line diff
--- a/treepkg/packager.py	Thu May 22 12:44:43 2008 +0000
+++ b/treepkg/packager.py	Thu May 22 18:12:30 2008 +0000
@@ -400,17 +400,28 @@
     """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.
+    packager.  The function tries to find or create a suitable
+    PackageTrack class from this module using the following rules:
+
+      - If the module contains a class called PackageTrack, use that.
+
+      - Otherwise create one using the module's RevisionPackager class,
+        creating RevisionPackager if necessary.
+
+      - If RevisionPackager needs to be created, it uses the module's
+        SourcePackager as source_packager_cls and if present also the
+        module's BinaryPackager as binary_packager_cls.  If the module
+        does not have a BinaryPackager, the default BinaryPackager is
+        used.
     """
     module = util.import_dotted_name(packager_class)
     if not hasattr(module, "PackageTrack"):
-        module.RevisionPackager \
-            = new.classobj("RevisionPackager", (RevisionPackager,),
-                           dict(source_packager_cls=module.SourcePackager))
+        if not hasattr(module, "RevisionPackager"):
+            binary_packager = getattr(module, "BinaryPackager", BinaryPackager)
+            module.RevisionPackager \
+                = new.classobj("RevisionPackager", (RevisionPackager,),
+                               dict(source_packager_cls=module.SourcePackager,
+                                    binary_packager_cls=binary_packager))
         module.PackageTrack \
             = new.classobj("PackageTrack", (PackageTrack,),
                            dict(revision_packager_cls=module.RevisionPackager))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)