1 # Copyright 2014 The Swarming Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 that
3 # can be found in the LICENSE file.
12 class EnvVars(object):
13 """Context manager for environment variables.
15 Passed a dict to the constructor it sets variables named with the key to the
16 value. Exiting the context causes all the variables named with the key to be
17 restored to their value before entering the context.
19 def __init__(self, var_map):
20 self.var_map = var_map
24 self._backup = os.environ
25 os.environ = os.environ.copy()
26 os.environ.update(self.var_map)
28 def __exit__(self, exc_type, exc_value, traceback):
29 os.environ = self._backup
33 """Returns current process umask without modifying it."""
36 _UMASK = os.umask(0777)
43 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR,
44 format='%(levelname)5s %(filename)15s(%(lineno)3d): %(message)s')
46 unittest.TestCase.maxDiff = None
47 # Use an unusual umask.