chiark / gitweb /
when generating config.py during init, uncomment changed options
authorHans-Christoph Steiner <hans@eds.org>
Fri, 4 Apr 2014 01:02:18 +0000 (21:02 -0400)
committerHans-Christoph Steiner <hans@eds.org>
Mon, 7 Apr 2014 20:00:17 +0000 (16:00 -0400)
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.

fdroidserver/init.py

index 5cd126c1bc9fa546419997f5b9bcf573fcffa0c4..4ecc39108fd04efafb61dad8e5c8ab02ee9c2b5e 100644 (file)
@@ -38,8 +38,8 @@ def write_to_config(key, value):
     '''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)