bh@216: # Copyright (C) 2007, 2008, 2009 by Intevation GmbH bh@216: # Authors: bh@216: # Bernhard Herzog bh@216: # bh@216: # This program is free software under the GPL (>=v2) bh@216: # Read the file COPYING coming with the software for details. bh@216: bh@216: """Base classes for all kdepim packagers""" bh@216: bh@216: import os bh@216: import time bh@216: import inspect bh@265: import logging bh@216: bh@216: import treepkg.packager bh@265: import treepkg.subversion bh@265: bh@265: bh@216: class BaseSourcePackager(treepkg.packager.SourcePackager): bh@216: bh@274: changemsg_template = "Update to SVN enterprise4 branch rev. %(revision)d" bh@274: bh@216: def __init__(self, *args, **kw): bh@216: super(BaseSourcePackager, self).__init__(*args, **kw) bh@216: self.enterprise_version = (time.strftime("%Y%m%d", time.localtime()) \ bh@216: + "." + str(self.revision)) bh@216: bh@216: def determine_package_version(self, directory): bh@216: enterprise_version = self.enterprise_version bh@216: return self.track.version_template % locals() bh@216: bh@274: def prepare_sources_for_tarball(self, pkgbasedir): bh@216: self.update_version_numbers(pkgbasedir) bh@216: 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@216: bh@216: bh@216: class BasePackageTrack(treepkg.packager.PackageTrack): bh@216: bh@265: extra_config_desc = ["version_template", bh@265: ("tags_url", str, ""), bh@265: ("tags_pattern", str, ""), bh@265: ("tags_subdir", str, "")] bh@216: bh@216: def __init__(self, *args, **kw): bh@216: self.version_template = kw.pop("version_template") bh@265: tags_url = kw.pop("tags_url") bh@265: tags_pattern = kw.pop("tags_pattern") bh@265: tags_subdir = kw.pop("tags_subdir") bh@216: super(BasePackageTrack, self).__init__(*args, **kw) bh@273: self.tag_detector = treepkg.subversion.TagDetector(tags_url, bh@273: tags_pattern, bh@273: tags_subdir) bh@265: bh@265: def packager_for_new_revision(self): bh@265: logging.info("Checking tags") bh@265: self.tag_url = None bh@265: tag_url, tag_revision = self.tag_detector.newest_tag_revision() bh@265: logging.info("Found: %s: %s", tag_url, tag_revision) bh@265: if tag_url is not None: bh@265: revision = (tag_revision, bh@265: self.rules_working_copy.last_changed_revision()) bh@265: logging.info("New revision is %s", revision) bh@265: if revision not in self.get_revision_numbers(): bh@265: logging.info("Revision %s has not been packaged yet", bh@265: revision) bh@265: self.tag_url = tag_url bh@265: return self.revision_packager_cls(self, tag=tag_url, *revision) bh@265: else: bh@265: logging.info("Revision %s has already been packaged.", bh@265: revision) bh@265: bh@265: return super(BasePackageTrack, self).packager_for_new_revision() bh@265: bh@265: def export_sources(self, to_dir): bh@265: if self.tag_url is not None: bh@267: self.export_tag(self.tag_url, to_dir) bh@265: else: bh@265: super(BasePackageTrack, self).export_sources(to_dir) bh@216: bh@267: def export_tag(self, tag_url, to_dir): bh@267: logging.info("Exporting sources from %s to %r", bh@267: tag_url, to_dir) bh@267: treepkg.subversion.export(tag_url, to_dir) bh@267: bh@216: bh@216: def define_kdepim_packager(basename=None, external_subdirs=None): bh@216: bh@216: caller_globals = inspect.currentframe().f_back.f_globals bh@216: bh@216: SourcePackager = caller_globals.get("SourcePackager") bh@216: if SourcePackager is None: bh@216: class SourcePackager(BaseSourcePackager): bh@216: pkg_basename = basename bh@216: bh@216: class RevisionPackager(treepkg.packager.RevisionPackager): bh@216: source_packager_cls = SourcePackager bh@216: bh@216: class PackageTrack(BasePackageTrack): bh@216: revision_packager_cls = RevisionPackager bh@216: bh@216: if external_subdirs is not None: bh@216: svn_external_subdirs = external_subdirs bh@216: bh@216: caller_globals["PackageTrack"] = PackageTrack