[elbe-devel] [PATCH v3 27/52] Add logging to opt.log for command mkcdrom

Torben Hohn torben.hohn at linutronix.de
Fri Jul 5 13:00:06 CEST 2019


On Thu, Jun 27, 2019 at 02:44:41PM +0200, dion at linutronix.de wrote:
> From: Olivier Dion <dion at linutronix.de>
> 
> Signed-off-by: Olivier Dion <dion at linutronix.de>
> ---
>  elbepack/commands/mkcdrom.py | 104 +++++++++++++++++++++----------------------
>  1 file changed, 51 insertions(+), 53 deletions(-)
> 
> diff --git a/elbepack/commands/mkcdrom.py b/elbepack/commands/mkcdrom.py
> index f00e9645..6387bd17 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,53 @@ 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)
> +    stdout = True
> +    if opt.log:
> +        stdout = False

i would really like this logic to be moved into elbe_logging()
looking closer, i dont understand, how specifying a logfile and a
project dir is distinguished.

i mean the async stuff should be doing sometinhg like:

with elbe_logging(builddir=p.projectpath)

normal commands can do

with elbe_logging(stdout=True)

or

with elbe_logging(opt.output)   # default to stdout, when opt.output is None
> +
> +    with elbe_logging(builddir=opt.log, stdout=stdout):
> +
> +        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