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)
This commit is contained in:
parent
49966a47c2
commit
5d74b8005c
@ -486,6 +486,16 @@ def mergedict(src, cand):
|
||||
return src
|
||||
|
||||
|
||||
@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)
|
||||
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user