Skip to content

Instantly share code, notes, and snippets.

@deanrock
Created October 16, 2013 13:55
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 deanrock/7008141 to your computer and use it in GitHub Desktop.
Save deanrock/7008141 to your computer and use it in GitHub Desktop.
def check_match(regex, line, type, value):
m = regex.match(line)
if m:
dj.log_info('found: %s' % m.group(0))
line = ' \'%s\' => \'%s\', \n' % (type, value)
dj.log_info('replaced: %s' %line)
return line
return line
path = 'path-to-settings.php'
db_name = 'db-name'
db_pass='db-password'
if os.path.isfile(path):
with open(path) as f:
content = f.readlines()
out = []
database = re.compile(' \'database\' => \'(.*)\'')
username = re.compile(' \'username\' => \'(.*)\'')
password = re.compile(' \'password\' => \'(.*)\'')
for line in content:
line = check_match(database, line, 'database', db_name)
line = check_match(username, line, 'username', db_name)
line = check_match(password, line, 'password', db_pass)
out.append(line)
f = open(path,'w')
for line in out:
f.write(line)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment