[elbe-devel] [PATCH v4 17/41] Add logging to opt.log for command mkcdrom

Torben Hohn torben.hohn at linutronix.de
Wed Aug 7 12:04:23 CEST 2019


On Mon, Jul 08, 2019 at 05:18:13PM +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({"files":opt.log}):"
> 
> Signed-off-by: Olivier Dion <dion at linutronix.de>

Acked-by: Torben Hohn <torben.hohn at linutronix.de>

style problems, i think... fix it later.


> ---
>  elbepack/commands/mkcdrom.py | 100 ++++++++++++++++++++-----------------------
>  1 file changed, 47 insertions(+), 53 deletions(-)
> 
> diff --git a/elbepack/commands/mkcdrom.py b/elbepack/commands/mkcdrom.py
> index f00e9645..26e6fb6e 100644
> --- a/elbepack/commands/mkcdrom.py
> +++ b/elbepack/commands/mkcdrom.py
> @@ -11,11 +11,12 @@ from __future__ import print_function
>  from optparse import OptionParser
>  import sys
>  import os
> +import logging
>  
>  from elbepack.elbeproject import ElbeProject
>  from elbepack.elbexml import ValidationError
> -from elbepack.asciidoclog import StdoutLog, ASCIIDocLog
>  from elbepack.efilesystem import ChRootFilesystem
> +from elbepack.log import elbe_logging
>  
>  from elbepack.cdroms import mk_source_cdrom, mk_binary_cdrom, CDROM_SIZE
>  
> @@ -61,56 +62,49 @@ def run_command(argv):
>          oparser.print_help()
>          sys.exit(20)
>  
> -    if not opt.rfs_only:
> -        try:
> -            project = ElbeProject(args[0], logpath=opt.log,
> -                                  override_buildtype=opt.buildtype,
> -                                  skip_validate=opt.skip_validation)
> -        except ValidationError as e:
> -            print(str(e), file=sys.stderr)
> -            print("xml validation failed. Bailing out", file=sys.stderr)
> -            sys.exit(20)
> -
> -        builddir = project.builddir
> -        rfs = project.buildenv.rfs
> -        xml = project.xml
> -        arch = xml.text("project/arch", key="arch")
> -        codename = xml.text("project/suite")
> -        log = project.log
> -        init_codename = xml.get_initvm_codename()
> -    else:
> -        builddir = os.path.abspath(os.path.curdir)
> -        rfs = ChRootFilesystem(args[0])
> -        arch = opt.arch
> -        codename = opt.codename
> -        init_codename = opt.init_codename
> -        xml = None
> -        if opt.log:
> -            log = ASCIIDocLog(opt.log)
> +    with elbe_logging({"files":opt.log}):
> +
> +        if not opt.rfs_only:
> +            try:
> +                project = ElbeProject(args[0], logpath=opt.log,
> +                                      override_buildtype=opt.buildtype,
> +                                      skip_validate=opt.skip_validation)
> +            except ValidationError:
> +                logging.exception("XML validation failed.  Bailing out")
> +                sys.exit(20)
> +
> +            builddir = project.builddir
> +            rfs = project.buildenv.rfs
> +            xml = project.xml
> +            arch = xml.text("project/arch", key="arch")
> +            codename = xml.text("project/suite")
> +            init_codename = xml.get_initvm_codename()
>          else:
> -            log = StdoutLog()
> -
> -    generated_files = []
> -    if opt.source:
> -        with rfs:
> -            generated_files += mk_source_cdrom(rfs, arch, codename,
> -                                               init_codename, builddir, log,
> -                                               opt.cdrom_size)
> -
> -    if opt.binary:
> -        with rfs:
> -            generated_files += mk_binary_cdrom(rfs,
> -                                               arch,
> -                                               codename,
> -                                               init_codename,
> -                                               xml,
> -                                               builddir,
> -                                               log,
> -                                               opt.cdrom_size)
> -
> -    print("")
> -    print("Image Build finished !")
> -    print("")
> -    print("Files generated:")
> -    for f in generated_files:
> -        print(" %s" % f)
> +            builddir = os.path.abspath(os.path.curdir)
> +            rfs = ChRootFilesystem(args[0])
> +            arch = opt.arch
> +            codename = opt.codename
> +            init_codename = opt.init_codename
> +            xml = None
> +
> +        generated_files = []
> +        if opt.source:
> +            with rfs:
> +                generated_files += mk_source_cdrom(rfs, arch, codename,
> +                                                   init_codename, builddir, log,
> +                                                   opt.cdrom_size)
> +
> +        if opt.binary:
> +            with rfs:
> +                generated_files += mk_binary_cdrom(rfs,
> +                                                   arch,
> +                                                   codename,
> +                                                   init_codename,
> +                                                   xml,
> +                                                   builddir,
> +                                                   log,
> +                                                   opt.cdrom_size)
> +
> +        logging.info("Image Build finished.\n")
> +        logging.info("Files generated:\n%s",
> +                     "\n".join([str(f) for f in generated_files]))
> -- 
> 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