Created
April 19, 2016 02:59
-
-
Save charlee/146cca2b6068a92b8488023296538595 to your computer and use it in GitHub Desktop.
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
#deprecated | |
def grep_php_const(lines, name): | |
regexp = "^define\(\s*'%s',\s*'(.*)'\s*\);\s*$" % name | |
for line in lines: | |
m = re.match(regexp, line) | |
if m: | |
return m.group(1) | |
#deprecated | |
def parse_wp_config(): | |
wp_config_file = os.path.join(BASEDIR, 'wp-config.php') | |
lines = open(wp_config_file, 'r').read().split('\n') | |
lines = [ line.strip() for line in lines ] | |
db_name = grep_php_const(lines, 'DB_NAME') | |
db_user = grep_php_const(lines, 'DB_USER') | |
db_host = grep_php_const(lines, 'DB_HOST') | |
db_password = grep_php_const(lines, 'DB_PASSWORD') | |
return { | |
'username': db_user, | |
'password': db_password, | |
'host': db_host, | |
'db': db_name, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment