self.old_environment = {}
for k in self.new_environment:
+ # Store the old value
self.old_environment[k] = os.environ.get(k, None)
- # Apply the new one
- os.environ.update(self.new_environment)
+ # Apply the new one
+ if self.new_environment[k]:
+ os.environ[k] = self.new_environment[k]
def __exit__(self, type, value, traceback):
# Roll back to the previous environment
"""
filename = os.path.join(*args)
- with open(filename) as f:
- value = f.read()
+ try:
+ with open(filename) as f:
+ value = f.read()
+ except FileNotFoundError as e:
+ return None
# Strip any excess whitespace
if strip:
try:
return int(value)
- except ValueError:
+ except (TypeError, ValueError):
return None
def read_proc_stat(self):