From 43c7db77d4ea5cc05ea1e6fb26baca3690bd7ebd Mon Sep 17 00:00:00 2001 From: "William D. Jones" Date: Sun, 10 Mar 2019 00:43:55 -0500 Subject: [PATCH 1/3] Gate Unix-specific functionality from resources and fcntl. Signed-off-by: William D. Jones --- sbysrc/sby_core.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/sbysrc/sby_core.py b/sbysrc/sby_core.py index e572f5c..1f56b1a 100644 --- a/sbysrc/sby_core.py +++ b/sbysrc/sby_core.py @@ -16,8 +16,10 @@ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # -import os, re, resource, sys -import subprocess, fcntl +import os, re, sys +if os.name == "posix": + import resource, fcntl +import subprocess from shutil import copyfile from select import select from time import time, localtime @@ -91,8 +93,9 @@ class SbyTask: self.job.log("%s: starting process \"%s\"" % (self.info, self.cmdline)) self.p = subprocess.Popen(self.cmdline, shell=True, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=(subprocess.STDOUT if self.logstderr else None)) - fl = fcntl.fcntl(self.p.stdout, fcntl.F_GETFL) - fcntl.fcntl(self.p.stdout, fcntl.F_SETFL, fl | os.O_NONBLOCK) + if os.name == "posix": + fl = fcntl.fcntl(self.p.stdout, fcntl.F_GETFL) + fcntl.fcntl(self.p.stdout, fcntl.F_SETFL, fl | os.O_NONBLOCK) self.job.tasks_pending.remove(self) self.job.tasks_running.append(self) self.running = True @@ -161,8 +164,9 @@ class SbyJob: self.start_clock_time = time() - ru = resource.getrusage(resource.RUSAGE_CHILDREN) - self.start_process_time = ru.ru_utime + ru.ru_stime + if os.name == "posix": + ru = resource.getrusage(resource.RUSAGE_CHILDREN) + self.start_process_time = ru.ru_utime + ru.ru_stime self.summary = list() @@ -565,9 +569,12 @@ class SbyJob: total_clock_time = int(time() - self.start_clock_time) - ru = resource.getrusage(resource.RUSAGE_CHILDREN) - total_process_time = int((ru.ru_utime + ru.ru_stime) - self.start_process_time) - self.total_time = total_process_time + if os.name == "posix": + ru = resource.getrusage(resource.RUSAGE_CHILDREN) + total_process_time = int((ru.ru_utime + ru.ru_stime) - self.start_process_time) + self.total_time = total_process_time + else: + total_process_time = 0 self.summary = [ "Elapsed clock time [H:MM:SS (secs)]: %d:%02d:%02d (%d)" % From b5eb5b3c7837ba7565a06d5079d23b86cc1b85b0 Mon Sep 17 00:00:00 2001 From: "William D. Jones" Date: Fri, 15 Mar 2019 23:14:12 -0400 Subject: [PATCH 2/3] Choose command separator for tasks based on OS. Signed-off-by: William D. Jones --- sbysrc/sby_core.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sbysrc/sby_core.py b/sbysrc/sby_core.py index 7db60c8..608cca1 100644 --- a/sbysrc/sby_core.py +++ b/sbysrc/sby_core.py @@ -33,7 +33,19 @@ class SbyTask: self.job = job self.info = info self.deps = deps - self.cmdline = cmdline + if os.name == "posix": + self.cmdline = cmdline + else: + replacements = { + ";" : "&", + "{" : "(", + "}" : ")", + } + + cmdline_copy = cmdline + for u, w in replacements.items(): + cmdline_copy = cmdline_copy.replace(u, w) + self.cmdline = cmdline_copy self.logfile = logfile self.noprintregex = None self.notify = [] From f8e27a06aa72951744078f0865591822286550af Mon Sep 17 00:00:00 2001 From: "William D. Jones" Date: Mon, 18 Mar 2019 00:46:06 -0400 Subject: [PATCH 3/3] Annotate cmdline comment, summary string, and output XML with OS-specific information. --- sbysrc/sby.py | 4 +++- sbysrc/sby_core.py | 22 ++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/sbysrc/sby.py b/sbysrc/sby.py index 13d1cd1..4680b00 100644 --- a/sbysrc/sby.py +++ b/sbysrc/sby.py @@ -364,6 +364,9 @@ def run_job(taskname): print('', file=f) print('' % (junit_errors, junit_failures, job.total_time), file=f) print('' % (junit_errors, junit_failures, junit_ts_name, job.total_time), file=f) + print('', file=f) + print('' % os.name, file=f) + print('', file=f) print('' % (junit_ts_name, junit_tc_name, job.status, job.total_time), file=f) if junit_errors: print('' % (job.status, job.status), file=f) @@ -385,4 +388,3 @@ for t in tasknames: retcode |= run_job(t) sys.exit(retcode) - diff --git a/sbysrc/sby_core.py b/sbysrc/sby_core.py index 608cca1..631524c 100644 --- a/sbysrc/sby_core.py +++ b/sbysrc/sby_core.py @@ -36,6 +36,8 @@ class SbyTask: if os.name == "posix": self.cmdline = cmdline else: + # Windows command interpreter equivalents for sequential + # commands (; => &) command grouping ({} => ()). replacements = { ";" : "&", "{" : "(", @@ -598,15 +600,19 @@ class SbyJob: ru = resource.getrusage(resource.RUSAGE_CHILDREN) total_process_time = int((ru.ru_utime + ru.ru_stime) - self.start_process_time) self.total_time = total_process_time - else: - total_process_time = 0 - self.summary = [ - "Elapsed clock time [H:MM:SS (secs)]: %d:%02d:%02d (%d)" % - (total_clock_time // (60*60), (total_clock_time // 60) % 60, total_clock_time % 60, total_clock_time), - "Elapsed process time [H:MM:SS (secs)]: %d:%02d:%02d (%d)" % - (total_process_time // (60*60), (total_process_time // 60) % 60, total_process_time % 60, total_process_time), - ] + self.summary + self.summary = [ + "Elapsed clock time [H:MM:SS (secs)]: %d:%02d:%02d (%d)" % + (total_clock_time // (60*60), (total_clock_time // 60) % 60, total_clock_time % 60, total_clock_time), + "Elapsed process time [H:MM:SS (secs)]: %d:%02d:%02d (%d)" % + (total_process_time // (60*60), (total_process_time // 60) % 60, total_process_time % 60, total_process_time), + ] + self.summary + else: + self.summary = [ + "Elapsed clock time [H:MM:SS (secs)]: %d:%02d:%02d (%d)" % + (total_clock_time // (60*60), (total_clock_time // 60) % 60, total_clock_time % 60, total_clock_time), + "Elapsed process time unvailable on Windows" + ] + self.summary for line in self.summary: self.log("summary: %s" % line)