Add exception handling for failure to return to original directory

Fixes #1552
This commit is contained in:
Labrys of Knossos 2019-02-16 10:17:01 -05:00
commit fd8452b5c6

View file

@ -33,7 +33,17 @@ class WorkingDirectory(object):
return self return self
def __exit__(self, exc_type, exc_val, exc_tb): def __exit__(self, exc_type, exc_val, exc_tb):
try:
os.chdir(self.original_directory) os.chdir(self.original_directory)
except OSError as error:
print(
'Unable to return to {original_directory}: {error}\n'
'Continuing in {working_directory}'.format(
original_directory=self.original_directory,
error=error,
working_directory=self.working_directory,
)
)
def module_path(module=__file__, parent=False): def module_path(module=__file__, parent=False):