bh@134: # Copyright (C) 2008 by Intevation GmbH bh@134: # Authors: bh@134: # Bernhard Herzog bh@134: # bh@134: # This program is free software under the GPL (>=v2) bh@134: # Read the file COPYING coming with the software for details. bh@134: bh@134: """Recipe to build gnugp2 from SVN""" bh@134: bh@141: import os bh@141: import shutil bh@141: import logging bh@141: import re bh@141: bh@156: from genshi.template import TemplateLoader bh@156: bh@141: import treepkg.packager bh@141: import treepkg.util bh@156: import treepkg.report bh@141: bh@134: import base bh@134: base.define_gnupg_packager("gnupg2") bh@141: bh@141: bh@141: class BinaryPackager(treepkg.packager.BinaryPackager): bh@141: bh@141: pkits_log = treepkg.packager._fromparent("pkits_log") bh@141: bh@141: def package(self): bh@141: self.status.creating_binary_package() bh@141: treepkg.util.ensure_directory(self.binary_dir) bh@141: self.create_pkits_workdir() bh@141: try: bh@141: logging.info("Building binary package; logging to %r", self.logfile) bh@141: extra_env=dict(GNUPG_PKITS_DIRECTORY=self.pkits_workdir) bh@141: self.track.builder.build(self.dsc_file, self.binary_dir, self.logfile, bh@141: bindmounts=[self.pkits_workdir], bh@141: extra_packages=["bzip2"], bh@141: extra_env=extra_env) bh@141: self.extract_pkits_log() bh@141: finally: bh@141: self.remove_pkits_workdir() bh@141: self.status.binary_package_created() bh@141: bh@141: def create_pkits_workdir(self): bh@141: self.pkits_workdir = os.path.join(self.parent.base_dir, "pkits-work") bh@141: treepkg.util.ensure_directory(self.pkits_workdir) bh@141: shutil.copy(os.path.join(self.track.checkout_dir, "tests", "pkits", bh@141: "PKITS_data.tar.bz2"), bh@141: self.pkits_workdir) bh@141: bh@141: def remove_pkits_workdir(self): bh@141: shutil.rmtree(self.pkits_workdir) bh@141: bh@141: def extract_pkits_log(self): bh@141: testlog = None bh@141: for line in open(self.logfile): bh@141: if re.match("--------- END PKITS LOG ---------", line): bh@141: break bh@141: elif re.match("-------- BEGIN PKITS LOG --------", line): bh@141: testlog = [] bh@141: elif testlog is not None and line[:1] in "0123456789": bh@141: testlog.append(line) bh@141: else: bh@141: logging.info("Could not find PKITS LOG in %s", self.logfile) bh@141: return bh@141: treepkg.util.ensure_directory(os.path.dirname(self.pkits_log)) bh@156: treepkg.util.writefile(self.pkits_log, bh@157: self.htmlize_pkits_log(testlog), 0644) bh@156: bh@156: def htmlize_pkits_log(self, raw_lines): bh@156: loader = TemplateLoader([os.path.dirname(__file__)]) bh@156: template = loader.load("pkits.html") bh@156: pkits = treepkg.report.struct(revision=self.parent.revision, bh@156: lines=raw_lines) bh@156: stream = template.generate(pkits=pkits) bh@156: return stream.render('html') bh@141: bh@141: bh@141: class RevisionPackager(treepkg.packager.RevisionPackager): bh@141: bh@141: source_packager_cls = SourcePackager bh@141: binary_packager_cls = BinaryPackager bh@141: bh@175: pkits_log = treepkg.util.filenameproperty("pkits_log.html", bh@175: dir_attr="log_dir") bh@141: bh@141: def list_log_files(self): bh@141: files = super(RevisionPackager, self).list_log_files() bh@141: if os.path.exists(self.pkits_log): bh@141: files.append(("PKITS log", self.pkits_log)) bh@141: return files