From 20b8b8fe9fad93e1d6d25365d46301e6b077ba37 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Fri, 24 Nov 2017 20:12:58 +0100 Subject: [PATCH] Add "sby -t", improve handling of stdin --- sbysrc/sby.py | 45 +++++++++++++++++++++++++++------------------ sbysrc/sby_core.py | 2 -- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/sbysrc/sby.py b/sbysrc/sby.py index ba0d80a..e643173 100644 --- a/sbysrc/sby.py +++ b/sbysrc/sby.py @@ -25,6 +25,7 @@ sbyfile = None workdir = None opt_force = False opt_backup = False +opt_tmpdir = False exe_paths = dict() def usage(): @@ -40,6 +41,9 @@ sby [options] [.sby] -b backup workdir if it already exists + -t + run in a temporary workdir (remove when finished) + --yosys --abc --smtbmc @@ -51,7 +55,7 @@ sby [options] [.sby] sys.exit(1) try: - opts, args = getopt.getopt(sys.argv[1:], "d:bf", ["yosys=", + opts, args = getopt.getopt(sys.argv[1:], "d:btf", ["yosys=", "abc=", "smtbmc=", "suprove=", "aigbmc=", "avy="]) except: usage() @@ -63,6 +67,8 @@ for o, a in opts: opt_force = True elif o == "-b": opt_backup = True + elif o == "-t": + opt_tmpdir = True elif o == "--yosys": exe_paths["yosys"] = a elif o == "--abc": @@ -91,27 +97,28 @@ def early_log(msg): early_logmsgs.append("SBY [%s] %s" % (workdir, msg)) print(early_logmsgs[-1]) -if workdir is None: - if sbyfile: - workdir = sbyfile[:-4] - else: - workdir = tempfile.mkdtemp() +if workdir is None and sbyfile is not None and not opt_tmpdir: + workdir = sbyfile[:-4] -if opt_backup: - backup_idx = 0 - while os.path.exists("%s.bak%03d" % (workdir, backup_idx)): - backup_idx += 1 - early_log("Moving direcory '%s' to '%s'." % (workdir, "%s.bak%03d" % (workdir, backup_idx))) - shutil.move(workdir, "%s.bak%03d" % (workdir, backup_idx)) +if workdir is not None: + if opt_backup: + backup_idx = 0 + while os.path.exists("%s.bak%03d" % (workdir, backup_idx)): + backup_idx += 1 + early_log("Moving direcory '%s' to '%s'." % (workdir, "%s.bak%03d" % (workdir, backup_idx))) + shutil.move(workdir, "%s.bak%03d" % (workdir, backup_idx)) -if opt_force: - early_log("Removing direcory '%s'." % (workdir)) - if sbyfile: - shutil.rmtree(workdir, ignore_errors=True) + if opt_force: + early_log("Removing direcory '%s'." % (workdir)) + if sbyfile: + shutil.rmtree(workdir, ignore_errors=True) -if sbyfile: os.makedirs(workdir) +else: + opt_tmpdir = True + workdir = tempfile.mkdtemp() + job = SbyJob(sbyfile, workdir, early_logmsgs) for k, v in exe_paths.items(): @@ -119,8 +126,10 @@ for k, v in exe_paths.items(): job.run() -if not sbyfile: +if opt_tmpdir: + job.log("Removing direcory '%s'." % (workdir)) shutil.rmtree(workdir, ignore_errors=True) +job.log("DONE (%s, rc=%d)" % (job.status, job.retcode)) sys.exit(job.retcode) diff --git a/sbysrc/sby_core.py b/sbysrc/sby_core.py index a287525..9808485 100644 --- a/sbysrc/sby_core.py +++ b/sbysrc/sby_core.py @@ -520,8 +520,6 @@ class SbyJob: if self.status == "UNKNOWN": self.retcode = 4 if self.status == "TIMEOUT": self.retcode = 5 - self.log("DONE (%s, rc=%d)" % (self.status, self.retcode)) - with open("%s/%s" % (self.workdir, self.status), "w") as f: for line in self.summary: print(line, file=f) -- 2.30.2