Created
October 23, 2013 10:57
-
-
Save chrislawlor/7116554 to your computer and use it in GitHub Desktop.
Get database password from ~/.my.cnf file, if it exists. Useful when developing on CloudSQL + AppEngine, which gleefully ignores environment variables.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get password from ~/.my.cnf if it exists | |
my_cnf_path = os.path.expanduser('~/.my.cnf') | |
if os.path.exists(my_cnf_path): | |
from ConfigParser import SafeConfigParser | |
config = SafeConfigParser() | |
with open(my_cnf_path) as my_cnf: | |
config.readfp(my_cnf) | |
try: | |
DATABASES['default']['PASSWORD'] = config.get('client', 'password') | |
except ConfigParser.NoOptionError: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment