diff options
author | Michael Schwarz <michi.schwarz@gmail.com> | 2014-12-12 18:07:28 +0100 |
---|---|---|
committer | Michael Schwarz <michi.schwarz@gmail.com> | 2014-12-12 18:07:28 +0100 |
commit | 88fef813b0d1013e90c9aa4156cbc836481377a3 (patch) | |
tree | 128b26f48b4a5abfbb803d85ecae48237cb0a238 /support/lib/util.py | |
parent | c02392b65243b3842e273cec36468e21ee376787 (diff) | |
parent | b69003800917a93c5c2b240ede6f83b80f1095cc (diff) | |
download | pogojig-88fef813b0d1013e90c9aa4156cbc836481377a3.tar.gz pogojig-88fef813b0d1013e90c9aa4156cbc836481377a3.tar.bz2 pogojig-88fef813b0d1013e90c9aa4156cbc836481377a3.zip |
Merge branch 'master' into no-examples
Diffstat (limited to 'support/lib/util.py')
-rw-r--r-- | support/lib/util.py | 36 |
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() |