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