diff options
Diffstat (limited to 'support/lib')
-rw-r--r-- | support/lib/util.py | 20 |
1 files changed, 19 insertions, 1 deletions
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() |