summaryrefslogtreecommitdiff
path: root/support/lib/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'support/lib/util.py')
-rw-r--r--support/lib/util.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/support/lib/util.py b/support/lib/util.py
new file mode 100644
index 0000000..bede240
--- /dev/null
+++ b/support/lib/util.py
@@ -0,0 +1,36 @@
+import contextlib, subprocess, tempfile, shutil, re, os
+
+
+@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
+
+
+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()