Mercurial > treepkg
changeset 494:31b64ebe4b42
determine upstream_version of a package
original patch by Andre
author | Bjoern Ricks <bricks@intevation.de> |
---|---|
date | Wed, 13 Oct 2010 16:26:53 +0000 |
parents | e075ce66e085 |
children | ca95be9d033a |
files | recipes/kde/enterprise/generic.py treepkg/packager.py treepkg/util.py |
diffstat | 3 files changed, 82 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/recipes/kde/enterprise/generic.py Sat Oct 02 10:09:05 2010 +0000 +++ b/recipes/kde/enterprise/generic.py Wed Oct 13 16:26:53 2010 +0000 @@ -24,13 +24,9 @@ + 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 self.track.version_template % locals() + return super(SourcePackager, self).determine_package_version( + directory, locals()) def prepare_sources_for_tarball(self, pkgbasedir, pkgbaseversion): self.update_version_numbers(pkgbasedir)
--- a/treepkg/packager.py Sat Oct 02 10:09:05 2010 +0000 +++ b/treepkg/packager.py Wed Oct 13 16:26:53 2010 +0000 @@ -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
--- a/treepkg/util.py Sat Oct 02 10:09:05 2010 +0000 +++ b/treepkg/util.py Wed Oct 13 16:26:53 2010 +0000 @@ -52,6 +52,37 @@ 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.