[elbe-devel] [PATCH v4 10/41] Add logging to stdout for command fetch_initvm_pkgs
Torben Hohn
torben.hohn at linutronix.de
Wed Aug 7 11:58:01 CEST 2019
On Mon, Jul 08, 2019 at 05:11:15PM +0200, dion at linutronix.de wrote:
> From: Olivier Dion <dion at linutronix.de>
>
> make use of the new logging system, and replace all print() with
> functions from logging and wrap it in
> "with elbe_logging({"streams":sys.stdout}):"
>
> Signed-off-by: Olivier Dion <dion at linutronix.de>
Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>
> ---
> elbepack/commands/fetch_initvm_pkgs.py | 169 +++++++++++++++------------------
> 1 file changed, 77 insertions(+), 92 deletions(-)
>
> diff --git a/elbepack/commands/fetch_initvm_pkgs.py b/elbepack/commands/fetch_initvm_pkgs.py
> index b252179f..d72800d7 100644
> --- a/elbepack/commands/fetch_initvm_pkgs.py
> +++ b/elbepack/commands/fetch_initvm_pkgs.py
> @@ -7,6 +7,7 @@
> from __future__ import print_function
>
> import sys
> +import logging
> from optparse import OptionParser
>
> from apt.package import FetchError
> @@ -14,10 +15,11 @@ from apt import Cache
>
> from elbepack.elbexml import ElbeXML, ValidationError
> from elbepack.repomanager import CdromInitRepo, CdromSrcRepo
> -from elbepack.asciidoclog import StdoutLog
> from elbepack.dump import get_initvm_pkglist
> from elbepack.aptprogress import ElbeAcquireProgress
> from elbepack.filesystem import hostfs
> +from elbepack.log import elbe_logging
> +from elbepack.shellhelper import do
>
>
> def run_command(argv):
> @@ -72,96 +74,79 @@ def run_command(argv):
> print("xml validation failed. Bailing out")
> sys.exit(20)
>
> - log = StdoutLog()
> + with elbe_logging({"streams":sys.stdout}):
> +
> + if opt.cdrom_path:
> + if opt.cdrom_device:
> + do('mount "%s" "%s"' % (opt.cdrom_device, opt.cdrom_path))
> +
> + # a cdrom build is identified by the cdrom option
> + # the xml file that is copied into the initvm
> + # by the initrd does not have the cdrom tags setup.
> + mirror = "file://%s" % opt.cdrom_path
> + else:
> + mirror = xml.get_initvm_primary_mirror(opt.cdrom_path)
> +
> + init_codename = xml.get_initvm_codename()
> +
> + # Binary Repo
> + #
> + repo = CdromInitRepo(init_codename, opt.binrepo, log, 0, mirror)
> +
> + hostfs.mkdir_p(opt.archive)
> +
> + if opt.build_bin:
> + pkglist = get_initvm_pkglist()
> + cache = Cache()
> + cache.open()
> + for pkg in pkglist:
> + pkg_id = "%s-%s" % (pkg.name, pkg.installed_version)
> + try:
> + p = cache[pkg.name]
> + pkgver = p.installed
> + deb = pkgver.fetch_binary(opt.archive,
> + ElbeAcquireProgress(cb=None))
> + repo.includedeb(deb, 'main')
> + except ValueError:
> + logging.exception('No package "%s"', pkg_id)
> + except FetchError:
> + logging.exception('Package "%s-%s" could not be downloaded',
> + pkg.name, pkgver.version)
> + except TypeError:
> + logging.exception('Package "%s" missing name or version', pkg_id)
> +
> + repo.finalize()
> +
> + # Source Repo
> + #
> + repo = CdromSrcRepo(init_codename, init_codename, opt.srcrepo, log, 0, mirror)
> + hostfs.mkdir_p(opt.srcarchive)
> +
> + # a cdrom build does not have sources
> + # skip adding packages to the source repo
> + #
> + # FIXME: we need a way to add source cdroms later on
> + if opt.cdrom_path:
> + opt.build_sources = False
> +
> + if opt.build_sources:
> + for pkg in pkglist:
> + pkg_id = "%s-%s" % (pkg.name, pkg.installed_version)
> + try:
> + p = cache[pkg.name]
> + pkgver = p.installed
> + dsc = pkgver.fetch_source(opt.srcarchive,
> + ElbeAcquireProgress(cb=None),
> + unpack=False)
> + repo.include_init_dsc(dsc, 'initvm')
> + except ValueError:
> + logging.exception('No package "%s"', pkg_id)
> + except FetchError:
> + logging.exception('Package "%s-%s" could not be downloaded', pkg.name, pkgver.version)
> + except TypeError:
> + logging.exception('Package "%s" missing name or version', pkg_id)
> +
> + repo.finalize()
>
> - if opt.cdrom_path:
> if opt.cdrom_device:
> - log.do('mount "%s" "%s"' % (opt.cdrom_device, opt.cdrom_path))
> -
> - # a cdrom build is identified by the cdrom option
> - # the xml file that is copied into the initvm
> - # by the initrd does not have the cdrom tags setup.
> - mirror = "file://%s" % opt.cdrom_path
> - else:
> - mirror = xml.get_initvm_primary_mirror(opt.cdrom_path)
> -
> - init_codename = xml.get_initvm_codename()
> -
> - # Binary Repo
> - #
> - repo = CdromInitRepo(init_codename, opt.binrepo, log, 0, mirror)
> -
> - hostfs.mkdir_p(opt.archive)
> -
> - if opt.build_bin:
> - pkglist = get_initvm_pkglist()
> - cache = Cache()
> - cache.open()
> - for pkg in pkglist:
> - try:
> - p = cache[pkg.name]
> - pkgver = p.installed
> - deb = pkgver.fetch_binary(opt.archive,
> - ElbeAcquireProgress(cb=None))
> - repo.includedeb(deb, 'main')
> - except ValueError:
> - log.printo("No Package " + pkg.name +
> - "-" + str(pkg.installed_version))
> - except FetchError:
> - log.printo(
> - "Package " +
> - pkg.name +
> - "-" +
> - pkgver.version +
> - " could not be downloaded")
> - except TypeError:
> - log.printo("Package " +
> - pkg.name +
> - "-" +
> - str(pkg.installed_version) +
> - " missing name or version")
> -
> - repo.finalize()
> -
> - # Source Repo
> - #
> - repo = CdromSrcRepo(init_codename, init_codename, opt.srcrepo, log, 0, mirror)
> - hostfs.mkdir_p(opt.srcarchive)
> -
> - # a cdrom build does not have sources
> - # skip adding packages to the source repo
> - #
> - # FIXME: we need a way to add source cdroms later on
> - if opt.cdrom_path:
> - opt.build_sources = False
> -
> - if opt.build_sources:
> - for pkg in pkglist:
> - try:
> - p = cache[pkg.name]
> - pkgver = p.installed
> - dsc = pkgver.fetch_source(opt.srcarchive,
> - ElbeAcquireProgress(cb=None),
> - unpack=False)
> - repo.include_init_dsc(dsc, 'initvm')
> - except ValueError:
> - log.printo("No Package " + pkg.name +
> - "-" + str(pkg.installed_version))
> - except FetchError:
> - log.printo(
> - "Package " +
> - pkg.name +
> - "-" +
> - pkgver.version +
> - " could not be downloaded")
> - except TypeError:
> - log.printo("Package " +
> - pkg.name +
> - "-" +
> - str(pkg.installed_version) +
> - " missing name or version")
> -
> - repo.finalize()
> -
> - if opt.cdrom_device:
> - log.do('umount "%s"' % opt.cdrom_device)
> + do('umount "%s"' % opt.cdrom_device)
> --
> 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