aboutsummaryrefslogtreecommitdiff
path: root/delivery_merge/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'delivery_merge/utils.py')
-rw-r--r--delivery_merge/utils.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/delivery_merge/utils.py b/delivery_merge/utils.py
new file mode 100644
index 0000000..1dca224
--- /dev/null
+++ b/delivery_merge/utils.py
@@ -0,0 +1,33 @@
+import os
+from contextlib import contextmanager
+from subprocess import run
+
+
+def sh(prog, *args):
+ command = [prog]
+ tmp = []
+ for arg in args:
+ tmp += arg.split()
+
+ command += tmp
+ print(f'Running: {" ".join(command)}')
+ return run(command, capture_output=True)
+
+
+def getenv(s):
+ """ Convert string of key pairs to dictionary format
+ """
+ return dict([x.split('=', 1) for x in s.splitlines()])
+
+
+@contextmanager
+def pushd(path):
+ """ Equivalent to shell pushd/popd behavior
+ """
+ last = os.path.abspath(os.getcwd())
+ os.chdir(path)
+ try:
+ yield
+ finally:
+ os.chdir(last)
+