[Treepkg-commits] r454 - in trunk: recipes/kde/enterprise treepkg

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Oct 13 18:26:53 CEST 2010


Author: bricks
Date: 2010-10-13 18:26:53 +0200 (Wed, 13 Oct 2010)
New Revision: 454

Modified:
   trunk/recipes/kde/enterprise/generic.py
   trunk/treepkg/packager.py
   trunk/treepkg/util.py
Log:
determine upstream_version of a package
original patch by Andre


Modified: trunk/recipes/kde/enterprise/generic.py
===================================================================
--- trunk/recipes/kde/enterprise/generic.py	2010-10-02 10:09:05 UTC (rev 453)
+++ trunk/recipes/kde/enterprise/generic.py	2010-10-13 16:26:53 UTC (rev 454)
@@ -24,14 +24,10 @@
                                    + str(self.revision))
 
     def determine_package_version(self, directory):
-        revision = self.revision
-        rules_revision = self.parent.rules_revision
-        pkg_revision = self.parent.pkg_revision
-        pkg_date = self.parent.pkg_date
         enterprise_version = self.enterprise_version
+        return super(SourcePackager, self).determine_package_version(
+                directory, locals())
 
-        return self.track.version_template % locals()
-
     def prepare_sources_for_tarball(self, pkgbasedir, pkgbaseversion):
         self.update_version_numbers(pkgbasedir)
 

Modified: trunk/treepkg/packager.py
===================================================================
--- trunk/treepkg/packager.py	2010-10-02 10:09:05 UTC (rev 453)
+++ trunk/treepkg/packager.py	2010-10-13 16:26:53 UTC (rev 454)
@@ -50,21 +50,65 @@
     def __init__(self, parent):
         self.parent = parent
 
-    def determine_package_version(self, directory):
-        """Returns the version number of the new package as a string
+    def determine_upstream_version(self, directory)
+        """
+            Tries to parse the upstream version from a source directory
+            and returns it as a string.
+        """
+        # TODO: it should be possible to select which files should be searched
+        # for upstream_version
 
+        #if os.path.isfile(os.path.join(directory, "CMakeList.txt")):
+        #    return util.extract_cmakefile_version(os.path.join(directory,
+        #                                         "CMakeList.txt"))
+        if os.path.isfile(os.path.join(directory, "configure.ac")):
+            return util.extract_configureac_version(os.path.join(directory,
+                                                    "configure.ac"))
+        changelog = os.path.join(self.track.debian_dir, "changelog")
+        if os.path.isfile(changelog):
+            debian_version = util.debian_changelog_version(
+                                changelog)
+            # upstream version is debian version without epoch and
+            # debian revision
+            if ":" in debian_version:
+                debian_version = debian_version.split(":")[1]
+            if "-" in debian_version:
+                debian_version = debian_version.split("-")[0]
+            upstream_version = debian_version
+        else:
+            upstream_version = "0"
+
+        return upstream_version
+
+    def determine_package_version(self, directory, additionals=None):
+        """Returns the resolved version template of the package as a string
+
         The directory parameter is the name of the directory containing
         the newly exported sources.  The sources were exported with the
         export_sources method.
 
-        The default implementation simply returns the revision converted
-        to a string.
+        The addionals parameter may contain a dictionary with additional
+        variables used in the version template.
+
+        Default variables that can be resolved are:
+             revision - The revision of the package
+             rules_revision - The revision of the packaging rules
+             pkg_date - The current date in the form: YYYYMMDD
+             pkg_revision - The number of times a new package has
+                            been created from this track.
+             upstream_version - The version parsed from the sources or
+                                package descriptions by
+                                determine_upstream_version. Default: "0"
         """
         revision = self.revision
         rules_revision = self.parent.rules_revision
         pkg_revision = self.parent.pkg_revision
         pkg_date = time.strftime("%Y%m%d", time.localtime())
-        return self.track.version_template % locals()
+        upstream_version = determine_upstream_version(directory)
+        version_dict = locals().copy()
+        if type(additionals).__name__=='dict':
+            version_dict.update(additionals)
+        return self.track.version_template % version_dict
 
     def export_sources(self):
         """Export the sources from the subversion working directory

Modified: trunk/treepkg/util.py
===================================================================
--- trunk/treepkg/util.py	2010-10-02 10:09:05 UTC (rev 453)
+++ trunk/treepkg/util.py	2010-10-13 16:26:53 UTC (rev 454)
@@ -52,7 +52,38 @@
     output = run.capture_output(["dpkg-parsechangelog",  "-l" + changelog])
     return extract_value_for_key(output.splitlines(), "Version:")
 
+def extract_cmakefile_version(cmakelist):
+    """ Returns the version mentioned in a CMakeList.txt """
+    major = re.compile(r"VERSION_MAJOR\s+(\d+)", re.IGNORECASE)
+    minor = re.compile(r"VERSION_MINOR\s+(\d+)", re.IGNORECASE)
+    patch = re.compile(r"VERSION_PATCH\s+(\d+)", re.IGNORECASE)
+    version = ""
+    try:
+        for line in open(cmakelist):
+            major_match = major.match(line)
+            minor_match = minor.match(line)
+            patch_match = patch.match(line)
+        if major_match:
+            version = major_match.group(1)
+            if minor_match and version:
+                version += "." + minor_match.group(1)
+                if patch_match:
+                    version += "." + patch_match.group(1)
+    except: pass
+    finally:
+        return version
 
+def extract_configureac_version(configure_ac):
+    match = re.match(r"m4_define\(\[?my_version\]?, \[([^]]+)\]\)",
+                     line)
+    if match:
+        return match.group(1)
+
+    match = re.match(r"AC_INIT\([a-zA-Z_]+, ([0-9.]+)", line)
+    if match:
+        return match.group(1)
+    return ""
+
 def ensure_directory(directory):
     """Creates directory and all its parents.
 



More information about the Treepkg-commits mailing list