From b7c33a72e9393ee25c984d1994ac7a2820829414 Mon Sep 17 00:00:00 2001 From: Andrew Wygle Date: Fri, 24 Nov 2017 09:39:41 -0800 Subject: [PATCH] Minimum-modification change for stdin support --- sbysrc/sby.py | 26 +++++++++++++++++++------- sbysrc/sby_core.py | 5 ++--- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/sbysrc/sby.py b/sbysrc/sby.py index 922513b..ba0d80a 100644 --- a/sbysrc/sby.py +++ b/sbysrc/sby.py @@ -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] .sby +sby [options] [.sby] -d set workdir name. default: (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) diff --git a/sbysrc/sby_core.py b/sbysrc/sby_core.py index 9f264be..a287525 100644 --- a/sbysrc/sby_core.py +++ b/sbysrc/sby_core.py @@ -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: -- 2.30.2