Minimum-modification change for stdin support
authorAndrew Wygle <awygle@gmail.com>
Fri, 24 Nov 2017 17:39:41 +0000 (09:39 -0800)
committerAndrew Wygle <awygle@gmail.com>
Fri, 24 Nov 2017 17:57:23 +0000 (09:57 -0800)
sbysrc/sby.py
sbysrc/sby_core.py

index 922513b9e29229e2f33d9bdf043a3042b4c0ce59..ba0d80a59ebbf70096266787f33726224415aa88 100644 (file)
@@ -17,7 +17,7 @@
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #
 
-import os, sys, getopt, shutil
+import os, sys, getopt, shutil, tempfile
 ##yosys-sys-path##
 from sby_core import SbyJob
 
@@ -29,7 +29,7 @@ exe_paths = dict()
 
 def usage():
     print("""
-sby [options] <jobname>.sby
+sby [options] [<jobname>.sby]
 
     -d <dirname>
         set workdir name. default: <jobname> (without .sby)
@@ -78,10 +78,13 @@ for o, a in opts:
     else:
         usage()
 
-if len(args) != 1:
+if len(args) > 1:
     usage()
 
-sbyfile = args[0]
+if len(args) == 1:
+    sbyfile = args[0]
+    assert sbyfile.endswith(".sby")
+
 early_logmsgs = list()
 
 def early_log(msg):
@@ -89,8 +92,10 @@ def early_log(msg):
     print(early_logmsgs[-1])
 
 if workdir is None:
-    assert sbyfile.endswith(".sby")
-    workdir = sbyfile[:-4]
+    if sbyfile:
+        workdir = sbyfile[:-4]
+    else:
+        workdir = tempfile.mkdtemp()
 
 if opt_backup:
     backup_idx = 0
@@ -101,7 +106,11 @@ if opt_backup:
 
 if opt_force:
     early_log("Removing direcory '%s'." % (workdir))
-    shutil.rmtree(workdir, ignore_errors=True)
+    if sbyfile:
+        shutil.rmtree(workdir, ignore_errors=True)
+
+if sbyfile:
+    os.makedirs(workdir)
 
 job = SbyJob(sbyfile, workdir, early_logmsgs)
 
@@ -110,5 +119,8 @@ for k, v in exe_paths.items():
 
 job.run()
 
+if not sbyfile:
+    shutil.rmtree(workdir, ignore_errors=True)
+
 sys.exit(job.retcode)
 
index 9f264be1dc13e8d45f6eda7a4d479073f4e2e050..a287525cc13ca9dd58a2a7a7e8a9dc279c3b6da3 100644 (file)
@@ -16,7 +16,7 @@
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #
 
-import os, re, resource
+import os, re, resource, sys
 import subprocess, fcntl
 from shutil import copyfile
 from select import select
@@ -157,7 +157,6 @@ class SbyJob:
         self.logprefix = "SBY [%s]" % self.workdir
         self.summary = list()
 
-        os.makedirs(workdir)
         self.logfile = open("%s/logfile.txt" % workdir, "w")
 
         for line in early_logs:
@@ -167,7 +166,7 @@ class SbyJob:
         mode = None
         key = None
 
-        with open(filename, "r") as f:
+        with (open(filename, "r") if filename else sys.stdin) as f:
             with open("%s/config.sby" % workdir, "w") as cfgfile:
                 pycode = None
                 for line in f: