- for line in open(os_env_filename):
- line = line.lstrip()
- if not line.startswith('#') and line.startswith('export '):
- line = line.lstrip('export ').strip()
- tokens = line.split('=')
- if len(tokens) > 1:
- # Remove leading and trailing ' & " characters from value
- out[tokens[0]] = tokens[1].lstrip('\'').lstrip('\"').rstrip('\'').rstrip('\"')
+ env_file = None
+ try:
+ env_file = open(os_env_filename)
+ for line in env_file:
+ line = line.lstrip()
+ if not line.startswith('#') and line.startswith('export '):
+ line = line.lstrip('export ').strip()
+ tokens = line.split('=')
+ if len(tokens) > 1:
+ # Remove leading and trailing ' & " characters from
+ # value
+ out[tokens[0]] = tokens[1].lstrip('\'').lstrip('\"').rstrip('\'').rstrip('\"')
+ finally:
+ if env_file:
+ env_file.close()