The defaults are set in config.py and are often commented out. Before, the
regex would only change the value, but leave it commented out. Now, it
will also uncomment it.
'''write a key/value to the local config.py'''
with open('config.py', 'r') as f:
data = f.read()
- pattern = key + '\s*=.*'
- repl = key + ' = "' + value + '"'
+ pattern = '\n[\s#]*' + key + '\s*=\s*"[^"]*"'
+ repl = '\n' + key + ' = "' + value + '"'
data = re.sub(pattern, repl, data)
with open('config.py', 'w') as f:
f.writelines(data)