Skip to content

Commit

Permalink
Fixed config loader to work correctly in Google App Engine (where os.…
Browse files Browse the repository at this point in the history
…path.expanduser() would fail)
  • Loading branch information
mfschwartz committed Apr 21, 2011
1 parent 3c79b71 commit 3fa1089
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions boto/pyami/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,32 @@
import ConfigParser
import boto

# If running in Google App Engine there is no "user" and
# os.path.expanduser() will fail. Use no-op expanduser in this case.
if 'getuid' in dir(os):
expanduser = os.path.expanduser
else:
expanduser = (lambda x: x)

# By default we use two locations for the boto configurations,
# /etc/boto.cfg and $HOME/.boto (which is ~/.boto on both Windows and
# Unix platforms for python)
BotoConfigPath = '/etc/boto.cfg'
BotoConfigLocations = [BotoConfigPath]
UserConfigPath = os.path.expanduser('~/.boto')
UserConfigPath = expanduser('~/.boto')
BotoConfigLocations.append(UserConfigPath)

# IF there's a BOTO_CONFIG variable set, we load ONLY
# that variable
if 'BOTO_CONFIG' in os.environ:
BotoConfigLocations = [os.path.expanduser(os.environ['BOTO_CONFIG'])]
BotoConfigLocations = [expanduser(os.environ['BOTO_CONFIG'])]

# If there's a BOTO_PATH variable set, we use anything there
# as the current configuration locations, split with semicolons
elif 'BOTO_PATH' in os.environ:
BotoConfigLocations = []
for path in os.environ['BOTO_PATH'].split(":"):
BotoConfigLocations.append(os.path.expanduser(path))
BotoConfigLocations.append(expanduser(path))


class Config(ConfigParser.SafeConfigParser):
Expand All @@ -58,7 +65,7 @@ def __init__(self, path=None, fp=None, do_load=True):
else:
self.read(BotoConfigLocations)
if "AWS_CREDENTIAL_FILE" in os.environ:
self.load_credential_file(os.path.expanduser(os.environ['AWS_CREDENTIAL_FILE']))
self.load_credential_file(expanduser(os.environ['AWS_CREDENTIAL_FILE']))

def load_credential_file(self, path):
"""Load a credential file as is setup like the Java utilities"""
Expand Down

0 comments on commit 3fa1089

Please sign in to comment.