bh@5: # Copyright (C) 2007 by Intevation GmbH bh@5: # Authors: bh@5: # Bernhard Herzog bh@5: # bh@5: # This program is free software under the GPL (>=v2) bh@5: # Read the file COPYING coming with the software for details. bh@5: bh@5: import os bh@5: import logging bh@5: import shutil bh@5: import time bh@5: bh@5: import treepkg.packager bh@5: import treepkg.util bh@5: import treepkg.run as run bh@45: from treepkg.cmdexpand import cmdexpand bh@5: bh@5: bh@5: class SourcePackager(treepkg.packager.SourcePackager): bh@5: bh@5: """Creates the debian source package for the i18n files bh@5: bh@5: This is quite complicated. The orig.tar.gz file of the debian bh@5: source package contains one .tar.bz2 file for every language. Those bh@5: .tar.bz files are the kde-18n- files released by the KDE bh@5: project. For now, we only have the German localization in the bh@5: enterprise source package, so the orig.tar.gz file will have the bh@5: following contents: bh@5: bh@5: kde-i18n-/ bh@5: kde-i18n-/kde-i18n-de-.tar.bz2 bh@5: bh@5: is the same everywhere. bh@5: bh@5: The kde-i18n-de tarball contains the localization files for the bh@5: entire KDE project, including KDE-PIM. The SVN enterprise branch bh@5: only contains the localizations for KDE-PIM, though, so we have to bh@5: assemble a new .tar.bz2 from an original bh@5: kde-i18n-de-.tar.bz and the new files from the enterprise bh@5: branch. bh@5: """ bh@5: bh@5: pkg_basename = "kde-i18n" bh@5: bh@5: def determine_package_version(self, directory): bh@5: enterprise_version = (time.strftime("%Y%m%d", time.localtime()) \ bh@5: + "." + str(self.revision)) bh@5: kdepimversion = "3.5.5" bh@5: version_template = "%(kdepimversion)s.enterprise.0.%(enterprise_version)s" bh@5: return version_template % locals() bh@5: bh@5: def unpack_orig_tarball(self): bh@53: orig_tarball = self.track.orig_tarball bh@45: run.call(cmdexpand("tar xjf $tarball -C $directory", bh@45: tarball=orig_tarball, directory=self.work_dir)) bh@5: tarbasename = os.path.basename(orig_tarball) bh@5: splitext = os.path.splitext bh@5: return os.path.join(self.work_dir, bh@5: splitext(splitext(tarbasename)[0])[0]) bh@5: bh@5: def create_i18n_de_tarball(self, pkgbasedir, pkgbaseversion): bh@5: """Creates a new kde-i18n-de tarball and returns its filename bh@5: bh@5: This is the tarball as it would be released by KDE. It is not bh@5: yet the tarball that will become the .orig.tar.gz for the debian bh@5: package. bh@5: """ bh@5: logging.info("Creating kde-i18n-de tarball") bh@5: untarred_dir = self.unpack_orig_tarball() bh@5: new_de_dir = os.path.join(pkgbasedir, "new-de") bh@5: de_dir = os.path.join(pkgbasedir, "de") bh@5: os.rename(de_dir, new_de_dir) bh@5: treepkg.util.copytree(untarred_dir, de_dir) bh@5: treepkg.util.copytree(new_de_dir, de_dir) bh@5: logging.info("Running scripts/autogen.sh for kde-i18n-de tarball") bh@45: run.call(cmdexpand("/bin/sh scripts/autogen.sh de"), cwd=pkgbasedir, bh@5: suppress_output=True) bh@5: bh@5: tarballdir = "kde-i18n-de-" + pkgbaseversion bh@5: os.rename(de_dir, os.path.join(pkgbasedir, tarballdir)) bh@5: bh@5: tarball = os.path.join(os.path.dirname(pkgbasedir), bh@5: tarballdir + ".tar.bz2") bh@45: run.call(cmdexpand("tar cjf $tarball -C $pkgbasedir $tarballdir", bh@45: **locals())) bh@5: logging.info("Created kde-i18n-de tarball") bh@5: return tarball bh@5: bh@5: def do_package(self): bh@28: # Create a new kde-i18n-de tarball from current SVN and the base bh@28: # kde-i18n-de tarball. bh@5: pkgbaseversion, pkgbasedir = self.export_sources() bh@5: tarball = self.create_i18n_de_tarball(pkgbasedir, pkgbaseversion) bh@5: bh@28: # We have to reuse the same directory when building the bh@28: # orig.tar.gz. However, we need to preserver the scripts bh@28: # sub-directory because it's not needed for the kde-i18n-de bh@28: # tarball but for the .orig.tar.gz. bh@28: pkg_scripts_dir = os.path.join(pkgbasedir, "scripts") bh@28: tmp_scripts_dir = os.path.join(self.work_dir, "scripts") bh@28: os.rename(pkg_scripts_dir, tmp_scripts_dir) bh@5: shutil.rmtree(pkgbasedir) bh@5: os.mkdir(pkgbasedir) bh@28: os.rename(tmp_scripts_dir, pkg_scripts_dir) bh@5: bh@5: pkgbasename = self.pkg_basename + "_" + pkgbaseversion bh@5: origtargz = os.path.join(self.work_dir, bh@5: pkgbasename + ".orig.tar.gz") bh@5: os.rename(tarball, os.path.join(pkgbasedir, bh@5: os.path.basename(tarball))) bh@5: self.create_tarball(origtargz, self.work_dir, bh@5: os.path.basename(pkgbasedir)) bh@5: bh@5: changemsg = ("Update to SVN enterprise branch rev. %d" bh@5: % (self.revision,)) bh@5: self.copy_debian_directory(pkgbasedir, pkgbaseversion, bh@5: changemsg) bh@5: bh@5: self.create_source_package(pkgbasedir, origtargz) bh@5: self.move_source_package(pkgbasename) bh@5: bh@5: bh@5: class RevisionPackager(treepkg.packager.RevisionPackager): bh@5: bh@5: source_packager_cls = SourcePackager bh@5: bh@5: bh@52: class PackageTrack(treepkg.packager.PackageTrack): bh@5: bh@5: revision_packager_cls = RevisionPackager bh@5: bh@5: svn_external_subdirs = ["scripts", "scripts/admin"] bh@5: bh@5: extra_config_desc = ["orig_tarball"] bh@5: bh@5: def __init__(self, *args, **kw): bh@5: self.orig_tarball = kw.pop("orig_tarball") bh@52: super(PackageTrack, self).__init__(*args, **kw) bh@5: