mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-04 22:40:12 +01:00
common.write_to_config(): if key doesn't exist in config.py, append it
This lets `fdroid update --create-key` add key/value pairs to config.py
This commit is contained in:
parent
ff48c6b7f9
commit
cc0908bdbb
@ -2067,5 +2067,11 @@ def write_to_config(thisconfig, key, value=None):
|
||||
pattern = '\n[\s#]*' + key + '\s*=\s*"[^"]*"'
|
||||
repl = '\n' + key + ' = "' + value + '"'
|
||||
data = re.sub(pattern, repl, data)
|
||||
# if this key is not in the file, append it
|
||||
if not re.match('\s*' + key + '\s*=\s*"', data):
|
||||
data += repl
|
||||
# make sure the file ends with a carraige return
|
||||
if not re.match('\n$', data):
|
||||
data += '\n'
|
||||
with open('config.py', 'w') as f:
|
||||
f.writelines(data)
|
||||
|
Loading…
Reference in New Issue
Block a user