[elbe-devel] [PATCH 18/32] Nuke ASCIIDocLog from repomanager

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


From: Olivier Dion <dion at linutronix.de>

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/cdroms.py                     |  5 +-
 elbepack/commands/fetch_initvm_pkgs.py |  4 +-
 elbepack/commands/toolchainextract.py  | 11 +++--
 elbepack/elbeproject.py                |  2 +-
 elbepack/finetuning.py                 |  3 +-
 elbepack/pkgarchive.py                 | 53 ++++++++-------------
 elbepack/repomanager.py                | 85 +++++++++++++---------------------
 elbepack/updatepkg.py                  |  2 +-
 8 files changed, 65 insertions(+), 100 deletions(-)

diff --git a/elbepack/cdroms.py b/elbepack/cdroms.py
index 3f2ecc21..8f0723f4 100644
--- a/elbepack/cdroms.py
+++ b/elbepack/cdroms.py
@@ -45,7 +45,6 @@ def mk_source_cdrom(
 
     repo = CdromSrcRepo(codename, init_codename,
                         os.path.join(target, "srcrepo"),
-                        log,
                         cdrom_size,
                         mirror)
 
@@ -144,10 +143,10 @@ def mk_binary_cdrom(
         log.printo('       generated with --skip-build-bin')
         log.do('mkdir -p "%s"' % repo_path)
 
-    repo = CdromInitRepo(init_codename, repo_path, log, cdrom_size, mirror)
+    repo = CdromInitRepo(init_codename, repo_path, cdrom_size, mirror)
 
     target_repo = CdromBinRepo(arch, codename, None,
-                               target_repo_path, log, cdrom_size, mirror)
+                               target_repo_path, cdrom_size, mirror)
 
     if xml is not None:
         cache = get_rpcaptcache(rfs, "aptcache.log", arch)
diff --git a/elbepack/commands/fetch_initvm_pkgs.py b/elbepack/commands/fetch_initvm_pkgs.py
index 564616d4..0b8367b6 100644
--- a/elbepack/commands/fetch_initvm_pkgs.py
+++ b/elbepack/commands/fetch_initvm_pkgs.py
@@ -90,7 +90,7 @@ def run_command(argv):
 
     # Binary Repo
     #
-    repo = CdromInitRepo(init_codename, opt.binrepo, log, 0, mirror)
+    repo = CdromInitRepo(init_codename, opt.binrepo, 0, mirror)
 
     hostfs.mkdir_p(opt.archive)
 
@@ -118,7 +118,7 @@ def run_command(argv):
 
     # Source Repo
     #
-    repo = CdromSrcRepo(init_codename, init_codename, opt.srcrepo, log, 0, mirror)
+    repo = CdromSrcRepo(init_codename, init_codename, opt.srcrepo, 0, mirror)
     hostfs.mkdir_p(opt.srcarchive)
 
     # a cdrom build does not have sources
diff --git a/elbepack/commands/toolchainextract.py b/elbepack/commands/toolchainextract.py
index 6565e9b1..0a6484df 100644
--- a/elbepack/commands/toolchainextract.py
+++ b/elbepack/commands/toolchainextract.py
@@ -73,11 +73,12 @@ def run_command(argv):
     else:
         log.stdout()
 
-    repo = ToolchainRepo(
-        defaults["arch"],
-        opt.codename,
-        opt.output,
-        StdoutLog())
+    # ERROR?  Is it really opt.output and not opt.path?
+    # ToolchainRepo::__init__(self, arch, codename, path)
+    # Seems to me like there has been a bad naming here.
+    repo = ToolchainRepo(defaults["arch"],
+                         opt.codename,
+                         opt.output)
 
     for p in pkgs:
         repo.includedeb(os.path.join(tmpdir, p))
diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index 652230ff..a0ecb989 100644
--- a/elbepack/elbeproject.py
+++ b/elbepack/elbeproject.py
@@ -189,7 +189,7 @@ class ElbeProject (object):
             self.log = StdoutLog()
 
         self.repo = ProjectRepo(self.arch, self.codename,
-                                os.path.join(self.builddir, "repo"), self.log)
+                                os.path.join(self.builddir, "repo"))
 
         # Create BuildEnv instance, if the chroot directory exists and
         # has an etc/elbe_version
diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
index 426097aa..5da50b1f 100644
--- a/elbepack/finetuning.py
+++ b/elbepack/finetuning.py
@@ -539,8 +539,7 @@ class UpdatedAction(FinetuningAction):
                         " missing name or version")
 
         r = UpdateRepo(target.xml,
-                       target.path + '/var/cache/elbe/repos/base',
-                       log)
+                       target.path + '/var/cache/elbe/repos/base')
 
         for d in buildenv.rfs.glob('tmp/pkgs/*.deb'):
             r.includedeb(d, 'main')
diff --git a/elbepack/pkgarchive.py b/elbepack/pkgarchive.py
index 14e6bd46..fca594d8 100644
--- a/elbepack/pkgarchive.py
+++ b/elbepack/pkgarchive.py
@@ -9,10 +9,11 @@ from os import path, remove
 from shutil import rmtree, copytree, move
 from apt.package import FetchError
 from elbepack.repomanager import RepoBase, RepoAttributes
+from elbepack.log import log
 
 
 class ArchiveRepo(RepoBase):
-    def __init__(self, xml, pathname, log, origin, description, components,
+    def __init__(self, xml, pathname, origin, description, components,
                  maxsize=None):
 
         # pylint: disable=too-many-arguments
@@ -24,7 +25,6 @@ class ArchiveRepo(RepoBase):
 
         RepoBase.__init__(self,
                           pathname,
-                          log,
                           None,
                           repo_attrs,
                           description,
@@ -45,7 +45,7 @@ def gen_binpkg_archive(ep, repodir):
 
     try:
         # Repository containing all packages currently installed
-        repo = ArchiveRepo(ep.xml, repopath, ep.log, "Elbe",
+        repo = ArchiveRepo(ep.xml, repopath, "Elbe",
                            "Elbe package archive", ["main"])
 
         c = ep.get_rpcaptcache()
@@ -59,34 +59,21 @@ def gen_binpkg_archive(ep, repodir):
 
             if not path.isfile(abs_path):
                 # Package file does not exist, download it and adjust path name
-                ep.log.printo(
-                    "Package file " +
-                    filename +
-                    " not found in var/cache/apt/archives, downloading it")
+                log.warning('Package file "%s" not found in var/cache/apt/archives, downloading it' % filename)
                 abs_path = ep.buildenv.rfs.fname(rel_path)
+                pkg_id = "%s-%s" % (pkg.name, pkg.installed_version)
                 try:
                     abs_path = c.download_binary(pkg.name,
                                                  '/var/cache/elbe/pkgarchive',
                                                  pkg.installed_version)
                 except ValueError:
-                    ep.log.printo("No Package " + pkg.name + "-" +
-                                  pkg.installed_version)
+                    log.error('No package "%s"' % pkg_id)
                     raise
                 except FetchError:
-                    ep.log.printo(
-                        "Package " +
-                        pkg.name +
-                        "-" +
-                        pkg.installed_version +
-                        " could not be downloaded")
+                    log.error('Package "%s" could not be downloaded' % pkd_id)
                     raise
                 except TypeError:
-                    ep.log.printo(
-                        "Package " +
-                        pkg.name +
-                        "-" +
-                        pkg.installed_version +
-                        " missing name or version")
+                    log.error('Package "%s" missing name or version' % pkd_id)
                     raise
 
             # Add package to repository
@@ -116,12 +103,12 @@ def checkout_binpkg_archive(ep, repodir):
         try:
             # Copy the package archive into the buildenv,
             # so the RPCAptCache can access it
-            ep.log.printo("Copying package archive into build environment")
+            log.info("Copying package archive into build environment")
             copytree(repopath, pkgarchive)
 
             # Move original etc/apt/sources.list and etc/apt/sources.list.d out
             # of the way
-            ep.log.printo("Moving original APT configuration out of the way")
+            log.info("Moving original APT configuration out of the way")
             if path.isfile(sources_list):
                 move(sources_list, sources_list_backup)
             if path.isdir(sources_list_d):
@@ -129,7 +116,7 @@ def checkout_binpkg_archive(ep, repodir):
 
             # Now create our own, with the package archive being the only
             # source
-            ep.log.printo("Creating new /etc/apt/sources.list")
+            log.info("Creating new /etc/apt/sources.list")
             deb = "deb file:///var/cache/elbe/pkgarchive "
             deb += ep.xml.text("/project/suite")
             deb += " main"
@@ -138,14 +125,14 @@ def checkout_binpkg_archive(ep, repodir):
 
             # We need to update the APT cache to apply the changed package
             # source
-            ep.log.printo("Updating APT cache to use package archive")
+            log.info("Updating APT cache to use package archive")
             ep.drop_rpcaptcache()
             c = ep.get_rpcaptcache()
             c.update()
 
             # Iterate over all packages, and mark them for installation or
             # deletion, using the same logic as in commands/updated.py
-            ep.log.printo("Calculating packages to install/remove")
+            log.info("Calculating packages to install/remove")
             fpl = ep.xml.node("fullpkgs")
             pkgs = c.get_pkglist('all')
 
@@ -154,24 +141,24 @@ def checkout_binpkg_archive(ep, repodir):
                 for fpi in fpl:
                     if p.name == fpi.et.text:
                         version = fpi.et.get('version')
-                        ep.log.printo("Install " + p.name + "-" + version)
+                        log.info('Install "%s-%s"' % (p.name, version))
                         c.mark_install(p.name, version,
                                        from_user=not fpi.et.get('auto'),
                                        nodeps=True)
                         marked = True
 
                 if not marked:
-                    ep.log.printo("Delete " + p.name + "-" + version)
+                    log.info('Delete "%s-%s"' % (p.name, version))
                     c.mark_delete(p.name)
 
             # Now commit the changes
-            ep.log.printo("Commiting package changes")
+            log.info("Commiting package changes")
             c.commit()
         finally:
             # If we changed the package sources, move back the backup
             if path.isdir(sources_list_d_backup) or \
                     path.isfile(sources_list_backup):
-                ep.log.printo("Moving back original APT configuration")
+                log.info("Moving back original APT configuration")
                 update_needed = True
             else:
                 update_needed = False
@@ -186,13 +173,11 @@ def checkout_binpkg_archive(ep, repodir):
 
             # Remove the package archive from the buildenv
             if path.isdir(pkgarchive):
-                ep.log.printo(
-                    "Removing package archive from build environment")
+                log.info("Removing package archive from build environment")
                 rmtree(pkgarchive)
 
             # Update APT cache, if we modified the package sources
             if update_needed:
-                ep.log.printo(
-                    "Updating APT cache to use original package sources")
+                log.info("Updating APT cache to use original package sources")
                 ep.drop_rpcaptcache()
                 ep.get_rpcaptcache().update()
diff --git a/elbepack/repomanager.py b/elbepack/repomanager.py
index 1969c8f9..f8359d60 100644
--- a/elbepack/repomanager.py
+++ b/elbepack/repomanager.py
@@ -16,7 +16,7 @@ from elbepack.debianreleases import codename2suite
 from elbepack.filesystem import Filesystem
 from elbepack.pkgutils import get_dsc_size
 from elbepack.egpg import generate_elbe_internal_key, export_key, unlock_key
-from elbepack.shellhelper import CommandError
+from elbepack.shellhelper import CommandError, do
 
 
 class RepoAttributes(object):
@@ -56,7 +56,6 @@ class RepoBase(object):
     def __init__(
             self,
             path,
-            log,
             init_attr,
             repo_attr,
             origin,
@@ -68,7 +67,6 @@ class RepoBase(object):
         self.vol_path = path
         self.volume_count = 0
 
-        self.log = log
         self.init_attr = init_attr
         self.repo_attr = repo_attr
 
@@ -164,28 +162,22 @@ class RepoBase(object):
             shutil.copyfile(keyring, self.fs.fname("/elbe-keyring.gpg"))
 
         if need_update:
-            self.log.do(
-                'reprepro --export=force --basedir "' +
-                self.fs.path +
-                '" update',
-                env_add={'GNUPGHOME': "/var/cache/elbe/gnupg"})
+            cmd = 'reprepro --export=force --basedir "%s" update' % self.fs.path
+            do(cmd,
+               env_add={'GNUPGHOME': "/var/cache/elbe/gnupg"})
         else:
             for att in self.attrs:
-                self.log.do(
-                    'reprepro --basedir "' +
-                    self.fs.path +
-                    '" export ' +
-                    att.codename,
+                cmd = 'reprepro --basedir "%s" export %s' % (self.fs.path,
+                                                              att.codename)
+                do(cmd,
                     env_add={'GNUPGHOME': "/var/cache/elbe/gnupg"})
 
     def finalize(self):
         for att in self.attrs:
-            self.log.do(
-                'reprepro --basedir "' +
-                self.fs.path +
-                '" export ' +
-                att.codename,
-                env_add={'GNUPGHOME': '/var/cache/elbe/gnupg'})
+            cmd = 'reprepro --basedir "%s" export %s' % (self.fs.path,
+                                                         att.codename)
+            do(cmd,
+               env_add={'GNUPGHOME': '/var/cache/elbe/gnupg'})
 
     def _includedeb(self, path, codename, component):
         if self.maxsize:
@@ -193,15 +185,12 @@ class RepoBase(object):
             if new_size > self.maxsize:
                 self.new_repo_volume()
 
-        self.log.do(
-            'reprepro --keepunreferencedfiles --export=never --basedir "' +
-            self.fs.path +
-            '" -C ' +
-            component +
-            ' includedeb ' +
-            codename +
-            ' ' +
-            path)
+        cmd = ('reprepro --keepunreferencedfiles --export=never '
+               '--basedir "%s" -C %s includedeb %s %s' % (self.fs.path,
+                                                          component,
+                                                          codename,
+                                                          path))
+        do(cmd)
 
     def includedeb(self, path, component="main", pkgname=None, force=False):
         # pkgname needs only to be specified if force is enabled
@@ -223,14 +212,14 @@ class RepoBase(object):
         self._includedeb(path, self.init_attr.codename, component)
 
     def _include(self, path, codename, component):
-        self.log.do('reprepro --ignore=wrongdistribution '
+        do('reprepro --ignore=wrongdistribution '
                     '--ignore=surprisingbinary --keepunreferencedfiles '
-                    '--export=never --basedir "' + self.fs.path + '" -C ' +
-                    component + ' -P normal -S misc include ' + codename +
-                    ' ' + path)
+           '--export=never --basedir "' + self.fs.path + '" -C ' +
+           component + ' -P normal -S misc include ' + codename +
+           ' ' + path)
 
     def _removedeb(self, pkgname, codename):
-        self.log.do(
+        do(
             "reprepro --basedir %s remove %s %s" %
             (self.fs.path, codename, pkgname),
             env_add={'GNUPGHOME': '/var/cache/elbe/gnupg'})
@@ -239,7 +228,7 @@ class RepoBase(object):
         self._removedeb(pkgname, self.repo_attr.codename)
 
     def _removesrc(self, srcname, codename):
-        self.log.do(
+        do(
             "reprepro --basedir %s removesrc %s %s" %
             (self.fs.path, codename, srcname),
             env_add={'GNUPGHOME': '/var/cache/elbe/gnupg'})
@@ -269,7 +258,7 @@ class RepoBase(object):
         if self.maxsize and (self.fs.disk_usage("") > self.maxsize):
             self.new_repo_volume()
 
-        self.log.do(
+        do(
             'reprepro --keepunreferencedfiles --export=never --basedir "' +
             self.fs.path +
             '" -C ' +
@@ -292,9 +281,8 @@ class RepoBase(object):
                 #
                 # copy the dsc into the cdrom root,
                 # when reprepro fails to insert it.
-                self.log.printo('Unable to verify dsc "%s":' % path)
-                self.log.printo('unsupported signature algorithm')
-                self.log.do('cp -av "%s" "%s"' % (path, self.fs.path))
+                log.error('Unable to verify dsc "%s": unsupported signature algorithm' % path)
+                do('cp -av "%s" "%s"' % (path, self.fs.path))
             elif force:
                 # Including dsc did not work.
                 # Maybe we have the same Version with a
@@ -321,7 +309,7 @@ class RepoBase(object):
         files = []
         if self.volume_count == 0:
             new_path = '"' + self.fs.path + '"'
-            self.log.do(
+            do(
                 "genisoimage -o %s -J -joliet-long -R %s" %
                 (fname, new_path))
             files.append(fname)
@@ -329,7 +317,7 @@ class RepoBase(object):
             for i in range(self.volume_count + 1):
                 volfs = self.get_volume_fs(i)
                 newname = fname + ("%02d" % i)
-                self.log.do(
+                do(
                     "genisoimage -o %s -J -joliet-long -R %s" %
                     (newname, volfs.path))
                 files.append(newname)
@@ -338,7 +326,7 @@ class RepoBase(object):
 
 
 class UpdateRepo(RepoBase):
-    def __init__(self, xml, path, log):
+    def __init__(self, xml, path):
         self.xml = xml
 
         arch = xml.text("project/arch", key="arch")
@@ -348,7 +336,6 @@ class UpdateRepo(RepoBase):
 
         RepoBase.__init__(self,
                           path,
-                          log,
                           None,
                           repo_attrs,
                           "Update",
@@ -356,7 +343,7 @@ class UpdateRepo(RepoBase):
 
 
 class CdromInitRepo(RepoBase):
-    def __init__(self, init_codename, path, log, maxsize,
+    def __init__(self, init_codename, path, maxsize,
                  mirror='http://ftp.de.debian.org/debian'):
 
         # pylint: disable=too-many-arguments
@@ -367,7 +354,6 @@ class CdromInitRepo(RepoBase):
 
         RepoBase.__init__(self,
                           path,
-                          log,
                           None,
                           init_attrs,
                           "Elbe",
@@ -382,7 +368,6 @@ class CdromBinRepo(RepoBase):
             codename,
             init_codename,
             path,
-            log,
             maxsize,
             mirror='http://ftp.debian.org/debian'):
 
@@ -398,7 +383,6 @@ class CdromBinRepo(RepoBase):
 
         RepoBase.__init__(self,
                           path,
-                          log,
                           init_attrs,
                           repo_attrs,
                           "Elbe",
@@ -407,7 +391,7 @@ class CdromBinRepo(RepoBase):
 
 
 class CdromSrcRepo(RepoBase):
-    def __init__(self, codename, init_codename, path, log, maxsize,
+    def __init__(self, codename, init_codename, path, maxsize,
                  mirror='http://ftp.debian.org/debian'):
 
         # pylint: disable=too-many-arguments
@@ -427,7 +411,6 @@ class CdromSrcRepo(RepoBase):
 
         RepoBase.__init__(self,
                           path,
-                          log,
                           init_attrs,
                           repo_attrs,
                           "Elbe",
@@ -436,11 +419,10 @@ class CdromSrcRepo(RepoBase):
 
 
 class ToolchainRepo(RepoBase):
-    def __init__(self, arch, codename, path, log):
+    def __init__(self, arch, codename, path):
         repo_attrs = RepoAttributes(codename, arch, "main")
         RepoBase.__init__(self,
                           path,
-                          log,
                           None,
                           repo_attrs,
                           "toolchain",
@@ -448,11 +430,10 @@ class ToolchainRepo(RepoBase):
 
 
 class ProjectRepo(RepoBase):
-    def __init__(self, arch, codename, path, log):
+    def __init__(self, arch, codename, path):
         repo_attrs = RepoAttributes(codename, arch + ' source', "main")
         RepoBase.__init__(self,
                           path,
-                          log,
                           None,
                           repo_attrs,
                           "Local",
diff --git a/elbepack/updatepkg.py b/elbepack/updatepkg.py
index b41cffe0..8c14aa23 100644
--- a/elbepack/updatepkg.py
+++ b/elbepack/updatepkg.py
@@ -114,7 +114,7 @@ def gen_update_pkg(project, xml_filename, upd_filename,
     if xml_filename:
         repodir = os.path.join(update, "repo")
 
-        repo = UpdateRepo(xml, repodir, project.log)
+        repo = UpdateRepo(xml, repodir)
 
         for fname in fnamelist:
             path = os.path.join(
-- 
2.11.0




More information about the elbe-devel mailing list