diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-06-26 12:16:39 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-06-26 12:16:39 -0700 |
commit | d3402eac1ca362e1db0b40eb677e7cfc74a3d2c9 (patch) | |
tree | d37b18c4876acf87a399b75dcdb431bcce2f36b8 /cloudinit/util.py | |
parent | e657162aa2e0b3b4a92e4860f758ee85d8d85eba (diff) | |
download | vyos-cloud-init-d3402eac1ca362e1db0b40eb677e7cfc74a3d2c9.tar.gz vyos-cloud-init-d3402eac1ca362e1db0b40eb677e7cfc74a3d2c9.zip |
1. Add a chdir context manager
2. Add a abs path joining function that will return the absolute path of
a combined path (where applicable)
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index 2f5ed275..f95a5d07 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -487,6 +487,16 @@ def mergedict(src, cand): @contextlib.contextmanager +def chdir(ndir): + curr = os.getcwd() + try: + os.chdir(ndir) + yield ndir + finally: + os.chdir(curr) + + +@contextlib.contextmanager def umask(n_msk): old = os.umask(n_msk) try: @@ -1285,6 +1295,10 @@ def subp(args, data=None, rcs=None, env=None, capture=True, shell=False): return (out, err) +def abs_join(*paths): + return os.path.abspath(os.path.join(*paths)) + + # shellify, takes a list of commands # for each entry in the list # if it is an array, shell protect it (with single ticks) |