[elbe-devel] [PATCH v2 18/28] Async logging for rpcaptcache
Torben Hohn
torben.hohn at linutronix.de
Wed Jun 26 16:02:56 CEST 2019
On Fri, Jun 21, 2019 at 07:40:10PM +0200, dion at linutronix.de wrote:
> From: Olivier Dion <dion at linutronix.de>
>
> Signed-off-by: Olivier Dion <dion at linutronix.de>
looks good, some comments missing, and
a proper commit log please.
> ---
> elbepack/cdroms.py | 6 ++---
> elbepack/elbeproject.py | 11 +++-----
> elbepack/rpcaptcache.py | 71 ++++++++++++++++++++++++++++---------------------
> 3 files changed, 48 insertions(+), 40 deletions(-)
>
> diff --git a/elbepack/cdroms.py b/elbepack/cdroms.py
> index 3f2ecc21..e16dcd2d 100644
> --- a/elbepack/cdroms.py
> +++ b/elbepack/cdroms.py
> @@ -49,7 +49,7 @@ def mk_source_cdrom(
> cdrom_size,
> mirror)
>
> - cache = get_rpcaptcache(rfs, "aptcache.log", arch)
> + cache = get_rpcaptcache(rfs, arch)
> cache.update()
> pkglist = cache.get_installed_pkgs()
>
> @@ -150,7 +150,7 @@ def mk_binary_cdrom(
> target_repo_path, log, cdrom_size, mirror)
>
> if xml is not None:
> - cache = get_rpcaptcache(rfs, "aptcache.log", arch)
> + cache = get_rpcaptcache(rfs, arch)
> for p in xml.node("debootstrappkgs"):
> pkg = XMLPackage(p, arch)
> try:
> @@ -179,7 +179,7 @@ def mk_binary_cdrom(
> pkg.installed_version +
> " missing name or version")
>
> - cache = get_rpcaptcache(rfs, "aptcache.log", arch)
> + cache = get_rpcaptcache(rfs, arch)
> pkglist = cache.get_installed_pkgs()
> for pkg in pkglist:
> try:
> diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
> index 073bfb15..6911a9c9 100644
> --- a/elbepack/elbeproject.py
> +++ b/elbepack/elbeproject.py
> @@ -807,13 +807,10 @@ class ElbeProject (object):
> arch = env.arch
>
> if env.rpcaptcache is None:
> - env.rpcaptcache = get_rpcaptcache(
> - env.rfs,
> - self.log.fp.name,
> - arch,
> - self.rpcaptcache_notifier,
> - norecommend,
> - self.xml.prj.has('noauth'))
> + env.rpcaptcache = get_rpcaptcache(env.rfs, arch,
> + self.rpcaptcache_notifier,
> + norecommend,
> + self.xml.prj.has('noauth'))
> return env.rpcaptcache
>
> def drop_rpcaptcache(self, env=None):
> diff --git a/elbepack/rpcaptcache.py b/elbepack/rpcaptcache.py
> index d4f4a794..b9f0afc6 100644
> --- a/elbepack/rpcaptcache.py
> +++ b/elbepack/rpcaptcache.py
> @@ -6,6 +6,7 @@
> #
> # SPDX-License-Identifier: GPL-3.0-or-later
>
> +import logging
> import os
> import sys
> import time
> @@ -20,6 +21,36 @@ from apt import Cache
> from elbepack.aptprogress import (ElbeAcquireProgress, ElbeInstallProgress,
> ElbeOpProgress)
> from elbepack.aptpkgutils import getalldeps, APTPackage
> +from elbepack.log import async_logging
> +
> +log = logging.getLogger("log")
> +soap = logging.getLogger("soap")
> +
> +
> +class MyMan(BaseManager):
> +
> + @staticmethod
> + def register(typeid):
> + def _register(cls):
> + BaseManager.register(typeid, cls)
> + return cls
> + return _register
> +
> + @staticmethod
> + def redirect_outputs(r, w):
> + os.close(r)
> + os.dup2(w, os.sys.stdout.fileno())
> + os.dup2(w, os.sys.stderr.fileno())
> + os.sys.stdout = os.fdopen(os.sys.stdout.fileno(), "w", 1)
> + os.sys.stderr = os.fdopen(os.sys.stderr.fileno(), "w", 1)
> + os.sys.__stdout__ = os.sys.stdout
> + os.sys.__stderr__ = os.sys.stderr
> +
> +
> + def start(self):
> + r, w = os.pipe()
> + super(MyMan, self).start(MyMan.redirect_outputs, [r, w])
> + async_logging(r, w, soap, log)
this confused the hell out of me.
please add comments stating, that the other pipe ends are closed,
etc...
>
> class InChRootObject(object):
> def __init__(self, rfs):
> @@ -28,23 +59,14 @@ class InChRootObject(object):
> self.finalizer = Finalize(self, self.rfs.leave_chroot, exitpriority=10)
>
>
> + at MyMan.register("RPCAPTCache")
> class RPCAPTCache(InChRootObject):
> +
> # pylint: disable=too-many-public-methods
> - def __init__(
> - self,
> - rfs,
> - log,
> - arch,
> - notifier=None,
> - norecommend=False,
> - noauth=True):
> + def __init__(self, rfs, arch,
> + notifier=None, norecommend=False, noauth=True):
>
> # pylint: disable=too-many-arguments
> -
> - sys.stdout = open(log, 'a', buffering=0)
> - sys.stderr = open(log, 'a', buffering=0)
> - self.logfile = open(log, 'a', buffering=0)
> -
> InChRootObject.__init__(self, rfs)
>
> self.notifier = notifier
> @@ -99,6 +121,7 @@ class RPCAPTCache(InChRootObject):
> return ret
>
> def mark_install(self, pkgname, version, from_user=True, nodeps=False):
> + print('Mark for install "%s"' % pkgname)
> p = self.cache[pkgname]
> if version:
> p.candidate = p.versions[version]
> @@ -165,8 +188,9 @@ class RPCAPTCache(InChRootObject):
> def commit(self):
> os.environ["DEBIAN_FRONTEND"] = "noninteractive"
> os.environ["DEBONF_NONINTERACTIVE_SEEN"] = "true"
> + print("Commiting changes ...")
> self.cache.commit(ElbeAcquireProgress(),
> - ElbeInstallProgress(fileno=self.logfile.fileno()))
> + ElbeInstallProgress(fileno=sys.stdout.fileno()))
> self.cache.open(progress=ElbeOpProgress())
>
> def clear(self):
> @@ -275,21 +299,8 @@ class RPCAPTCache(InChRootObject):
> unpack=False)
> return self.rfs.fname(rel_filename)
>
> -
> -class MyMan(BaseManager):
> - pass
> -
> -
> -MyMan.register("RPCAPTCache", RPCAPTCache)
> -
> -
> -def get_rpcaptcache(
> - rfs,
> - log,
> - arch,
> - notifier=None,
> - norecommend=False,
> - noauth=True):
> +def get_rpcaptcache(rfs, arch,
> + notifier=None, norecommend=False, noauth=True):
>
> # pylint: disable=too-many-arguments
>
> @@ -301,4 +312,4 @@ def get_rpcaptcache(
> # MyMan.register()
> #
> # pylint: disable=no-member
> - return mm.RPCAPTCache(rfs, log, arch, notifier, norecommend, noauth)
> + return mm.RPCAPTCache(rfs, arch, notifier, norecommend, noauth)
> --
> 2.11.0
>
>
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel
--
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99
Hinweise zum Datenschutz finden Sie hier (Informations on data privacy
can be found here): https://linutronix.de/kontakt/Datenschutz.php
Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen |
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner
More information about the elbe-devel
mailing list