From 60b25ad13d0fdee926006bc728b031c4da1fb931 Mon Sep 17 00:00:00 2001 From: Michael Schwarz Date: Wed, 10 Dec 2014 22:18:14 +0100 Subject: Extracted common functions to separate module. --- support/lib/__init__.py | 0 support/lib/util.py | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 support/lib/__init__.py create mode 100644 support/lib/util.py (limited to 'support/lib') diff --git a/support/lib/__init__.py b/support/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/support/lib/util.py b/support/lib/util.py new file mode 100644 index 0000000..a3bc3dc --- /dev/null +++ b/support/lib/util.py @@ -0,0 +1,18 @@ +import contextlib, subprocess, tempfile, shutil + + +@contextlib.contextmanager +def TemporaryDirectory(): + dir = tempfile.mkdtemp() + + try: + yield dir + finally: + shutil.rmtree(dir) + + +def command(args): + process = subprocess.Popen(args) + process.wait() + + assert not process.returncode -- cgit From f9fa53eef8e1183c4f7e3f9e0dd463ec1babdc86 Mon Sep 17 00:00:00 2001 From: Michael Schwarz Date: Fri, 12 Dec 2014 11:44:29 +0100 Subject: Added support for recording dependencies while compiling OpenSCAD files. --- support/lib/util.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'support/lib') diff --git a/support/lib/util.py b/support/lib/util.py index a3bc3dc..bede240 100644 --- a/support/lib/util.py +++ b/support/lib/util.py @@ -1,4 +1,4 @@ -import contextlib, subprocess, tempfile, shutil +import contextlib, subprocess, tempfile, shutil, re, os @contextlib.contextmanager @@ -16,3 +16,21 @@ def command(args): process.wait() assert not process.returncode + + +def bash_escape_string(string): + return "'{}'".format(re.sub("'", "'\"'\"'", string)) + + +def write_file(path, data): + temp_path = path + '~' + + with open(temp_path, 'wb') as file: + file.write(data) + + os.rename(temp_path, path) + + +def read_file(path): + with open(path, 'rb') as file: + return file.read() -- cgit