Skip to content

Instantly share code, notes, and snippets.

@charlee
Created April 19, 2016 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlee/146cca2b6068a92b8488023296538595 to your computer and use it in GitHub Desktop.
Save charlee/146cca2b6068a92b8488023296538595 to your computer and use it in GitHub Desktop.
#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