aboutsummaryrefslogtreecommitdiff
path: root/delivery_merge/utils.py
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2019-05-06 23:19:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2019-05-06 23:19:52 -0400
commit502bb16cab44aed9e36b6052f725a994b1ffab16 (patch)
tree2ba02459edf27102eb58af3c85ec2c29b41d4224 /delivery_merge/utils.py
downloaddelivery_merge-502bb16cab44aed9e36b6052f725a994b1ffab16.tar.gz
Initial commit
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)
+