Gate Unix-specific functionality from resources and fcntl.
authorWilliam D. Jones <thor0505@comcast.net>
Sun, 10 Mar 2019 05:43:55 +0000 (00:43 -0500)
committerWilliam D. Jones <thor0505@comcast.net>
Sun, 10 Mar 2019 05:43:55 +0000 (00:43 -0500)
Signed-off-by: William D. Jones <thor0505@comcast.net>
sbysrc/sby_core.py

index e572f5cb77eb263de9bc6a6a470ccef880fe7a24..1f56b1ad340d21ecb28597f1984cc2dc752a4bac 100644 (file)
 # 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)" %