case sensitive config parser

This commit is contained in:
mwiegand 2021-11-13 15:57:29 +01:00
parent 6c2473e2da
commit d6e4cdb45a
2 changed files with 21 additions and 15 deletions

View file

@ -44,11 +44,11 @@ defaults = {
'php': {
'post_max_size': '32G',
'www.conf': {
'env[hostname]': '$HOSTNAME',
'env[path]': '/usr/local/bin:/usr/bin:/bin',
'env[tmp]': '/tmp',
'env[tmpdir]': '/tmp',
'env[temp]': '/tmp',
'env[HOSTNAME]': '$HOSTNAME',
'env[PATH]': '/usr/local/bin:/usr/bin:/bin',
'env[TMP]': '/tmp',
'env[TMPDIR]': '/tmp',
'env[TEMP]': '/tmp',
},
},
'postgresql': {

View file

@ -1,8 +1,18 @@
from configparser import ConfigParser
import json
class Writable():
data = ''
def write(self, line):
self.data += line
class CaseSensitiveConfigParser(ConfigParser):
# dont make keys lowercase
def optionxform(self, value):
return value
def parse(text):
config = ConfigParser()
config = CaseSensitiveConfigParser()
config.read_string(text)
return {
@ -10,17 +20,13 @@ def parse(text):
for section in config.sections()
}
class Writable():
data = ''
def write(self, line):
self.data += line
def dumps(dict):
config = ConfigParser()
sorted_dict = json.loads(json.dumps(dict, sort_keys=True))
config.read_dict(sorted_dict)
parser = CaseSensitiveConfigParser()
parser.read_dict(sorted_dict)
writable = Writable()
config.write(writable)
parser.write(writable)
return writable.data