[elbe-devel] [PATCH v2 27/28] Validation and report now use logging

dion at linutronix.de dion at linutronix.de
Fri Jun 21 19:40:19 CEST 2019


From: Olivier Dion <dion at linutronix.de>

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/commands/buildchroot.py |   2 +-
 elbepack/commands/hdimg.py       |   2 +-
 elbepack/commands/mkcdrom.py     |   3 +-
 elbepack/db.py                   |   2 +-
 elbepack/dump.py                 | 100 +++++++++----------
 elbepack/elbeproject.py          | 201 ++++++++++++++++++---------------------
 6 files changed, 140 insertions(+), 170 deletions(-)

diff --git a/elbepack/commands/buildchroot.py b/elbepack/commands/buildchroot.py
index 73eed1fc..cb8dd1a1 100644
--- a/elbepack/commands/buildchroot.py
+++ b/elbepack/commands/buildchroot.py
@@ -92,7 +92,7 @@ def run_command(argv):
     # Is opt.output necessary here?
     with eble_logging(opt.target):
         try:
-            project = ElbeProject(opt.target, args[0], opt.output, opt.name,
+            project = ElbeProject(opt.target, args[0], opt.name,
                                   opt.buildtype, opt.skip_validation)
         except ValidationError as e:
             print(str(e))
diff --git a/elbepack/commands/hdimg.py b/elbepack/commands/hdimg.py
index c673469a..4d41633e 100644
--- a/elbepack/commands/hdimg.py
+++ b/elbepack/commands/hdimg.py
@@ -70,7 +70,7 @@ def run_command(argv):
         try:
             project = ElbeProject(opt.target,
                                   override_buildtype=opt.buildtype,
-                                  xmlpath=args[0], logpath=opt.output,
+                                  xmlpath=args[0],
                                   skip_validate=opt.skip_validation)
         except ValidationError as e:
             print(str(e))
diff --git a/elbepack/commands/mkcdrom.py b/elbepack/commands/mkcdrom.py
index a8e9afad..abc9ce71 100644
--- a/elbepack/commands/mkcdrom.py
+++ b/elbepack/commands/mkcdrom.py
@@ -61,12 +61,13 @@ def run_command(argv):
         oparser.print_help()
         sys.exit(20)
 
+<<<<<<< HEAD
 
     with elbe_logging(opt.log):
 
         if not opt.rfs_only:
             try:
-                project = ElbeProject(args[0], logpath=opt.log,
+                project = ElbeProject(args[0],
                                       override_buildtype=opt.buildtype,
                                       skip_validate=opt.skip_validation)
             except ValidationError as e:
diff --git a/elbepack/db.py b/elbepack/db.py
index 7590329d..5722cc42 100644
--- a/elbepack/db.py
+++ b/elbepack/db.py
@@ -491,7 +491,7 @@ class ElbeDB(object):
                 p = s.query(Project). \
                     filter(Project.builddir == builddir).one()
 
-                return ElbeProject(p.builddir, name=p.name, logpath=logpath,
+                return ElbeProject(p.builddir, name=p.name,
                                    postbuild_file=postbuild_file,
                                    presh_file=presh_file,
                                    postsh_file=postsh_file,
diff --git a/elbepack/dump.py b/elbepack/dump.py
index 20b0bf4b..10df28e8 100644
--- a/elbepack/dump.py
+++ b/elbepack/dump.py
@@ -6,16 +6,20 @@
 # SPDX-License-Identifier: GPL-3.0-or-later
 
 import warnings
+import logging
+
 from datetime import datetime
 
 from apt import Cache
 
-from elbepack.asciidoclog import ASCIIDocLog
 from elbepack.finetuning import do_finetuning
 from elbepack.filesystem import hostfs
 from elbepack.version import elbe_version
 from elbepack.aptpkgutils import APTPackage
+from elbepack.shellhelper import do
 
+report = logging.getLogger("report")
+validation = logging.getLogger("validation")
 
 def get_initvm_pkglist():
     with warnings.catch_warnings():
@@ -73,15 +77,14 @@ def dump_initvmpkgs(xml):
         pass
 
 
-def check_full_pkgs(pkgs, fullpkgs, errorname, cache):
+def check_full_pkgs(pkgs, fullpkgs, cache):
 
     # pylint: disable=too-many-statements
     # pylint: disable=too-many-branches
 
-    elog = ASCIIDocLog(errorname, True)
 
-    elog.h1("ELBE Package validation")
-    elog.h2("Package List validation")
+    validation.info("ELBE Package validation")
+    validation.info("Package List validation")
 
     errors = 0
 
@@ -90,31 +93,31 @@ def check_full_pkgs(pkgs, fullpkgs, errorname, cache):
             name = p.et.text
             nomulti_name = name.split(":")[0]
             if not cache.has_pkg(nomulti_name):
-                elog.printo("- package %s does not exist" % nomulti_name)
+                validation.error("- package %s does not exist" % nomulti_name)
                 errors += 1
                 continue
 
             if not cache.is_installed(nomulti_name):
-                elog.printo("- package %s is not installed" % nomulti_name)
+                validation.error("- package %s is not installed" % nomulti_name)
                 errors += 1
                 continue
 
             ver = p.et.get('version')
             pkg = cache.get_pkg(nomulti_name)
             if ver and (pkg.installed_version != ver):
-                elog.printo(
+                validation.error(
                     "- package %s version %s does not match installed version %s" %
                     (name, ver, pkg.installed_version))
                 errors += 1
                 continue
 
     if errors == 0:
-        elog.printo("No Errors found")
+        validation.info("No Errors found")
 
     if not fullpkgs:
         return
 
-    elog.h2("Full Packagelist validation")
+    validation.info("Full Packagelist validation")
     errors = 0
 
     pindex = {}
@@ -126,95 +129,88 @@ def check_full_pkgs(pkgs, fullpkgs, errorname, cache):
         pindex[name] = p
 
         if not cache.has_pkg(name):
-            elog.printo("- package %s does not exist" % name)
+            validation.error("- package %s does not exist" % name)
             errors += 1
             continue
 
         if not cache.is_installed(name):
-            elog.printo("- package %s is not installed" % name)
+            validation.error("- package %s is not installed" % name)
             errors += 1
             continue
 
         pkg = cache.get_pkg(name)
 
         if pkg.installed_version != ver:
-            elog.printo(
+            validation.error(
                 "- package %s version %s does not match installed version %s" %
                 (name, ver, pkg.installed_version))
             errors += 1
             continue
 
         if pkg.installed_md5 != md5:
-            elog.printo("- package %s md5 %s does not match installed md5 %s" %
+            validation.error("- package %s md5 %s does not match installed md5 %s" %
                         (name, md5, pkg.installed_md5))
             errors += 1
 
     for cp in cache.get_installed_pkgs():
         if cp.name not in pindex:
-            elog.printo(
+            validation.error(
                 "additional package %s installed, that was not requested" %
                 cp.name)
             errors += 1
 
     if errors == 0:
-        elog.printo("No Errors found")
+        validation.info("No Errors found")
 
 
-def elbe_report(xml, buildenv, cache, reportname, errorname, targetfs):
+def elbe_report(xml, buildenv, cache, targetfs):
 
     # pylint: disable=too-many-arguments
     # pylint: disable=too-many-locals
     # pylint: disable=too-many-statements
     # pylint: disable=too-many-branches
 
-    outf = ASCIIDocLog(reportname)
     rfs = buildenv.rfs
 
-    outf.h1("ELBE Report for Project " + xml.text("project/name"))
+    report.info("ELBE Report for Project " + xml.text("project/name"))
 
-    outf.printo(
+    report.info(
         "report timestamp: " +
         datetime.now().strftime("%Y%m%d-%H%M%S"))
-    outf.printo("elbe: %s" % str(elbe_version))
+    report.info("elbe: %s" % str(elbe_version))
 
     slist = rfs.read_file('etc/apt/sources.list')
-    outf.h2("Apt Sources dump")
-    outf.verbatim_start()
-    outf.print_raw(slist)
-    outf.verbatim_end()
+    report.info("Apt Sources dump")
+    report.info(slist)
 
     try:
         prefs = rfs.read_file("etc/apt/preferences")
     except IOError:
         prefs = ""
 
-    outf.h2("Apt Preferences dump")
-    outf.verbatim_start()
-    outf.print_raw(prefs)
-    outf.verbatim_end()
+    report.info("Apt Preferences dump")
+    if prefs:
+        report.info(prefs)
 
-    outf.h2("Installed Packages List")
-    outf.table()
+    report.info("Installed Packages List")
 
     instpkgs = cache.get_installed_pkgs()
     for p in instpkgs:
-        outf.printo("|%s|%s|%s" % (p.name, p.installed_version, p.origin))
-    outf.table()
+        report.info("|%s|%s|%s" % (p.name, p.installed_version, p.origin))
 
     index = cache.get_fileindex()
     mt_index = targetfs.mtime_snap()
 
-    outf.h2("archive extract")
+    report.info("Archive extract")
 
     if xml.has("archive") and not xml.text("archive") is None:
         with xml.archive_tmpfile() as fp:
-            outf.do('tar xvfj "%s" -h -C "%s"' % (fp.name, targetfs.path))
+            do('tar xvfj "%s" -h -C "%s"' % (fp.name, targetfs.path))
         mt_index_postarch = targetfs.mtime_snap()
     else:
         mt_index_postarch = mt_index
 
-    outf.h2("finetuning log")
-    outf.verbatim_start()
+    report.info("Finetuning log")
 
     if xml.has("target/finetuning"):
         do_finetuning(xml, buildenv, targetfs)
@@ -222,10 +218,9 @@ def elbe_report(xml, buildenv, cache, reportname, errorname, targetfs):
     else:
         mt_index_post_fine = mt_index_postarch
 
-    outf.verbatim_end()
 
-    outf.h2("fileslist")
-    outf.table()
+
+    report.info("Fileslist")
 
     tgt_pkg_list = set()
 
@@ -250,23 +245,20 @@ def elbe_report(xml, buildenv, cache, reportname, errorname, targetfs):
                 pkg = "added in finetuning"
         # else leave pkg as is
 
-        outf.printo("|+%s+|%s" % (fpath, pkg))
+        report.info("|+%s+|%s" % (fpath, pkg))
 
-    outf.table()
 
-    outf.h2("Deleted Files")
-    outf.table()
+    report.info("Deleted Files")
     for fpath in list(mt_index.keys()):
         if fpath not in mt_index_post_fine:
             if fpath in index:
                 pkg = index[fpath]
             else:
                 pkg = "postinst generated"
-            outf.printo("|+%s+|%s" % (fpath, pkg))
-    outf.table()
+            report.info("|+%s+|%s" % (fpath, pkg))
+
+    report.info("Target Package List")
 
-    outf.h2("Target Package List")
-    outf.table()
     instpkgs = cache.get_installed_pkgs()
     pkgindex = {}
     for p in instpkgs:
@@ -277,7 +269,7 @@ def elbe_report(xml, buildenv, cache, reportname, errorname, targetfs):
         f = targetfs.open('etc/elbe_pkglist', 'w')
     for pkg in tgt_pkg_list:
         p = pkgindex[pkg]
-        outf.printo(
+        report.info(
             "|%s|%s|%s|%s" %
             (p.name,
              p.installed_version,
@@ -289,7 +281,6 @@ def elbe_report(xml, buildenv, cache, reportname, errorname, targetfs):
                 (p.name,
                  p.installed_version,
                  p.installed_md5))
-    outf.table()
 
     if xml.has("target/pkgversionlist"):
         f.close()
@@ -297,9 +288,8 @@ def elbe_report(xml, buildenv, cache, reportname, errorname, targetfs):
     if not xml.has("archive") or xml.text("archive") is None:
         return
 
-    elog = ASCIIDocLog(errorname, True)
 
-    elog.h1("Archive validation")
+    validation.info("Archive validation")
 
     errors = 0
 
@@ -307,15 +297,15 @@ def elbe_report(xml, buildenv, cache, reportname, errorname, targetfs):
         if fpath not in mt_index or \
                 mt_index_postarch[fpath] != mt_index[fpath]:
             if fpath not in mt_index_post_fine:
-                elog.printo(
+                validation.error(
                         "- archive file %s deleted in finetuning" %
                         fpath)
                 errors += 1
             elif mt_index_post_fine[fpath] != mt_index_postarch[fpath]:
-                elog.printo(
+                validation.error(
                         "- archive file %s modified in finetuning" %
                         fpath)
                 errors += 1
 
     if errors == 0:
-        elog.printo("No Errors found")
+        validation.info("No Errors found")
diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index cb08032d..64a2850e 100644
--- a/elbepack/elbeproject.py
+++ b/elbepack/elbeproject.py
@@ -12,9 +12,9 @@ import sys
 import os
 import datetime
 import io
+import logging
 
-from elbepack.asciidoclog import ASCIIDocLog, StdoutLog
-from elbepack.shellhelper import CommandError
+from elbepack.shellhelper import CommandError, do
 
 from elbepack.elbexml import (ElbeXML, NoInitvmNode,
                               ValidationError, ValidationMode)
@@ -39,6 +39,9 @@ from elbepack.templates import write_pack_template
 from elbepack.finetuning import do_prj_finetuning
 
 
+validation = logging.getLogger("validation")
+
+
 class IncompatibleArchitectureException(Exception):
     def __init__(self, oldarch, newarch):
         Exception.__init__(
@@ -116,7 +119,6 @@ class ElbeProject (object):
             self,
             builddir,
             xmlpath=None,
-            logpath=None,
             name=None,
             override_buildtype=None,
             skip_validate=False,
@@ -181,13 +183,6 @@ class ElbeProject (object):
         if not self.name:
             self.name = self.xml.text("project/name")
 
-        # If logpath is given, use an AsciiDocLog instance, otherwise log
-        # to stdout
-        if logpath:
-            self.log = ASCIIDocLog(logpath)
-        else:
-            self.log = StdoutLog()
-
         self.repo = ProjectRepo(self.arch, self.codename,
                                 os.path.join(self.builddir, "repo"))
 
@@ -211,13 +206,13 @@ class ElbeProject (object):
         # each time, because the pkglist including the -dev packages is
         # tracked nowhere.
         self.sysrootenv = None
-        self.log.do('rm -rf %s' % self.sysrootpath)
+        do('rm -rf %s' % self.sysrootpath)
 
         # same for host_sysroot instance recreate it in any case
         self.host_sysrootenv = None
 
     def build_chroottarball(self):
-        self.log.do("tar cJf %s/chroot.tar.xz \
+        do("tar cJf %s/chroot.tar.xz \
                 --exclude=./tmp/*  --exclude=./dev/* \
                 --exclude=./run/*  --exclude=./sys/* \
                 --exclude=./proc/* --exclude=./var/cache/* \
@@ -247,7 +242,7 @@ class ElbeProject (object):
 
     def build_sysroot(self):
 
-        self.log.do('rm -rf %s; mkdir "%s"' % (self.sysrootpath,
+        do('rm -rf %s; mkdir "%s"' % (self.sysrootpath,
                                                self.sysrootpath))
 
         self.sysrootenv = BuildEnv(self.xml,
@@ -255,7 +250,7 @@ class ElbeProject (object):
                                    clean=True)
         # Import keyring
         self.sysrootenv.import_keys()
-        self.log.printo("Keys imported")
+        logging.info("Keys imported")
 
         self.install_packages(self.sysrootenv, buildenv=False)
 
@@ -279,36 +274,36 @@ class ElbeProject (object):
                         env=self.sysrootenv).mark_install_devpkgs(
                                 set(ignore_pkgs), set(ignore_dev_pkgs))
             except SystemError as e:
-                self.log.printo("mark install devpkgs failed: %s" % str(e))
+                logging.exception("Mark install devpkgs failed")
             try:
                 self.get_rpcaptcache(env=self.sysrootenv).commit()
             except SystemError as e:
-                self.log.printo("commiting changes failed: %s" % str(e))
+                logging.exception("Commiting changes failed")
                 raise AptCacheCommitError(str(e))
 
         try:
             self.sysrootenv.rfs.dump_elbeversion(self.xml)
         except IOError:
-            self.log.printo("dump elbeversion into sysroot failed")
+            logging.exception("Dump elbeversion into sysroot failed")
 
         sysrootfilelist = os.path.join(self.builddir, "sysroot-filelist")
 
         with self.sysrootenv.rfs:
-            self.log.do("chroot %s /usr/bin/symlinks -cr /usr/lib" %
+            do("chroot %s /usr/bin/symlinks -cr /usr/lib" %
                         self.sysrootpath)
 
         paths = self.get_sysroot_paths()
 
-        self.log.do("rm %s" % sysrootfilelist, allow_fail=True)
+        do("rm %s" % sysrootfilelist, allow_fail=True)
         os.chdir(self.sysrootpath)
         for p in paths:
-            self.log.do('find -path "%s" >> %s' % (p, sysrootfilelist))
+            do('find -path "%s" >> %s' % (p, sysrootfilelist))
 
-        self.log.do("tar cfJ %s/sysroot.tar.xz -C %s -T %s" %
+        do("tar cfJ %s/sysroot.tar.xz -C %s -T %s" %
                     (self.builddir, self.sysrootpath, sysrootfilelist))
 
     def build_host_sysroot(self, pkgs, hostsysrootpath):
-        self.log.do('rm -rf %s; mkdir "%s"' % (hostsysrootpath,
+        do('rm -rf %s; mkdir "%s"' % (hostsysrootpath,
                                                hostsysrootpath))
 
         self.host_sysrootenv = BuildEnv(self.xml,
@@ -317,7 +312,7 @@ class ElbeProject (object):
                                         arch="amd64")
         # Import keyring
         self.host_sysrootenv.import_keys()
-        self.log.printo("Keys imported")
+        logging.info("Keys imported")
 
         with self.host_sysrootenv:
 
@@ -333,15 +328,14 @@ class ElbeProject (object):
                 try:
                     cache.mark_install(p, None)
                 except KeyError:
-                    self.log.printo("No Package " + p)
+                    logging.exception("No Package %s", p)
                 except SystemError as e:
-                    self.log.printo("Error: Unable to correct problems "
-                                    "in package %s (%s)" % (p, str(e)))
+                    logging.exception("Error: Unable to correct problems in package %s", p)
 
             try:
                 cache.commit()
             except SystemError as e:
-                self.log.printo("commiting changes failed: %s" % str(e))
+                logging.exception("Commiting changes failed")
                 raise AptCacheCommitError(str(e))
 
         # This is just a sysroot, some directories
@@ -382,8 +376,8 @@ class ElbeProject (object):
         # build target sysroot including libs and headers for the target
         self.build_sysroot()
         sdktargetpath = os.path.join(self.sdkpath, "sysroots", "target")
-        self.log.do("mkdir -p %s" % sdktargetpath)
-        self.log.do("tar xJf %s/sysroot.tar.xz -C %s" % (self.builddir,
+        do("mkdir -p %s" % sdktargetpath)
+        do("tar xJf %s/sysroot.tar.xz -C %s" % (self.builddir,
                                                          sdktargetpath))
         # build host sysroot including cross compiler
         hostsysrootpath = os.path.join(self.sdkpath, 'sysroots', 'host')
@@ -398,30 +392,30 @@ class ElbeProject (object):
                             self.sdkpath)
 
         # create sdk tar and append it to setup script
-        self.log.do("cd %s; tar cJf ../sdk.txz ." % self.sdkpath)
-        self.log.do("cd %s; rm -rf sdk" % self.builddir)
-        self.log.do("cd %s; cat sdk.txz >> %s" % (self.builddir, n))
-        self.log.do("cd %s; chmod +x %s" % (self.builddir, n))
-        self.log.do("cd %s; rm sdk.txz" % self.builddir)
+        do("cd %s; tar cJf ../sdk.txz ." % self.sdkpath)
+        do("cd %s; rm -rf sdk" % self.builddir)
+        do("cd %s; cat sdk.txz >> %s" % (self.builddir, n))
+        do("cd %s; chmod +x %s" % (self.builddir, n))
+        do("cd %s; rm sdk.txz" % self.builddir)
 
     def pbuild(self, p):
         self.pdebuild_init()
         src_path = os.path.join(self.builddir, "pdebuilder", "current")
 
         src_uri = p.text('.').replace("LOCALMACHINE", "10.0.2.2").strip()
-        self.log.printo("retrieve pbuild sources: %s" % src_uri)
+        logging.info("Retrieve pbuild sources: %s" % src_uri)
         if p.tag == 'git':
-            self.log.do("git clone %s %s" % (src_uri, src_path))
+            do("git clone %s %s" % (src_uri, src_path))
             try:
-                self.log.do(
+                do(
                     "cd %s; git reset --hard %s" %
                     (src_path, p.et.attrib['revision']))
             except IndexError:
                 pass
         elif p.tag == 'svn':
-            self.log.do("svn co --non-interactive %s %s" % (src_uri, src_path))
+            do("svn co --non-interactive %s %s" % (src_uri, src_path))
         else:
-            self.log.printo("unknown pbuild source vcs: %s" % p.tag)
+            logging.info("Unknown pbuild source vcs: %s" % p.tag)
 
         # pdebuild_build(-1) means use all cpus
         self.pdebuild_build(cpuset=-1, profile="")
@@ -430,8 +424,6 @@ class ElbeProject (object):
                      build_sources=False, cdrom_size=None):
         self.repo_images = []
 
-        elog = ASCIIDocLog(self.validationpath, True)
-
         env = None
         sysrootstr = ""
         if os.path.exists(self.sysrootpath):
@@ -454,7 +446,7 @@ class ElbeProject (object):
             init_codename = self.xml.get_initvm_codename()
 
             if build_bin:
-                elog.h1("Binary CD %s" % sysrootstr)
+                validation.info("Binary CD %s" % sysrootstr)
 
                 self.repo_images += mk_binary_cdrom(env.rfs,
                                                     self.arch,
@@ -464,7 +456,7 @@ class ElbeProject (object):
                                                     self.builddir,
                                                     cdrom_size=cdrom_size)
             if build_sources:
-                elog.h1("Source CD %s" % sysrootstr)
+                validation.info("Source CD %s" % sysrootstr)
                 try:
                     self.repo_images += mk_source_cdrom(env.rfs,
                                                         self.arch,
@@ -475,7 +467,7 @@ class ElbeProject (object):
                                                         xml=self.xml)
                 except SystemError as e:
                     # e.g. no deb-src urls specified
-                    elog.printo(str(e))
+                    validation.exception(str(e))
 
     def build(self, build_bin=False, build_sources=False, cdrom_size=None,
               skip_pkglist=False, skip_pbuild=False):
@@ -516,14 +508,14 @@ class ElbeProject (object):
         # However, if its not a full_buildenv, we specify clean here,
         # so it gets rebuilt properly.
         if not self.has_full_buildenv():
-            self.log.do('mkdir -p "%s"' % self.chrootpath)
+            do('mkdir -p "%s"' % self.chrootpath)
             self.buildenv = BuildEnv(self.xml, self.chrootpath,
                                      build_sources=build_sources, clean=True)
             skip_pkglist = False
 
         # Import keyring
         self.buildenv.import_keys()
-        self.log.printo("Keys imported")
+        logging.info("Keys imported")
 
         # Install packages
         if not skip_pkglist:
@@ -532,7 +524,7 @@ class ElbeProject (object):
         try:
             self.buildenv.rfs.dump_elbeversion(self.xml)
         except IOError:
-            self.log.printo("dump elbeversion failed")
+            logging.exception("Dump elbeversion failed")
 
         # Extract target FS. We always create a new instance here with
         # clean=true, because we want a pristine directory.
@@ -542,21 +534,14 @@ class ElbeProject (object):
         extract_target(self.buildenv.rfs, self.xml, self.targetfs,
                        self.get_rpcaptcache())
 
-        # The validation file is created using check_full_pkgs() and
-        # elbe_report(), both opening the file in append mode. So if an
-        # old validation file already exists, it must be deleted first.
-        if os.path.isfile(self.validationpath):
-            os.unlink(self.validationpath)
-
         # Package validation and package list
         if not skip_pkglist:
             pkgs = self.xml.xml.node("/target/pkg-list")
             if self.xml.has("fullpkgs"):
                 check_full_pkgs(pkgs, self.xml.xml.node("/fullpkgs"),
-                                self.validationpath, self.get_rpcaptcache())
-            else:
-                check_full_pkgs(pkgs, None, self.validationpath,
                                 self.get_rpcaptcache())
+            else:
+                check_full_pkgs(pkgs, None, self.get_rpcaptcache())
             dump_fullpkgs(self.xml, self.buildenv.rfs, self.get_rpcaptcache())
 
             self.xml.dump_elbe_version()
@@ -567,7 +552,7 @@ class ElbeProject (object):
         try:
             self.targetfs.dump_elbeversion(self.xml)
         except MemoryError:
-            self.log.printo("dump elbeversion failed")
+            logging.exception("Dump elbeversion failed")
 
         # install packages for buildenv
         if not skip_pkglist:
@@ -578,12 +563,11 @@ class ElbeProject (object):
             sourcexmlpath = os.path.join(self.builddir, "source.xml")
             self.xml.xml.write(sourcexmlpath)
         except MemoryError:
-            self.log.printo("write source.xml failed (archive to huge?)")
+            logging.exception("Write source.xml failed (archive to huge?)")
 
         # Elbe report
-        reportpath = os.path.join(self.builddir, "elbe-report.txt")
         elbe_report(self.xml, self.buildenv, self.get_rpcaptcache(),
-                    reportpath, self.validationpath, self.targetfs)
+                    self.targetfs)
 
         # the current license code raises an exception that interrupts the hole
         # build if a licence can't be converted to utf-8. Exception handling
@@ -599,8 +583,7 @@ class ElbeProject (object):
             self.buildenv.rfs.write_licenses(f,
                                              os.path.join(self.builddir, "licence.xml"))
         except Exception:
-            self.log.printo("error during generating licence.txt/xml")
-            self.log.printo(sys.exc_info()[0])
+            logging.exception("Error during generating licence.txt/xml")
             lic_err = True
         finally:
             f.close()
@@ -626,12 +609,12 @@ class ElbeProject (object):
             grub_version = 202
             grub_fw_type = "efi"
         elif self.get_rpcaptcache().is_installed('grub-legacy'):
-            self.log.printo("package grub-legacy is installed, "
+            logging.warning("package grub-legacy is installed, "
                             "this is obsolete, skipping grub")
             grub_version = 0
             grub_fw_type = ""
         else:
-            self.log.printo("package grub-pc is not installed, skipping grub")
+            logging.warning("package grub-pc is not installed, skipping grub")
             # version 0 == skip_grub
             grub_version = 0
             grub_fw_type = ""
@@ -640,8 +623,8 @@ class ElbeProject (object):
         self.build_cdroms(build_bin, build_sources, cdrom_size)
 
         if self.postbuild_file:
-            self.log.h2("postbuild script:")
-            self.log.do(self.postbuild_file + ' "%s %s %s"' % (
+            logging.info("Postbuild script")
+            do(self.postbuild_file + ' "%s %s %s"' % (
                 self.builddir,
                 self.xml.text("project/version"),
                 self.xml.text("project/name")),
@@ -658,27 +641,27 @@ class ElbeProject (object):
 
     def pdebuild_init(self):
         # Remove pdebuilder directory, containing last build results
-        self.log.do('rm -rf "%s"' % os.path.join(self.builddir,
+        do('rm -rf "%s"' % os.path.join(self.builddir,
                                                  "pdebuilder"))
 
         # Remove pbuilder/result directory
-        self.log.do('rm -rf "%s"' % os.path.join(self.builddir,
+        do('rm -rf "%s"' % os.path.join(self.builddir,
                                                  "pbuilder", "result"))
 
         # Recreate the directories removed
-        self.log.do('mkdir -p "%s"' % os.path.join(self.builddir,
+        do('mkdir -p "%s"' % os.path.join(self.builddir,
                                                    "pbuilder", "result"))
 
     def pdebuild(self, cpuset, profile):
         self.pdebuild_init()
 
         pbdir = os.path.join(self.builddir, "pdebuilder", "current")
-        self.log.do('mkdir -p "%s"' % os.path.join(pbdir))
+        do('mkdir -p "%s"' % os.path.join(pbdir))
 
         try:
             for orig_fname in self.orig_files:
                 ofname = os.path.join(self.builddir, orig_fname)
-                self.log.do('mv "%s" "%s"' % (ofname,
+                do('mv "%s" "%s"' % (ofname,
                                               os.path.join(self.builddir,
                                                            "pdebuilder")))
         finally:
@@ -686,7 +669,7 @@ class ElbeProject (object):
             self.orig_files = []
 
         # Untar current_pdebuild.tar.gz into pdebuilder/current
-        self.log.do(
+        do(
             'tar xfz "%s" -C "%s"' %
             (os.path.join(
                 self.builddir,
@@ -708,7 +691,7 @@ class ElbeProject (object):
             cpuset_cmd = ''
 
         try:
-            self.log.do('cd "%s"; %s pdebuild --debbuildopts "-j%s -sa" '
+            do('cd "%s"; %s pdebuild --debbuildopts "-j%s -sa" '
                         '--configfile "%s" '
                         '--use-pdebuild-internal --buildresult "%s"' % (
                             os.path.join(self.builddir,
@@ -729,13 +712,12 @@ class ElbeProject (object):
             self.repo.include(os.path.join(self.builddir,
                                            "pbuilder", "result", "*.changes"))
         except CommandError:
-            self.log.printo('')
-            self.log.printo('Package fails to build.')
-            self.log.printo('Please make sure, that the submitted package '
-                            'builds in pbuilder')
+            logging.exception("Package fails to build.\n"
+                              "Please make sure, that the submited package "
+                              "builds in pbuilder")
 
     def update_pbuilder(self):
-        self.log.do(
+        do(
             'pbuilder --update --configfile "%s" --aptconfdir "%s"' %
             (os.path.join(
                 self.builddir, "pbuilderrc"), os.path.join(
@@ -743,22 +725,22 @@ class ElbeProject (object):
 
     def create_pbuilder(self):
         # Remove old pbuilder directory, if it exists
-        self.log.do('rm -rf "%s"' % os.path.join(self.builddir, "pbuilder"))
+        do('rm -rf "%s"' % os.path.join(self.builddir, "pbuilder"))
 
         # make hooks.d and pbuilder directory
-        self.log.do(
+        do(
             'mkdir -p "%s"' %
             os.path.join(
                 self.builddir,
                 "pbuilder",
                 "hooks.d"))
-        self.log.do(
+        do(
             'mkdir -p "%s"' %
             os.path.join(
                 self.builddir,
                 "pbuilder",
                 "aptcache"))
-        self.log.do(
+        do(
             'mkdir -p "%s"' %
             os.path.join(
                 self.builddir,
@@ -769,7 +751,7 @@ class ElbeProject (object):
         pbuilder_write_config(self.builddir, self.xml)
         pbuilder_write_apt_conf(self.builddir, self.xml)
         pbuilder_write_repo_hook(self.builddir, self.xml)
-        self.log.do(
+        do(
             'chmod -R 755 "%s"' %
             os.path.join(
                 self.builddir,
@@ -777,7 +759,7 @@ class ElbeProject (object):
                 "hooks.d"))
 
         # Run pbuilder --create
-        self.log.do('pbuilder --create --configfile "%s" --aptconfdir "%s" '
+        do('pbuilder --create --configfile "%s" --aptconfdir "%s" '
                     '--debootstrapopts --include="git gnupg2"' % (
                         os.path.join(self.builddir, "pbuilderrc"),
                         os.path.join(self.builddir, "aptconfdir")))
@@ -787,7 +769,7 @@ class ElbeProject (object):
             sourcexmlpath = os.path.join(self.builddir, "source.xml")
             self.xml.xml.write(sourcexmlpath)
         except MemoryError:
-            self.log.printo("write source.xml failed (archive to huge?)")
+            logging.exception("write source.xml failed (archive to huge?)")
 
     def get_rpcaptcache(self, env=None, norecommend=None):
         if not env:
@@ -820,7 +802,7 @@ class ElbeProject (object):
             if os.path.isfile(elbeversionpath):
                 return True
 
-            self.log.printo("%s exists, but it does not have "
+            logging.warning("%s exists, but it does not have "
                             "an etc/elbe_version file." % self.chrootpath)
             # Apparently we do not have a functional build environment
             return False
@@ -850,7 +832,7 @@ class ElbeProject (object):
         # each time, because the pkglist including the -dev packages is
         # tracked nowhere.
         self.sysrootenv = None
-        self.log.do('rm -rf %s' % self.sysrootpath)
+        do('rm -rf %s' % self.sysrootpath)
 
         self.xml = newxml
 
@@ -871,11 +853,11 @@ class ElbeProject (object):
 
     def write_log_header(self):
         if self.name:
-            self.log.h1("ELBE Report for Project " + self.name)
+            logging.info("ELBE Report for Project " + self.name)
         else:
-            self.log.h1("ELBE Report")
-        self.log.printo("report timestamp: " +
-                        datetime.datetime.now().strftime("%Y%m%d-%H%M%S"))
+            logging.info("ELBE Report")
+            logging.info("report timestamp: " +
+                         datetime.datetime.now().strftime("%Y%m%d-%H%M%S"))
 
     def install_packages(self, target, buildenv=False):
 
@@ -897,23 +879,21 @@ class ElbeProject (object):
                     dump_initvmpkgs(self.xml)
                 target.need_dumpdebootstrap = False
                 source = self.xml
+                source_path = "/var/cache/elbe/source.xml"
                 try:
-                    initxml = ElbeXML(
-                        "/var/cache/elbe/source.xml",
-                        skip_validate=self.skip_validate,
-                        url_validation=ValidationMode.NO_CHECK)
+                    initxml = ElbeXML(source_path,
+                                      skip_validate=self.skip_validate,
+                                      url_validation=ValidationMode.NO_CHECK)
                     self.xml.get_initvmnode_from(initxml)
-                except ValidationError as e:
-                    self.log.printo(
-                        "/var/cache/elbe/source.xml validation failed")
-                    self.log.printo(str(e))
-                    self.log.printo("will not copy initvm node")
+                except ValidationError:
+                    logging.exception("%s validation failed.  "
+                                      "Will not copy initvm node", source_path)
                 except IOError:
-                    self.log.printo("/var/cache/elbe/source.xml not available")
-                    self.log.printo("can not copy initvm node")
+                    logging.exception("%s not available.  "
+                                      "Can not copy initvm node", source_path)
                 except NoInitvmNode:
-                    self.log.printo("/var/cache/elbe/source.xml is available")
-                    self.log.printo("But it does not contain an initvm node")
+                    logging.exception("%s is available.  But it does not "
+                                      "contain an initvm node", source_path)
             else:
                 sourcepath = os.path.join(self.builddir, "source.xml")
                 source = ElbeXML(sourcepath,
@@ -925,8 +905,8 @@ class ElbeProject (object):
                 try:
                     self.xml.get_initvmnode_from(source)
                 except NoInitvmNode:
-                    self.log.printo("source.xml is available")
-                    self.log.printo("But it does not contain an initvm node")
+                    logging.exception("source.xml is available.  "
+                                      "But it does not contain an initvm node")
 
             # Seed /etc, we need /etc/hosts for hostname -f to work correctly
             if not buildenv:
@@ -948,10 +928,9 @@ class ElbeProject (object):
                 try:
                     self.get_rpcaptcache(env=target).mark_install(p, None)
                 except KeyError:
-                    self.log.printo("No Package " + p)
-                except SystemError as e:
-                    self.log.printo("Error: Unable to correct problems in "
-                                    "package %s (%s)" % (p, str(e)))
+                    logging.exception("No Package " + p)
+                except SystemError:
+                    logging.exception("Unable to correct problems in package %s", p)
 
             # temporary disabled because of
             # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=776057
@@ -961,5 +940,5 @@ class ElbeProject (object):
             try:
                 self.get_rpcaptcache(env=target).commit()
             except SystemError as e:
-                self.log.printo("commiting changes failed: %s" % str(e))
+                logging.exception("Commiting changes failed")
                 raise AptCacheCommitError(str(e))
-- 
2.11.0




More information about the elbe-devel mailing list