From d332f2c52192144d6205b68a1a2888eb63e9efb1 Mon Sep 17 00:00:00 2001 From: Luca Ceresoli Date: Wed, 10 May 2017 23:33:46 +0200 Subject: support/testing: simplify logging by keeping the log file open We currently call infra.smart_open() to open log files each time we need to write to them. Opening the file once in the constructor of Builder and Emulator and writing to it whenever needed is simpler and slightly more efficient. Remove smart_open and instead create a new open_log_file() function which just opens the logfile. Also let it compute the filename, in order to simplify even further the Builder and Emulator code. Signed-off-by: Luca Ceresoli Signed-off-by: Thomas Petazzoni --- support/testing/infra/builder.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'support/testing/infra/builder.py') diff --git a/support/testing/infra/builder.py b/support/testing/infra/builder.py index 105da01ca2..a475bb0a30 100644 --- a/support/testing/infra/builder.py +++ b/support/testing/infra/builder.py @@ -8,16 +8,12 @@ class Builder(object): def __init__(self, config, builddir, logtofile): self.config = config self.builddir = builddir - self.logtofile = logtofile + self.logfile = infra.open_log_file(builddir, "build", logtofile) def build(self): if not os.path.isdir(self.builddir): os.makedirs(self.builddir) - log = "{}-build.log".format(self.builddir) - if not self.logtofile: - log = None - config_file = os.path.join(self.builddir, ".config") with open(config_file, "w+") as cf: cf.write(self.config) @@ -25,14 +21,12 @@ class Builder(object): cmd = ["make", "O={}".format(self.builddir), "olddefconfig"] - with infra.smart_open(log) as log_fh: - ret = subprocess.call(cmd, stdout=log_fh, stderr=log_fh) + ret = subprocess.call(cmd, stdout=self.logfile, stderr=self.logfile) if ret != 0: raise SystemError("Cannot olddefconfig") cmd = ["make", "-C", self.builddir] - with infra.smart_open(log) as log_fh: - ret = subprocess.call(cmd, stdout=log_fh, stderr=log_fh) + ret = subprocess.call(cmd, stdout=self.logfile, stderr=self.logfile) if ret != 0: raise SystemError("Build failed") -- cgit v1.2.3