Advertisement
Guest User

Untitled

a guest
Apr 19th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #deprecated
  2. def grep_php_const(lines, name):
  3.  
  4. regexp = "^define\(\s*'%s',\s*'(.*)'\s*\);\s*$" % name
  5. for line in lines:
  6. m = re.match(regexp, line)
  7. if m:
  8. return m.group(1)
  9.  
  10.  
  11. #deprecated
  12. def parse_wp_config():
  13. wp_config_file = os.path.join(BASEDIR, 'wp-config.php')
  14.  
  15. lines = open(wp_config_file, 'r').read().split('\n')
  16. lines = [ line.strip() for line in lines ]
  17.  
  18. db_name = grep_php_const(lines, 'DB_NAME')
  19. db_user = grep_php_const(lines, 'DB_USER')
  20. db_host = grep_php_const(lines, 'DB_HOST')
  21. db_password = grep_php_const(lines, 'DB_PASSWORD')
  22.  
  23. return {
  24. 'username': db_user,
  25. 'password': db_password,
  26. 'host': db_host,
  27. 'db': db_name,
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement