bh@316: # Copyright (C) 2007, 2008, 2009 by Intevation GmbH
bh@316: # Authors:
bh@316: # Bernhard Herzog <bh@intevation.de>
bh@316: #
bh@316: # This program is free software under the GPL (>=v2)
bh@316: # Read the file COPYING coming with the software for details.
bh@316: 
bh@316: import os
bh@316: import logging
bh@316: import shutil
bh@316: import time
bh@316: 
bh@316: import treepkg.util
bh@316: 
bh@316: import recipes.kde.enterprise.generic as generic
bh@316: 
bh@316: 
bh@316: class SourcePackager(generic.SourcePackager):
bh@316: 
bh@316:     """Creates the debian source package for the l10n files
bh@316: 
bh@316:     This is a bit more complicated than for other packages.  The
bh@316:     orig.tar.gz file of the debian source package contains one .tar.bz2
bh@316:     file for every language.  Those .tar.bz files are the kde-18n-<lang>
bh@316:     files released by the KDE project.  For now, we only have the German
bh@316:     localization in the enterprise source package, so the orig.tar.gz
bh@316:     file will have the following contents:
bh@316: 
bh@316:       kde-l10n-<version>/
bh@316:       kde-l10n-<version>/kde-l10n-de-<version>.tar.bz2
bh@316: 
bh@316:     <version> is the same everywhere.
bh@316:     """
bh@316: 
bh@316:     createtarball_script = """\
bh@316: #! /bin/bash
bh@316: set -e
bh@316: 
bh@316: apt-get --assume-yes --force-yes install %(builddeps)s
bh@316: 
bh@316: # copy the source tree to a directory that's under pbuilder control so
bh@316: # that it gets removed along with the build environment.  Otherwise we
bh@316: # end up with a directory containing files that cannot be removed by
bh@316: # treepkg
bh@316: workdir=/tmp/work
bh@316: cp -a %(basedir)s $workdir
bh@316: cd $workdir
bh@316: 
bh@316: # only handle the de subdirectory
bh@316: echo de > subdirs
bh@316: 
bh@316: # create the CMakeFiles
bh@316: ./scripts/autogen.sh
bh@316: mv de kde-l10n-de-%(version)s
bh@316: tar cjf %(tarball)s kde-l10n-de-%(version)s
bh@316: """
bh@316: 
bh@316: 
bh@316:     def __init__(self, *args, **kw):
bh@316:         super(SourcePackager, self).__init__(*args, **kw)
bh@316:         self.enterprise_version = (time.strftime("%Y%m%d", time.localtime())
bh@316:                                    + "." + str(self.revision))
bh@316: 
bh@316:     def determine_package_version(self, directory):
bh@316:         enterprise_version = self.enterprise_version
bh@316:         return self.track.version_template % locals()
bh@316: 
bh@316:     def create_l10n_de_tarball(self, pkgbasedir, pkgbaseversion):
bh@316:         logging.info("Creating kde-l10n-de tarball")
bh@316:         de_tarball = os.path.join(self.work_dir,
bh@316:                                   "kde-l10n-de-" + pkgbaseversion + ".tar.bz2")
bh@316:         # xutils-dev is needed for the revpath script used by
bh@316:         # scripts/autogen.sh
bh@316:         script = (self.createtarball_script
bh@316:                   % dict(builddeps="xutils-dev",  tarball=de_tarball,
bh@316:                          basedir=pkgbasedir, version=pkgbaseversion))
bh@316:         script_name = os.path.join(self.work_dir, "createtarball")
bh@316:         treepkg.util.writefile(script_name, script, 0755)
bh@316:         treepkg.util.ensure_directory(self.src_dir)
bh@316:         treepkg.util.ensure_directory(self.log_dir)
bh@316:         self.track.builder.run_script([script_name],
bh@316:                                       logfile=os.path.join(self.log_dir,
bh@316:                                                            "tarball_log.txt"),
bh@316:                                       bindmounts=[self.work_dir])
bh@316:         return de_tarball
bh@316: 
bh@316:     def prepare_sources_for_tarball(self, pkgbasedir, pkgbaseversion):
bh@316:         de_tarball = self.create_l10n_de_tarball(pkgbasedir, pkgbaseversion)
bh@316:         shutil.rmtree(pkgbasedir)
bh@316:         os.mkdir(pkgbasedir)
bh@316:         os.rename(de_tarball,
bh@316:                   os.path.join(pkgbasedir, os.path.basename(de_tarball)))
bh@316: 
bh@316: 
bh@316: class RevisionPackager(generic.RevisionPackager):
bh@316: 
bh@316:     source_packager_cls = SourcePackager
bh@316: 
bh@316: 
bh@316: class PackageTrack(generic.PackageTrack):
bh@316: 
bh@316:     revision_packager_cls = RevisionPackager