bh@271: # Copyright (C) 2007, 2008, 2009 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@271: import base bh@5: bh@277: class SourcePackager(base.BaseSourcePackager): 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 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@277: def prepare_sources_for_tarball(self, pkgbasedir, pkgbaseversion): bh@28: # We have to reuse the same directory when building the bh@277: # orig.tar.gz. However, we need to preserve 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@277: tarball = self.create_i18n_de_tarball(pkgbasedir, pkgbaseversion) 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: os.rename(tarball, os.path.join(pkgbasedir, bh@5: os.path.basename(tarball))) bh@5: bh@5: bh@284: class RevisionPackager(base.BaseRevisionPackager): bh@5: bh@5: source_packager_cls = SourcePackager bh@5: bh@5: bh@271: class PackageTrack(base.BasePackageTrack): bh@5: bh@5: revision_packager_cls = RevisionPackager bh@5: bh@101: svn_external_subdirs = ["scripts", "scripts/admin", "documentation/kdepim"] bh@5: bh@271: extra_config_desc = base.BasePackageTrack.extra_config_desc \ bh@271: + ["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: bh@106: def init_treepkg(self): bh@106: super(PackageTrack, self).init_treepkg() bh@106: if not os.path.exists(self.orig_tarball): bh@106: print ("TODO: The orig_tarball %s still has to be created" bh@106: % (self.orig_tarball,))