summaryrefslogtreecommitdiff
path: root/support/lib
diff options
context:
space:
mode:
authorMichael Schwarz <michi.schwarz@gmail.com>2014-12-12 18:07:28 +0100
committerMichael Schwarz <michi.schwarz@gmail.com>2014-12-12 18:07:28 +0100
commit88fef813b0d1013e90c9aa4156cbc836481377a3 (patch)
tree128b26f48b4a5abfbb803d85ecae48237cb0a238 /support/lib
parentc02392b65243b3842e273cec36468e21ee376787 (diff)
parentb69003800917a93c5c2b240ede6f83b80f1095cc (diff)
downloadpogojig-88fef813b0d1013e90c9aa4156cbc836481377a3.tar.gz
pogojig-88fef813b0d1013e90c9aa4156cbc836481377a3.tar.bz2
pogojig-88fef813b0d1013e90c9aa4156cbc836481377a3.zip
Merge branch 'master' into no-examples
Diffstat (limited to 'support/lib')
-rw-r--r--support/lib/__init__.py0
-rw-r--r--support/lib/util.py36
2 files changed, 36 insertions, 0 deletions
diff --git a/support/lib/__init__.py b/support/lib/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/support/lib/__init__.py
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()