changeset 274:2676abfc0e1d

Refactoring: Implement do_package in treepkg.packager.SourcePackager. The actual implementation in the derived classes is almost identical in all cases so it's better to have as much of the implementation in the base class. The update_version_numbers method is not called directly by the base class code so is removed from the base class. OTOH, prepare_sources_for_tarball has been added as a more general variant of update_version_numbers that is actually called by the default implementation of do_package.
author Bernhard Herzog <bh@intevation.de>
date Thu, 07 May 2009 15:19:15 +0000
parents 4b700b39c32f
children c0cbd133b607
files recipes/kde_enterprise_3_5/base.py recipes/kde_enterprise_4/base.py treepkg/packager.py
diffstat 3 files changed, 39 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/recipes/kde_enterprise_3_5/base.py	Thu May 07 14:25:10 2009 +0000
+++ b/recipes/kde_enterprise_3_5/base.py	Thu May 07 15:19:15 2009 +0000
@@ -17,8 +17,6 @@
 
 class BaseSourcePackager(treepkg.packager.SourcePackager):
 
-    changemsg_template = None
-
     def __init__(self, *args, **kw):
         super(BaseSourcePackager, self).__init__(*args, **kw)
         self.enterprise_version = (time.strftime("%Y%m%d", time.localtime()) \
@@ -28,22 +26,14 @@
         enterprise_version = self.enterprise_version
         return self.track.version_template % locals()
 
-    def do_package(self):
-        pkgbaseversion, pkgbasedir = self.export_sources()
+    def prepare_sources_for_tarball(self, pkgbasedir):
         self.update_version_numbers(pkgbasedir)
 
-        pkgbasename = self.pkg_basename + "_" + pkgbaseversion
-        origtargz = os.path.join(self.work_dir,
-                                 pkgbasename + ".orig.tar.gz")
-        self.create_tarball(origtargz, self.work_dir,
-                            os.path.basename(pkgbasedir))
-
-        changemsg = self.changemsg_template % dict(revision=self.revision)
-        self.copy_debian_directory(pkgbasedir, pkgbaseversion,
-                                   changemsg)
-
-        self.create_source_package(pkgbasedir, origtargz)
-        self.move_source_package(pkgbasename)
+    def update_version_numbers(self, pkgbasedir):
+        """Updates the version numbers in the code in pkgbasedir.
+        The default implementation does nothing.  Derived classes should
+        override this method if necessary.
+        """
 
 
 class BasePackageTrack(treepkg.packager.PackageTrack):
--- a/recipes/kde_enterprise_4/base.py	Thu May 07 14:25:10 2009 +0000
+++ b/recipes/kde_enterprise_4/base.py	Thu May 07 15:19:15 2009 +0000
@@ -18,6 +18,8 @@
 
 class BaseSourcePackager(treepkg.packager.SourcePackager):
 
+    changemsg_template = "Update to SVN enterprise4 branch rev. %(revision)d"
+
     def __init__(self, *args, **kw):
         super(BaseSourcePackager, self).__init__(*args, **kw)
         self.enterprise_version = (time.strftime("%Y%m%d", time.localtime()) \
@@ -27,23 +29,14 @@
         enterprise_version = self.enterprise_version
         return self.track.version_template % locals()
 
-    def do_package(self):
-        pkgbaseversion, pkgbasedir = self.export_sources()
+    def prepare_sources_for_tarball(self, pkgbasedir):
         self.update_version_numbers(pkgbasedir)
 
-        pkgbasename = self.pkg_basename + "_" + pkgbaseversion
-        origtargz = os.path.join(self.work_dir,
-                                 pkgbasename + ".orig.tar.gz")
-        self.create_tarball(origtargz, self.work_dir,
-                            os.path.basename(pkgbasedir))
-
-        changemsg = ("Update to SVN enterprise4 branch rev. %d"
-                     % (self.revision,))
-        self.copy_debian_directory(pkgbasedir, pkgbaseversion,
-                                   changemsg)
-
-        self.create_source_package(pkgbasedir, origtargz)
-        self.move_source_package(pkgbasename)
+    def update_version_numbers(self, pkgbasedir):
+        """Updates the version numbers in the code in pkgbasedir.
+        The default implementation does nothing.  Derived classes should
+        override this method if necessary.
+        """
 
 
 class BasePackageTrack(treepkg.packager.PackageTrack):
--- a/treepkg/packager.py	Thu May 07 14:25:10 2009 +0000
+++ b/treepkg/packager.py	Thu May 07 15:19:15 2009 +0000
@@ -35,6 +35,10 @@
     # Derived classes must supply the package basename
     pkg_basename = None
 
+    # Derived classes may want to override this message
+    changemsg_template = "Update to revision %(revision)d"
+
+
     track = _fromparent("track")
     revision = _fromparent("revision")
     status = _fromparent("status")
@@ -80,11 +84,12 @@
         return pkgbaseversion, pkgbasedir
 
 
-    def update_version_numbers(self, pkgbasedir):
-        """Updates the version numbers in the code in pkgbasedir.
+    def prepare_sources_for_tarball(self, pkgbasedir):
+        """Prepare the exported sources prior to creating the tarball.
 
         The default implementation does nothing.  Derived classes should
-        override this method if necessary.
+        override this method if necessary to e.g. update the version
+        numbers in the code.
         """
 
     def create_tarball(self, tarballname, workdir, basedir, compression="gz"):
@@ -189,14 +194,24 @@
             shutil.rmtree(self.work_dir)
 
     def do_package(self):
-        """Does the work of creating a source package
-        This method must be overriden by derived classes.
+        """Does the work of creating a source package."""
+        pkgbaseversion, pkgbasedir = self.export_sources()
 
-        The method should do the work in self.work_dir.  When the
-        package is done, the source package files should be in
-        self.src_dir.
-        """
-        raise NotImplementedError
+        pkgbasename = self.pkg_basename + "_" + pkgbaseversion
+        origtargz = os.path.join(self.work_dir,
+                                 pkgbasename + ".orig.tar.gz")
+
+        self.prepare_sources_for_tarball(pkgbasedir)
+
+        self.create_tarball(origtargz, self.work_dir,
+                            os.path.basename(pkgbasedir))
+
+        changemsg = self.changemsg_template % dict(revision=self.revision)
+        self.copy_debian_directory(pkgbasedir, pkgbaseversion,
+                                   changemsg)
+
+        self.create_source_package(pkgbasedir, origtargz)
+        self.move_source_package(pkgbasename)
 
 
 class BinaryPackager(object):
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)