[elbe-devel] [PATCH v2 03/28] ASCIIDocLog compatible with new logging system
dion at linutronix.de
dion at linutronix.de
Fri Jun 21 19:39:55 CEST 2019
From: Olivier Dion <dion at linutronix.de>
By changing the definitions of 'ASCIIDocLog::*', it's possible to use
the new logging system already, without changing anything else.
Of course, the logging objects has to be initialize first.
Signed-off-by: Olivier Dion <dion at linutronix.de>
---
elbepack/asciidoclog.py | 116 +++++++++++++-----------------------------------
1 file changed, 30 insertions(+), 86 deletions(-)
diff --git a/elbepack/asciidoclog.py b/elbepack/asciidoclog.py
index ad899feb..322e037d 100644
--- a/elbepack/asciidoclog.py
+++ b/elbepack/asciidoclog.py
@@ -7,117 +7,61 @@
import os
import sys
+import logging
-from elbepack.shellhelper import CommandError, command_out_stderr, command_out
+from elbepack.shellhelper import get_command_out, do, chroot
+class CommandError(Exception):
+ def __init__(self, cmd, returncode):
+ Exception.__init__(self)
+ self.returncode = returncode
+ self.cmd = cmd
-class LogBase(object):
- def __init__(self, fp):
- self.fp = fp
+ def __repr__(self):
+ return "Error: %d returned from Command %s" % (
+ self.returncode, self.cmd)
+
+
+
+class LogBase():
+ def __init__(self, *args, **kwargs):
+ pass
def printo(self, text=""):
- self.fp.write("%s\n" % str(text))
+ logging.debug(text)
def print_raw(self, text):
- self.fp.write(text)
+ self.printo(text)
def h1(self, text):
- self.printo()
self.printo(text)
- self.printo("=" * len(str(text)))
- self.printo()
def h2(self, text):
- self.printo()
self.printo(text)
- self.printo("-" * len(str(text)))
- self.printo()
def table(self):
- self.printo("|=====================================")
+ pass
def verbatim_start(self):
- self.printo("---------------------------------------"
- "---------------------------------------")
+ pass
def verbatim_end(self):
- self.printo("---------------------------------------"
- "---------------------------------------")
- self.printo()
-
- def do(self, cmd, allow_fail=False, stdin=None, env_add=None):
-
- if stdin is None:
- self.printo("running cmd +%s+" % cmd)
- else:
- self.printo("running cmd +%s with STDIN %s+" % (cmd, stdin))
-
- self.verbatim_start()
- ret, _ = command_out(cmd, stdin=stdin, output=self.fp, env_add=env_add)
- self.verbatim_end()
-
- if ret != 0:
- self.printo("Command failed with errorcode %d" % ret)
- if not allow_fail:
- raise CommandError(cmd, ret)
-
- def chroot(self, directory, cmd, **args):
- os.environ["LANG"] = "C"
- os.environ["LANGUAGE"] = "C"
- os.environ["LC_ALL"] = "C"
-
- chcmd = "chroot %s %s" % (directory, cmd)
- self.do(chcmd, **args)
-
- def get_command_out(self, cmd, allow_fail=False):
-
- self.printo("getting output from cmd +%s+" % cmd)
-
- ret, output, stderr = command_out_stderr(cmd)
-
- if stderr:
- self.verbatim_start()
- self.print_raw(stderr)
- self.verbatim_end()
+ pass
- if ret != 0:
- self.printo("Command failed with errorcode %d" % ret)
- if not allow_fail:
- raise CommandError(cmd, ret)
+ def do(self, cmd, **kwargs):
+ return do(cmd, **kwargs)
- return output
+ def chroot(self, directory, cmd, **kwargs):
+ return chroot(directory, cmd, **kwargs)
+ def get_command_out(self, cmd, **kwargs):
+ return get_command_out(cmd, **kwargs)
class ASCIIDocLog (LogBase):
- def __init__(self, fname, append=False):
- self.fname = fname
- if append:
- fp = file(fname, "a", 0)
- else:
- if os.path.isfile(fname):
- os.unlink(fname)
- fp = file(fname, "w", 0)
-
- LogBase.__init__(self, fp)
-
- def reset(self):
- self.fp.close()
- if os.path.isfile(self.fname):
- os.unlink(self.fname)
- self.fp = file(self.fname, "w", 0)
-
+ pass
class StdoutLog(LogBase):
- def __init__(self):
- LogBase.__init__(self, sys.stdout)
-
- def reset(self):
- pass
-
+ pass
class StderrLog(LogBase):
- def __init__(self):
- LogBase.__init__(self, sys.stderr)
-
- def reset(self):
- pass
+ pass
--
2.11.0
More information about the elbe-devel
mailing list