[elbe-devel] [PATCH 31/32] Nuke ASCIIDocLog from elbeproject
dion at linutronix.de
dion at linutronix.de
Fri Jun 14 22:13:45 CEST 2019
From: Olivier Dion <dion at linutronix.de>
Signed-off-by: Olivier Dion <dion at linutronix.de>
---
elbepack/commands/buildchroot.py | 2 +-
elbepack/commands/chroot.py | 9 +-
elbepack/commands/hdimg.py | 2 +-
elbepack/commands/mkcdrom.py | 2 +-
elbepack/db.py | 3 +-
elbepack/elbeproject.py | 212 ++++++++++++++++++---------------------
6 files changed, 109 insertions(+), 121 deletions(-)
diff --git a/elbepack/commands/buildchroot.py b/elbepack/commands/buildchroot.py
index 5d0624e1..f836c96a 100644
--- a/elbepack/commands/buildchroot.py
+++ b/elbepack/commands/buildchroot.py
@@ -95,7 +95,7 @@ def run_command(argv):
else:
log.stdout()
- project = ElbeProject(opt.target, args[0], opt.output, opt.name,
+ project = ElbeProject(opt.target, args[0], opt.name,
opt.buildtype, opt.skip_validation)
except ValidationError as e:
print(str(e))
diff --git a/elbepack/commands/chroot.py b/elbepack/commands/chroot.py
index 41e1dda6..ed8b6869 100644
--- a/elbepack/commands/chroot.py
+++ b/elbepack/commands/chroot.py
@@ -38,11 +38,10 @@ def run_command(argv):
try:
log.stdout()
- project = ElbeProject(
- args[0],
- override_buildtype=opt.buildtype,
- skip_validate=opt.skip_validation,
- url_validation=ValidationMode.NO_CHECK)
+ project = ElbeProject(args[0],
+ override_buildtype=opt.buildtype,
+ skip_validate=opt.skip_validation,
+ url_validation=ValidationMode.NO_CHECK)
except ValidationError as e:
print(str(e))
print("xml validation failed. Bailing out")
diff --git a/elbepack/commands/hdimg.py b/elbepack/commands/hdimg.py
index bff79d7c..d184e77b 100644
--- a/elbepack/commands/hdimg.py
+++ b/elbepack/commands/hdimg.py
@@ -70,7 +70,7 @@ def run_command(argv):
log.new(opt.output)
project = ElbeProject(opt.target,
override_buildtype=opt.buildtype,
- xmlpath=args[0], logpath=opt.output,
+ xmlpath=args[0],
skip_validate=opt.skip_validation)
except ValidationError as e:
print(str(e))
diff --git a/elbepack/commands/mkcdrom.py b/elbepack/commands/mkcdrom.py
index dc6806e2..966e178e 100644
--- a/elbepack/commands/mkcdrom.py
+++ b/elbepack/commands/mkcdrom.py
@@ -68,7 +68,7 @@ def run_command(argv):
if not opt.rfs_only:
try:
- project = ElbeProject(args[0], logpath=opt.log,
+ project = ElbeProject(args[0],
override_buildtype=opt.buildtype,
skip_validate=opt.skip_validation)
except ValidationError as e:
diff --git a/elbepack/db.py b/elbepack/db.py
index df4e89e9..8f841ea3 100644
--- a/elbepack/db.py
+++ b/elbepack/db.py
@@ -492,8 +492,9 @@ class ElbeDB(object):
p = s.query(Project). \
filter(Project.builddir == builddir).one()
+
log.new(os.path.join(builddir, "log.txt"))
- return ElbeProject(p.builddir, name=p.name, logpath=logpath,
+ return ElbeProject(p.builddir, name=p.name,
postbuild_file=postbuild_file,
presh_file=presh_file,
postsh_file=postsh_file,
diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
index 6862a258..3c9eacc2 100644
--- a/elbepack/elbeproject.py
+++ b/elbepack/elbeproject.py
@@ -13,8 +13,7 @@ import os
import datetime
import io
-from elbepack.asciidoclog import ASCIIDocLog, StdoutLog
-from elbepack.shellhelper import CommandError
+from elbepack.shellhelper import CommandError, do
from elbepack.elbexml import (ElbeXML, NoInitvmNode,
ValidationError, ValidationMode)
@@ -37,6 +36,7 @@ from elbepack.repomanager import ProjectRepo
from elbepack.config import cfg
from elbepack.templates import write_pack_template
from elbepack.finetuning import do_prj_finetuning
+from elbepack.log import log
class IncompatibleArchitectureException(Exception):
@@ -112,21 +112,18 @@ class ElbeProject (object):
# pylint: disable=too-many-instance-attributes
- def __init__(
- self,
- builddir,
- xmlpath=None,
- logpath=None,
- name=None,
- override_buildtype=None,
- skip_validate=False,
- url_validation=ValidationMode.CHECK_ALL,
- rpcaptcache_notifier=None,
- private_data=None,
- postbuild_file=None,
- presh_file=None,
- postsh_file=None,
- savesh_file=None):
+ def __init__(self, builddir,
+ xmlpath=None,
+ name=None,
+ override_buildtype=None,
+ skip_validate=False,
+ url_validation=ValidationMode.CHECK_ALL,
+ rpcaptcache_notifier=None,
+ private_data=None,
+ postbuild_file=None,
+ presh_file=None,
+ postsh_file=None,
+ savesh_file=None):
# pylint: disable=too-many-arguments
@@ -179,13 +176,6 @@ class ElbeProject (object):
if not self.name:
self.name = self.xml.text("project/name")
- # If logpath is given, use an AsciiDocLog instance, otherwise log
- # to stdout
- if logpath:
- self.log = ASCIIDocLog(logpath)
- else:
- self.log = StdoutLog()
-
self.repo = ProjectRepo(self.arch, self.codename,
os.path.join(self.builddir, "repo"))
@@ -209,13 +199,13 @@ class ElbeProject (object):
# each time, because the pkglist including the -dev packages is
# tracked nowhere.
self.sysrootenv = None
- self.log.do('rm -rf %s' % self.sysrootpath)
+ do('rm -rf %s' % self.sysrootpath)
# same for host_sysroot instance recreate it in any case
self.host_sysrootenv = None
def build_chroottarball(self):
- self.log.do("tar cJf %s/chroot.tar.xz \
+ do("tar cJf %s/chroot.tar.xz \
--exclude=./tmp/* --exclude=./dev/* \
--exclude=./run/* --exclude=./sys/* \
--exclude=./proc/* --exclude=./var/cache/* \
@@ -245,15 +235,15 @@ class ElbeProject (object):
def build_sysroot(self):
- self.log.do('rm -rf %s; mkdir "%s"' % (self.sysrootpath,
- self.sysrootpath))
+ do('rm -rf %s; mkdir "%s"' % (self.sysrootpath,
+ self.sysrootpath))
self.sysrootenv = BuildEnv(self.xml,
self.sysrootpath,
clean=True)
# Import keyring
self.sysrootenv.import_keys()
- self.log.printo("Keys imported")
+ log.info("Keys imported")
self.install_packages(self.sysrootenv, buildenv=False)
@@ -277,36 +267,35 @@ class ElbeProject (object):
env=self.sysrootenv).mark_install_devpkgs(
set(ignore_pkgs), set(ignore_dev_pkgs))
except SystemError as e:
- self.log.printo("mark install devpkgs failed: %s" % str(e))
+ log.error("mark install devpkgs failed: %s" % e)
try:
self.get_rpcaptcache(env=self.sysrootenv).commit()
except SystemError as e:
- self.log.printo("commiting changes failed: %s" % str(e))
+ log.error("commiting changes failed: %s" % e)
raise AptCacheCommitError(str(e))
try:
self.sysrootenv.rfs.dump_elbeversion(self.xml)
except IOError:
- self.log.printo("dump elbeversion into sysroot failed")
+ log.error("dump elbeversion into sysroot failed")
sysrootfilelist = os.path.join(self.builddir, "sysroot-filelist")
with self.sysrootenv.rfs:
- self.log.do("chroot %s /usr/bin/symlinks -cr /usr/lib" %
- self.sysrootpath)
+ do("chroot %s /usr/bin/symlinks -cr /usr/lib" % self.sysrootpath)
paths = self.get_sysroot_paths()
- self.log.do("rm %s" % sysrootfilelist, allow_fail=True)
+ do("rm %s" % sysrootfilelist, allow_fail=True)
os.chdir(self.sysrootpath)
for p in paths:
- self.log.do('find -path "%s" >> %s' % (p, sysrootfilelist))
+ do('find -path "%s" >> %s' % (p, sysrootfilelist))
- self.log.do("tar cfJ %s/sysroot.tar.xz -C %s -T %s" %
+ do("tar cfJ %s/sysroot.tar.xz -C %s -T %s" %
(self.builddir, self.sysrootpath, sysrootfilelist))
def build_host_sysroot(self, pkgs, hostsysrootpath):
- self.log.do('rm -rf %s; mkdir "%s"' % (hostsysrootpath,
+ do('rm -rf %s; mkdir "%s"' % (hostsysrootpath,
hostsysrootpath))
self.host_sysrootenv = BuildEnv(self.xml,
@@ -315,7 +304,7 @@ class ElbeProject (object):
arch="amd64")
# Import keyring
self.host_sysrootenv.import_keys()
- self.log.printo("Keys imported")
+ log.info("Key imported")
with self.host_sysrootenv:
@@ -331,15 +320,15 @@ class ElbeProject (object):
try:
cache.mark_install(p, None)
except KeyError:
- self.log.printo("No Package " + p)
+ log.error("No Package " + p)
except SystemError as e:
- self.log.printo("Error: Unable to correct problems "
- "in package %s (%s)" % (p, str(e)))
+ log.error("Error: Unable to correct problems "
+ "in package %s (%s)" % (p, e))
try:
cache.commit()
except SystemError as e:
- self.log.printo("commiting changes failed: %s" % str(e))
+ log.error("commiting changes failed: %s" % e)
raise AptCacheCommitError(str(e))
# This is just a sysroot, some directories
@@ -380,8 +369,8 @@ class ElbeProject (object):
# build target sysroot including libs and headers for the target
self.build_sysroot()
sdktargetpath = os.path.join(self.sdkpath, "sysroots", "target")
- self.log.do("mkdir -p %s" % sdktargetpath)
- self.log.do("tar xJf %s/sysroot.tar.xz -C %s" % (self.builddir,
+ do("mkdir -p %s" % sdktargetpath)
+ do("tar xJf %s/sysroot.tar.xz -C %s" % (self.builddir,
sdktargetpath))
# build host sysroot including cross compiler
hostsysrootpath = os.path.join(self.sdkpath, 'sysroots', 'host')
@@ -396,30 +385,30 @@ class ElbeProject (object):
self.sdkpath)
# create sdk tar and append it to setup script
- self.log.do("cd %s; tar cJf ../sdk.txz ." % self.sdkpath)
- self.log.do("cd %s; rm -rf sdk" % self.builddir)
- self.log.do("cd %s; cat sdk.txz >> %s" % (self.builddir, n))
- self.log.do("cd %s; chmod +x %s" % (self.builddir, n))
- self.log.do("cd %s; rm sdk.txz" % self.builddir)
+ do("cd %s; tar cJf ../sdk.txz ." % self.sdkpath)
+ do("cd %s; rm -rf sdk" % self.builddir)
+ do("cd %s; cat sdk.txz >> %s" % (self.builddir, n))
+ do("cd %s; chmod +x %s" % (self.builddir, n))
+ do("cd %s; rm sdk.txz" % self.builddir)
def pbuild(self, p):
self.pdebuild_init()
src_path = os.path.join(self.builddir, "pdebuilder", "current")
src_uri = p.text('.').replace("LOCALMACHINE", "10.0.2.2").strip()
- self.log.printo("retrieve pbuild sources: %s" % src_uri)
+ log.info("retrieve pbuild sources: %s" % src_uri)
if p.tag == 'git':
- self.log.do("git clone %s %s" % (src_uri, src_path))
+ do("git clone %s %s" % (src_uri, src_path))
try:
- self.log.do(
+ do(
"cd %s; git reset --hard %s" %
(src_path, p.et.attrib['revision']))
except IndexError:
pass
elif p.tag == 'svn':
- self.log.do("svn co --non-interactive %s %s" % (src_uri, src_path))
+ do("svn co --non-interactive %s %s" % (src_uri, src_path))
else:
- self.log.printo("unknown pbuild source vcs: %s" % p.tag)
+ log.info("unknown pbuild source vcs: %s" % p.tag)
# pdebuild_build(-1) means use all cpus
self.pdebuild_build(cpuset=-1, profile="")
@@ -473,6 +462,7 @@ class ElbeProject (object):
# e.g. no deb-src urls specified
log.error(str(e))
+
def build(self, build_bin=False, build_sources=False, cdrom_size=None,
skip_pkglist=False, skip_pbuild=False):
@@ -512,14 +502,14 @@ class ElbeProject (object):
# However, if its not a full_buildenv, we specify clean here,
# so it gets rebuilt properly.
if not self.has_full_buildenv():
- self.log.do('mkdir -p "%s"' % self.chrootpath)
+ do('mkdir -p "%s"' % self.chrootpath)
self.buildenv = BuildEnv(self.xml, self.chrootpath,
build_sources=build_sources, clean=True)
skip_pkglist = False
# Import keyring
self.buildenv.import_keys()
- self.log.printo("Keys imported")
+ log.info("Keys imported")
# Install packages
if not skip_pkglist:
@@ -528,7 +518,7 @@ class ElbeProject (object):
try:
self.buildenv.rfs.dump_elbeversion(self.xml)
except IOError:
- self.log.printo("dump elbeversion failed")
+ log.error("dump elbeversion failed")
# Extract target FS. We always create a new instance here with
# clean=true, because we want a pristine directory.
@@ -558,7 +548,7 @@ class ElbeProject (object):
try:
self.targetfs.dump_elbeversion(self.xml)
except MemoryError:
- self.log.printo("dump elbeversion failed")
+ log.error("dump elbeversion failed")
# install packages for buildenv
if not skip_pkglist:
@@ -569,7 +559,7 @@ class ElbeProject (object):
sourcexmlpath = os.path.join(self.builddir, "source.xml")
self.xml.xml.write(sourcexmlpath)
except MemoryError:
- self.log.printo("write source.xml failed (archive to huge?)")
+ log.error("write source.xml failed (archive to huge?)")
# Elbe report
reportpath = os.path.join(self.builddir, "elbe-report.txt")
@@ -590,8 +580,8 @@ class ElbeProject (object):
self.buildenv.rfs.write_licenses(f,
os.path.join(self.builddir, "licence.xml"))
except Exception:
- self.log.printo("error during generating licence.txt/xml")
- self.log.printo(sys.exc_info()[0])
+ log.error(sys.exc_info()[0],
+ header="error during generating licence.txt/xml")
lic_err = True
finally:
f.close()
@@ -617,12 +607,12 @@ class ElbeProject (object):
grub_version = 202
grub_fw_type = "efi"
elif self.get_rpcaptcache().is_installed('grub-legacy'):
- self.log.printo("package grub-legacy is installed, "
- "this is obsolete, skipping grub")
+ log.warning("package grub-legacy is installed, "
+ "this is obsolete, skipping grub")
grub_version = 0
grub_fw_type = ""
else:
- self.log.printo("package grub-pc is not installed, skipping grub")
+ log.warning("package grub-pc is not installed, skipping grub")
# version 0 == skip_grub
grub_version = 0
grub_fw_type = ""
@@ -631,8 +621,8 @@ class ElbeProject (object):
self.build_cdroms(build_bin, build_sources, cdrom_size)
if self.postbuild_file:
- self.log.h2("postbuild script:")
- self.log.do(self.postbuild_file + ' "%s %s %s"' % (
+ log.h2("postbuild script:")
+ do(self.postbuild_file + ' "%s %s %s"' % (
self.builddir,
self.xml.text("project/version"),
self.xml.text("project/name")),
@@ -649,27 +639,27 @@ class ElbeProject (object):
def pdebuild_init(self):
# Remove pdebuilder directory, containing last build results
- self.log.do('rm -rf "%s"' % os.path.join(self.builddir,
+ do('rm -rf "%s"' % os.path.join(self.builddir,
"pdebuilder"))
# Remove pbuilder/result directory
- self.log.do('rm -rf "%s"' % os.path.join(self.builddir,
+ do('rm -rf "%s"' % os.path.join(self.builddir,
"pbuilder", "result"))
# Recreate the directories removed
- self.log.do('mkdir -p "%s"' % os.path.join(self.builddir,
+ do('mkdir -p "%s"' % os.path.join(self.builddir,
"pbuilder", "result"))
def pdebuild(self, cpuset, profile):
self.pdebuild_init()
pbdir = os.path.join(self.builddir, "pdebuilder", "current")
- self.log.do('mkdir -p "%s"' % os.path.join(pbdir))
+ do('mkdir -p "%s"' % os.path.join(pbdir))
try:
for orig_fname in self.orig_files:
ofname = os.path.join(self.builddir, orig_fname)
- self.log.do('mv "%s" "%s"' % (ofname,
+ do('mv "%s" "%s"' % (ofname,
os.path.join(self.builddir,
"pdebuilder")))
finally:
@@ -677,7 +667,7 @@ class ElbeProject (object):
self.orig_files = []
# Untar current_pdebuild.tar.gz into pdebuilder/current
- self.log.do(
+ do(
'tar xfz "%s" -C "%s"' %
(os.path.join(
self.builddir,
@@ -699,7 +689,7 @@ class ElbeProject (object):
cpuset_cmd = ''
try:
- self.log.do('cd "%s"; %s pdebuild --debbuildopts "-j%s -sa" '
+ do('cd "%s"; %s pdebuild --debbuildopts "-j%s -sa" '
'--configfile "%s" '
'--use-pdebuild-internal --buildresult "%s"' % (
os.path.join(self.builddir,
@@ -720,13 +710,12 @@ class ElbeProject (object):
self.repo.include(os.path.join(self.builddir,
"pbuilder", "result", "*.changes"))
except CommandError:
- self.log.printo('')
- self.log.printo('Package fails to build.')
- self.log.printo('Please make sure, that the submitted package '
- 'builds in pbuilder')
+ log.error("Package fails to build.\n"
+ "Please make sure, that the submitted package "
+ "builds in pbuilder")
def update_pbuilder(self):
- self.log.do(
+ do(
'pbuilder --update --configfile "%s" --aptconfdir "%s"' %
(os.path.join(
self.builddir, "pbuilderrc"), os.path.join(
@@ -734,22 +723,22 @@ class ElbeProject (object):
def create_pbuilder(self):
# Remove old pbuilder directory, if it exists
- self.log.do('rm -rf "%s"' % os.path.join(self.builddir, "pbuilder"))
+ do('rm -rf "%s"' % os.path.join(self.builddir, "pbuilder"))
# make hooks.d and pbuilder directory
- self.log.do(
+ do(
'mkdir -p "%s"' %
os.path.join(
self.builddir,
"pbuilder",
"hooks.d"))
- self.log.do(
+ do(
'mkdir -p "%s"' %
os.path.join(
self.builddir,
"pbuilder",
"aptcache"))
- self.log.do(
+ do(
'mkdir -p "%s"' %
os.path.join(
self.builddir,
@@ -760,7 +749,7 @@ class ElbeProject (object):
pbuilder_write_config(self.builddir, self.xml)
pbuilder_write_apt_conf(self.builddir, self.xml)
pbuilder_write_repo_hook(self.builddir, self.xml)
- self.log.do(
+ do(
'chmod -R 755 "%s"' %
os.path.join(
self.builddir,
@@ -768,7 +757,7 @@ class ElbeProject (object):
"hooks.d"))
# Run pbuilder --create
- self.log.do('pbuilder --create --configfile "%s" --aptconfdir "%s" '
+ do('pbuilder --create --configfile "%s" --aptconfdir "%s" '
'--debootstrapopts --include="git gnupg2"' % (
os.path.join(self.builddir, "pbuilderrc"),
os.path.join(self.builddir, "aptconfdir")))
@@ -778,7 +767,7 @@ class ElbeProject (object):
sourcexmlpath = os.path.join(self.builddir, "source.xml")
self.xml.xml.write(sourcexmlpath)
except MemoryError:
- self.log.printo("write source.xml failed (archive to huge?)")
+ log.error("write source.xml failed (archive to huge?)")
def get_rpcaptcache(self, env=None, norecommend=None):
if not env:
@@ -811,8 +800,8 @@ class ElbeProject (object):
if os.path.isfile(elbeversionpath):
return True
- self.log.printo("%s exists, but it does not have "
- "an etc/elbe_version file." % self.chrootpath)
+ log.warning("%s exists, but it does not have "
+ "an etc/elbe_version file." % self.chrootpath)
# Apparently we do not have a functional build environment
return False
@@ -841,7 +830,7 @@ class ElbeProject (object):
# each time, because the pkglist including the -dev packages is
# tracked nowhere.
self.sysrootenv = None
- self.log.do('rm -rf %s' % self.sysrootpath)
+ do('rm -rf %s' % self.sysrootpath)
self.xml = newxml
@@ -861,12 +850,12 @@ class ElbeProject (object):
self.targetfs = None
def write_log_header(self):
+ header = "ELBE Report"
if self.name:
- self.log.h1("ELBE Report for Project " + self.name)
- else:
- self.log.h1("ELBE Report")
- self.log.printo("report timestamp: " +
- datetime.datetime.now().strftime("%Y%m%d-%H%M%S"))
+ header += " for Project %s" % self.name
+ now = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
+ log.info("Report timestamp: %s" % now,
+ header=header)
def install_packages(self, target, buildenv=False):
@@ -889,22 +878,21 @@ class ElbeProject (object):
target.need_dumpdebootstrap = False
source = self.xml
try:
- initxml = ElbeXML(
- "/var/cache/elbe/source.xml",
- skip_validate=self.skip_validate,
- url_validation=ValidationMode.NO_CHECK)
+ source = "/var/cache/elbe/source.xml"
+ initxml = ElbeXML(source,
+ skip_validate=self.skip_validate,
+ url_validation=ValidationMode.NO_CHECK)
self.xml.get_initvmnode_from(initxml)
except ValidationError as e:
- self.log.printo(
- "/var/cache/elbe/source.xml validation failed")
- self.log.printo(str(e))
- self.log.printo("will not copy initvm node")
+ log.error(str(e),
+ header="%s validation failed" % source,
+ footer="will not copy initvm node")
except IOError:
- self.log.printo("/var/cache/elbe/source.xml not available")
- self.log.printo("can not copy initvm node")
+ log.error("can not copy initvm node",
+ header="%s not available" % source)
except NoInitvmNode:
- self.log.printo("/var/cache/elbe/source.xml is available")
- self.log.printo("But it does not contain an initvm node")
+ log.error("But it does not contain an initvm node",
+ header="%s is available" % source)
else:
sourcepath = os.path.join(self.builddir, "source.xml")
source = ElbeXML(sourcepath,
@@ -916,8 +904,8 @@ class ElbeProject (object):
try:
self.xml.get_initvmnode_from(source)
except NoInitvmNode:
- self.log.printo("source.xml is available")
- self.log.printo("But it does not contain an initvm node")
+ log.error("But it does not contain an initvm node",
+ header="source.xml is available")
# Seed /etc, we need /etc/hosts for hostname -f to work correctly
if not buildenv:
@@ -939,10 +927,10 @@ class ElbeProject (object):
try:
self.get_rpcaptcache(env=target).mark_install(p, None)
except KeyError:
- self.log.printo("No Package " + p)
+ log.error("No package " + p)
except SystemError as e:
- self.log.printo("Error: Unable to correct problems in "
- "package %s (%s)" % (p, str(e)))
+ log.error(str(e),
+ header="Error: Unable to correct problems in package %s" % p)
# temporary disabled because of
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=776057
@@ -952,5 +940,5 @@ class ElbeProject (object):
try:
self.get_rpcaptcache(env=target).commit()
except SystemError as e:
- self.log.printo("commiting changes failed: %s" % str(e))
+ log.error(str(e), header="Commiting changes failed")
raise AptCacheCommitError(str(e))
--
2.11.0
More information about the elbe-devel
mailing list