Add chdir utility function.

This commit is contained in:
Bastian Kleineidam 2013-02-22 18:33:38 +01:00
parent 293cb63145
commit b11498e8aa
1 changed files with 12 additions and 0 deletions

View File

@ -492,4 +492,16 @@ def link_or_copy(src, dst, verbose=False):
shutil.copy(src, dst) shutil.copy(src, dst)
def chdir(directory):
"""Remember and return current directory before calling os.chdir().
If the current directory could not be determined, return None.
"""
try:
olddir = os.getcwd()
except OSError:
olddir = None
os.chdir(directory)
return olddir
init_mimedb() init_mimedb()