bh@271: # Copyright (C) 2007, 2008, 2009 by Intevation GmbH bh@271: # Authors: bh@271: # Bernhard Herzog bh@271: # bh@271: # This program is free software under the GPL (>=v2) bh@271: # Read the file COPYING coming with the software for details. bh@271: bh@271: """Base classes for all kdepim packagers""" bh@271: bh@271: import os bh@286: import re bh@271: import time bh@271: import logging bh@271: bh@271: import treepkg.packager bh@286: import treepkg.subversion as subversion bh@271: bh@271: bh@271: class BaseSourcePackager(treepkg.packager.SourcePackager): bh@271: aheinecke@335: changemsg_template = "Update to SVN enterprise35 branch rev. %(revision)s" bh@275: bh@271: def __init__(self, *args, **kw): bh@271: super(BaseSourcePackager, self).__init__(*args, **kw) bh@283: self.enterprise_version = (self.parent.pkg_date + "." bh@283: + str(self.revision)) bh@271: bh@271: def determine_package_version(self, directory): bh@271: enterprise_version = self.enterprise_version bh@271: return self.track.version_template % locals() bh@271: bh@276: def prepare_sources_for_tarball(self, pkgbasedir, pkgbaseversion): bh@271: self.update_version_numbers(pkgbasedir) bh@271: bh@274: def update_version_numbers(self, pkgbasedir): bh@274: """Updates the version numbers in the code in pkgbasedir. bh@274: The default implementation does nothing. Derived classes should bh@274: override this method if necessary. bh@274: """ bh@271: bh@271: bh@283: class BaseRevisionPackager(treepkg.packager.RevisionPackager): bh@283: bh@301: source_packager_cls = BaseSourcePackager bh@301: bh@283: def __init__(self, *args, **kw): bh@283: self.pkg_date = kw.pop("pkg_date", bh@283: time.strftime("%Y%m%d", time.localtime())) bh@283: super(BaseRevisionPackager, self).__init__(*args, **kw) bh@283: bh@283: bh@271: class BasePackageTrack(treepkg.packager.PackageTrack): bh@271: bh@309: revision_packager_cls = BaseRevisionPackager bh@309: bh@271: extra_config_desc = [("version_template", str, "%(enterprise_version)s"), bh@271: ("tags_url", str, ""), bh@271: ("tags_pattern", str, ""), bh@271: ("tags_subdir", str, "")] bh@271: bh@271: def __init__(self, *args, **kw): bh@271: self.version_template = kw.pop("version_template") bh@271: tags_url = kw.pop("tags_url") bh@271: tags_pattern = kw.pop("tags_pattern") bh@271: tags_subdir = kw.pop("tags_subdir") bh@271: super(BasePackageTrack, self).__init__(*args, **kw) bh@286: self.tag_detector = subversion.TagDetector(tags_url, tags_pattern, bh@286: tags_subdir) bh@271: bh@271: def packager_for_new_revision(self): bh@271: logging.info("Checking tags") bh@271: self.tag_url = None bh@271: tag_url, tag_revision = self.tag_detector.newest_tag_revision() bh@271: logging.info("Found: %s: %s", tag_url, tag_revision) bh@271: if tag_url is not None: bh@271: revision = (tag_revision, bh@271: self.rules_working_copy.last_changed_revision()) bh@271: logging.info("New revision is %s", revision) bh@271: if revision not in self.get_revision_numbers(): bh@271: logging.info("Revision %s has not been packaged yet", bh@271: revision) bh@271: self.tag_url = tag_url bh@280: self.tag_revision = tag_revision bh@286: tag_date, tag_change_count = self.tag_pkg_parameters(tag_url) bh@293: pkg_revision = (self.pkg_revision_template bh@293: % dict(pkg_revision=tag_change_count)) bh@286: return self.revision_packager_cls(self, tag=tag_url, bh@286: pkg_revision=pkg_revision, bh@286: pkg_date=tag_date, bh@286: *revision) bh@271: else: bh@271: logging.info("Revision %s has already been packaged.", bh@271: revision) bh@271: bh@271: return super(BasePackageTrack, self).packager_for_new_revision() bh@271: bh@271: def export_sources(self, to_dir): bh@271: if self.tag_url is not None: bh@280: self.export_tag(self.tag_url, to_dir, revision=self.tag_revision) bh@271: else: bh@271: super(BasePackageTrack, self).export_sources(to_dir) bh@271: bh@280: def export_tag(self, tag_url, to_dir, revision=None): bh@271: logging.info("Exporting sources from %s to %r", bh@271: tag_url, to_dir) bh@286: subversion.export(tag_url, to_dir, revision=revision) bh@286: bh@286: def tag_pkg_parameters(self, tag_url): bh@286: match = re.search(r"/enterprise[^.]*\.[^.]*\." bh@286: r"(?P[0-9]{8})\.(?P[0-9]+)/", bh@286: tag_url) bh@286: if match: bh@286: date = match.group("date") bh@286: baserev = int(match.group("baserev")) bh@286: xml_log = subversion.log_xml(tag_url, baserev) bh@286: revisions = subversion.extract_tag_revisions(xml_log) bh@286: tag_change_count = len(revisions) bh@286: return (date, tag_change_count) bh@286: else: bh@286: raise RuntimeError("Cannot determine tag parameters from %r" bh@286: % tag_url)