[elbe-devel] [PATCH 30/32] Remove validation.txt

dion at linutronix.de dion at linutronix.de
Fri Jun 14 22:13:44 CEST 2019


From: Olivier Dion <dion at linutronix.de>

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/db.py           |   4 --
 elbepack/dump.py         | 134 ++++++++++++++++++++---------------------------
 elbepack/elbeproject.py  |  27 ++++------
 elbepack/initvmaction.py |  19 -------
 4 files changed, 66 insertions(+), 118 deletions(-)

diff --git a/elbepack/db.py b/elbepack/db.py
index 75fbd3dd..df4e89e9 100644
--- a/elbepack/db.py
+++ b/elbepack/db.py
@@ -841,10 +841,6 @@ class ElbeDB(object):
                                       "application/xml",
                                       "xml License file")
 
-            _update_project_file(s, p.builddir, "validation.txt",
-                                      "text/plain; charset=utf-8",
-                                      "Package list validation result")
-
             _update_project_file(s, p.builddir, "elbe-report.txt",
                                       "text/plain; charset=utf-8",
                                       "Report")
diff --git a/elbepack/dump.py b/elbepack/dump.py
index 20b0bf4b..4003e981 100644
--- a/elbepack/dump.py
+++ b/elbepack/dump.py
@@ -5,16 +5,17 @@
 #
 # SPDX-License-Identifier: GPL-3.0-or-later
 
+import os
 import warnings
 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.log import log, report
 
 
 def get_initvm_pkglist():
@@ -73,15 +74,13 @@ 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")
+    log.h1("ELBE Package validation")
+    log.h2("Package List validation")
 
     errors = 0
 
@@ -90,31 +89,32 @@ 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)
+                log.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)
+                log.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(
-                    "- package %s version %s does not match installed version %s" %
-                    (name, ver, pkg.installed_version))
+                log.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")
+        log.info("No Errors found")
 
     if not fullpkgs:
         return
 
-    elog.h2("Full Packagelist validation")
+    log.h2("Full Packagelist validation")
     errors = 0
 
     pindex = {}
@@ -126,109 +126,95 @@ 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)
+            log.error('Package "%s" does not exist' % name)
             errors += 1
             continue
 
         if not cache.is_installed(name):
-            elog.printo("- package %s is not installed" % name)
+            log.error('Package "%s" is not installed' % name)
             errors += 1
             continue
 
         pkg = cache.get_pkg(name)
 
         if pkg.installed_version != ver:
-            elog.printo(
-                "- package %s version %s does not match installed version %s" %
-                (name, ver, pkg.installed_version))
+            log.error(('Package "%s" version %s does not '
+                       'match installed versiion %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" %
-                        (name, md5, pkg.installed_md5))
+            log.error(('Package "%s" md5 %s does not '
+                       'match installed md5 %s') % (name,
+                                                    mdr,
+                                                    pkg.installed_md5))
             errors += 1
 
     for cp in cache.get_installed_pkgs():
         if cp.name not in pindex:
-            elog.printo(
-                "additional package %s installed, that was not requested" %
-                cp.name)
+            log.error(('Additional package "%s" installed, '
+                       'that was not requested') % cp.name)
             errors += 1
 
     if errors == 0:
-        elog.printo("No Errors found")
+        log.info("No Errors found")
 
 
-def elbe_report(xml, buildenv, cache, reportname, errorname, targetfs):
+def elbe_report(xml, buildenv, cache, reportname, targetfs):
 
     # pylint: disable=too-many-arguments
     # pylint: disable=too-many-locals
     # pylint: disable=too-many-statements
     # pylint: disable=too-many-branches
 
-    outf = ASCIIDocLog(reportname)
+    report.new(reportname)
     rfs = buildenv.rfs
 
-    outf.h1("ELBE Report for Project " + xml.text("project/name"))
-
-    outf.printo(
-        "report timestamp: " +
-        datetime.now().strftime("%Y%m%d-%H%M%S"))
-    outf.printo("elbe: %s" % str(elbe_version))
+    now = datetime.now().strftime("%Y%m%d-%H%M%S")
+    report.info(('elbe-%s\n'
+                 'Report timestamp "%s"') % (elbe_version, now),
+                header='ELBE Report for Project "%s"' % xml.text("project/name"))
 
     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(slist, header="Apt Sources dump")
 
     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()
-
-    outf.h2("Installed Packages List")
-    outf.table()
+    report.info(prefs, header="Apt Preferences dump", verbatim=True)
 
     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('\n'.join(["%s-%s:%s" % (p.name, p.installed_version, p.origin) for p in instpkgs]),
+                header="Installed packages list", verbatim=True)
 
     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))
+            # TODO - do will redirect to project log.txt not report.txt
+            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.h2("finetuning log")
     if xml.has("target/finetuning"):
         do_finetuning(xml, buildenv, targetfs)
         mt_index_post_fine = targetfs.mtime_snap()
     else:
         mt_index_post_fine = mt_index_postarch
 
-    outf.verbatim_end()
-
-    outf.h2("fileslist")
-    outf.table()
-
     tgt_pkg_list = set()
-
+    table = []
     for fpath, _ in targetfs.walk_files():
         if fpath in index:
             pkg = index[fpath]
@@ -250,25 +236,25 @@ def elbe_report(xml, buildenv, cache, reportname, errorname, targetfs):
                 pkg = "added in finetuning"
         # else leave pkg as is
 
