def main():
if not os.path.exists('.env'):
print('ERROR!! .env file is missing!')
print("Please copy 'env.example' to '.env' and add appropriate values")
exit()
command = ['eb', 'setenv']
failures = []
for key, value in dotenv.Dotenv('.env').items():
if key.startswith('POSTGRES'):
print('Skipping POSTGRES values - Amazon RDS provides these')
continue
if value:
command.append("{}={}".format(key, value))
else:
failures.append(key)
if failures:
for failure in failures:
print("{} requires a value".format(failure))
else:
print(' '.join(command))
check_call(command)
python类Dotenv()的实例源码
def __init__(self, sort_key):
try:
env = Dotenv('./.env')
credential_table = env["CREDENTIAL_TABLE_ARN"]
except IOError:
try:
env = Dotenv('../.env')
credential_table = env["CREDENTIAL_TABLE_ARN"]
except:
credential_table ="arn:aws:dynamodb:us-west-2:576309420438:table/dev_credential"
self.sort_key = sort_key
self.table_name = credential_table.split('/')[1]
self.dynamodb = None