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@271: import time bh@271: import logging bh@271: bh@271: import treepkg.packager bh@271: import treepkg.subversion bh@271: bh@271: bh@271: class BaseSourcePackager(treepkg.packager.SourcePackager): bh@271: bh@271: changemsg_template = None bh@271: bh@271: def __init__(self, *args, **kw): bh@271: super(BaseSourcePackager, self).__init__(*args, **kw) bh@271: self.enterprise_version = (time.strftime("%Y%m%d", time.localtime()) \ bh@271: + "." + 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@271: def do_package(self): bh@271: pkgbaseversion, pkgbasedir = self.export_sources() bh@271: self.update_version_numbers(pkgbasedir) bh@271: bh@271: pkgbasename = self.pkg_basename + "_" + pkgbaseversion bh@271: origtargz = os.path.join(self.work_dir, bh@271: pkgbasename + ".orig.tar.gz") bh@271: self.create_tarball(origtargz, self.work_dir, bh@271: os.path.basename(pkgbasedir)) bh@271: bh@271: changemsg = self.changemsg_template % dict(revision=self.revision) bh@271: self.copy_debian_directory(pkgbasedir, pkgbaseversion, bh@271: changemsg) bh@271: bh@271: self.create_source_package(pkgbasedir, origtargz) bh@271: self.move_source_package(pkgbasename) bh@271: bh@271: bh@271: class BasePackageTrack(treepkg.packager.PackageTrack): bh@271: 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@273: self.tag_detector = treepkg.subversion.TagDetector(tags_url, bh@273: tags_pattern, bh@273: 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@271: return self.revision_packager_cls(self, tag=tag_url, *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@271: self.export_tag(self.tag_url, to_dir) bh@271: else: bh@271: super(BasePackageTrack, self).export_sources(to_dir) bh@271: bh@271: def export_tag(self, tag_url, to_dir): bh@271: logging.info("Exporting sources from %s to %r", bh@271: tag_url, to_dir) bh@271: treepkg.subversion.export(tag_url, to_dir)