-        outf.printo("|+%s+|%s" % (fpath, pkg))
+        table.append("|+%s+|%s" % (fpath, pkg))
+
+    report.info('\n'.join(table), header="fileslist")
+
 
-    outf.table()
 
-    outf.h2("Deleted Files")
-    outf.table()
+    table = []
     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()
+            table.append("|+%s+|%s" % (fpath, pkg))
+    report.info('\n'.join(table), header="Deleted Files")
 
-    outf.h2("Target Package List")
-    outf.table()
     instpkgs = cache.get_installed_pkgs()
     pkgindex = {}
+    table = []
     for p in instpkgs:
         pkgindex[p.name] = p
 
@@ -277,7 +263,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(
+        table.append(
             "|%s|%s|%s|%s" %
             (p.name,
              p.installed_version,
@@ -289,7 +275,8 @@ def elbe_report(xml, buildenv, cache, reportname, errorname, targetfs):
                 (p.name,
                  p.installed_version,
                  p.installed_md5))
-    outf.table()
+
+    report.info('\n'.join(table), header="Target Package List")
 
     if xml.has("target/pkgversionlist"):
         f.close()
@@ -297,25 +284,18 @@ 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")
+    report.h1("Archive validation")
 
     errors = 0
-
     for fpath in list(mt_index_postarch.keys()):
         if fpath not in mt_index or \
                 mt_index_postarch[fpath] != mt_index[fpath]:
             if fpath not in mt_index_post_fine:
-                elog.printo(
-                        "- archive file %s deleted in finetuning" %
-                        fpath)
+                log.error('Archive file "%s" deleted in finetuning' % fpath)
                 errors += 1
             elif mt_index_post_fine[fpath] != mt_index_postarch[fpath]:
-                elog.printo(
-                        "- archive file %s modified in finetuning" %
-                        fpath)
+                log.error('Archive file "%s" modified in finetuning' % fpath)
                 errors += 1
 
     if errors == 0:
-        elog.printo("No Errors found")
+        report.info("No Errors found")
diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index cb08032d..6862a258 100644
--- a/elbepack/elbeproject.py
+++ b/elbepack/elbeproject.py
@@ -135,8 +135,6 @@ class ElbeProject (object):
         self.targetpath = os.path.join(self.builddir, "target")
         self.sysrootpath = os.path.join(self.builddir, "sysroot")
         self.sdkpath = os.path.join(self.builddir, "sdk")
-        self.validationpath = os.path.join(self.builddir, "validation.txt")
-
         self.name = name
         self.override_buildtype = override_buildtype
         self.skip_validate = skip_validate
@@ -430,8 +428,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 +450,7 @@ class ElbeProject (object):
             init_codename = self.xml.get_initvm_codename()
 
             if build_bin:
-                elog.h1("Binary CD %s" % sysrootstr)
+                log.h1("Binary CD %s" % sysrootstr)
 
                 self.repo_images += mk_binary_cdrom(env.rfs,
                                                     self.arch,
@@ -464,7 +460,7 @@ class ElbeProject (object):
                                                     self.builddir,
                                                     cdrom_size=cdrom_size)
             if build_sources:
-                elog.h1("Source CD %s" % sysrootstr)
+                log.h1("Source CD %s" % sysrootstr)
                 try:
                     self.repo_images += mk_source_cdrom(env.rfs,
                                                         self.arch,
@@ -475,7 +471,7 @@ class ElbeProject (object):
                                                         xml=self.xml)
                 except SystemError as e:
                     # e.g. no deb-src urls specified
-                    elog.printo(str(e))
+                    log.error(str(e))
 
     def build(self, build_bin=False, build_sources=False, cdrom_size=None,
               skip_pkglist=False, skip_pbuild=False):
@@ -542,20 +538,15 @@ 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())
+                check_full_pkgs(pkgs,
+                                self.xml.xml.node("/fullpkgs"),
+                                self.get_rpcaptcache())
             else:
-                check_full_pkgs(pkgs, None, self.validationpath,
+                check_full_pkgs(pkgs, None,
                                 self.get_rpcaptcache())
             dump_fullpkgs(self.xml, self.buildenv.rfs, self.get_rpcaptcache())
 
@@ -583,7 +574,7 @@ class ElbeProject (object):
         # 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)
+                    reportpath, 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
@@ -654,7 +645,7 @@ class ElbeProject (object):
 
         self.targetfs.pack_images(self.builddir)
 
-        os.system('cat "%s"' % self.validationpath)
+        os.system('cat "%s"' % log.filename)
 
     def pdebuild_init(self):
         # Remove pdebuilder directory, containing last build results
diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
index 25af1d3f..3d2d6999 100644
--- a/elbepack/initvmaction.py
+++ b/elbepack/initvmaction.py
@@ -320,25 +320,6 @@ def submit_and_dl_result(xmlfile, cdrom, opt):
         print("SDK Build finished !")
         print("")
 
-    try:
-        system(
-            '%s control dump_file "%s" validation.txt' %
-            (elbe_exe, prjdir))
-    except CommandError:
-        print(
-            "Project failed to generate validation.txt",
-            file=sys.stderr)
-        print("Getting log.txt", file=sys.stderr)
-        try:
-            system(
-                '%s control dump_file "%s" log.txt' %
-                (elbe_exe, prjdir))
-        except CommandError:
-
-            print("Failed to dump log.txt", file=sys.stderr)
-            print("Giving up", file=sys.stderr)
-        sys.exit(20)
-
     if opt.skip_download:
         print("")
         print("Listing available files:")
-- 
2.11.0




More information about the elbe-devel mailing list