bh@315: # Copyright (C) 2007, 2008, 2009 by Intevation GmbH bh@315: # Authors: bh@315: # Bernhard Herzog bh@315: # bh@315: # This program is free software under the GPL (>=v2) bh@315: # Read the file COPYING coming with the software for details. bh@315: bh@315: import os bh@315: import logging bh@315: import shutil bh@315: bh@315: import treepkg.util bh@315: import treepkg.run as run bh@315: from treepkg.cmdexpand import cmdexpand bh@315: bh@315: import recipes.kde.enterprise.generic as generic bh@315: bh@315: bh@315: class SourcePackager(generic.SourcePackager): bh@315: bh@315: """Creates the debian source package for the i18n files bh@315: bh@315: This is quite complicated. The orig.tar.gz file of the debian bh@315: source package contains one .tar.bz2 file for every language. Those bh@315: .tar.bz files are the kde-18n- files released by the KDE bh@315: project. For now, we only have the German localization in the bh@315: enterprise source package, so the orig.tar.gz file will have the bh@315: following contents: bh@315: bh@315: kde-i18n-/ bh@315: kde-i18n-/kde-i18n-de-.tar.bz2 bh@315: bh@315: is the same everywhere. bh@315: bh@315: The kde-i18n-de tarball contains the localization files for the bh@315: entire KDE project, including KDE-PIM. The SVN enterprise branch bh@315: only contains the localizations for KDE-PIM, though, so we have to bh@315: assemble a new .tar.bz2 from an original bh@315: kde-i18n-de-.tar.bz and the new files from the enterprise bh@315: branch. bh@315: """ bh@315: bh@315: def unpack_orig_tarball(self): bh@315: orig_tarball = self.track.orig_tarball bh@315: run.call(cmdexpand("tar xjf $tarball -C $directory", bh@315: tarball=orig_tarball, directory=self.work_dir)) bh@315: tarbasename = os.path.basename(orig_tarball) bh@315: splitext = os.path.splitext bh@315: return os.path.join(self.work_dir, bh@315: splitext(splitext(tarbasename)[0])[0]) bh@315: bh@315: def create_i18n_de_tarball(self, pkgbasedir, pkgbaseversion): bh@315: """Creates a new kde-i18n-de tarball and returns its filename bh@315: bh@315: This is the tarball as it would be released by KDE. It is not bh@315: yet the tarball that will become the .orig.tar.gz for the debian bh@315: package. bh@315: """ bh@315: logging.info("Creating kde-i18n-de tarball") bh@315: untarred_dir = self.unpack_orig_tarball() bh@315: new_de_dir = os.path.join(pkgbasedir, "new-de") bh@315: de_dir = os.path.join(pkgbasedir, "de") bh@315: os.rename(de_dir, new_de_dir) bh@315: treepkg.util.copytree(untarred_dir, de_dir) bh@315: treepkg.util.copytree(new_de_dir, de_dir) bh@315: logging.info("Running scripts/autogen.sh for kde-i18n-de tarball") bh@315: run.call(cmdexpand("/bin/sh scripts/autogen.sh de"), cwd=pkgbasedir, bh@315: suppress_output=True) bh@315: bh@315: tarballdir = "kde-i18n-de-" + pkgbaseversion bh@315: os.rename(de_dir, os.path.join(pkgbasedir, tarballdir)) bh@315: bh@315: tarball = os.path.join(os.path.dirname(pkgbasedir), bh@315: tarballdir + ".tar.bz2") bh@315: run.call(cmdexpand("tar cjf $tarball -C $pkgbasedir $tarballdir", bh@315: **locals())) bh@315: logging.info("Created kde-i18n-de tarball") bh@315: return tarball bh@315: bh@315: def prepare_sources_for_tarball(self, pkgbasedir, pkgbaseversion): bh@315: # We have to reuse the same directory when building the bh@315: # orig.tar.gz. However, we need to preserve the scripts bh@315: # sub-directory because it's not needed for the kde-i18n-de bh@315: # tarball but for the .orig.tar.gz. bh@315: tarball = self.create_i18n_de_tarball(pkgbasedir, pkgbaseversion) bh@315: pkg_scripts_dir = os.path.join(pkgbasedir, "scripts") bh@315: tmp_scripts_dir = os.path.join(self.work_dir, "scripts") bh@315: os.rename(pkg_scripts_dir, tmp_scripts_dir) bh@315: shutil.rmtree(pkgbasedir) bh@315: os.mkdir(pkgbasedir) bh@315: os.rename(tmp_scripts_dir, pkg_scripts_dir) bh@315: os.rename(tarball, os.path.join(pkgbasedir, bh@315: os.path.basename(tarball))) bh@315: bh@315: bh@315: class RevisionPackager(generic.RevisionPackager): bh@315: bh@315: source_packager_cls = SourcePackager bh@315: bh@315: bh@315: class PackageTrack(generic.PackageTrack): bh@315: bh@315: revision_packager_cls = RevisionPackager bh@315: bh@315: extra_config_desc = generic.PackageTrack.extra_config_desc \ bh@315: + ["orig_tarball"] bh@315: bh@315: def __init__(self, *args, **kw): bh@315: self.orig_tarball = kw.pop("orig_tarball") bh@315: super(PackageTrack, self).__init__(*args, **kw) bh@315: bh@315: def init_treepkg(self): bh@315: super(PackageTrack, self).init_treepkg() bh@315: if not os.path.exists(self.orig_tarball): bh@315: print ("TODO: The orig_tarball %s still has to be created" bh@315: % (self.orig_tarball,))