config: Add support for formating with commented out defaults
- Changes inline comments to ; for configparser conformance
This commit is contained in:
parent
9ca222ed39
commit
bd1ee7ff39
@ -66,7 +66,7 @@ def format(config, extensions, comments=None, display=True):
|
|||||||
# need to know about extensions.
|
# need to know about extensions.
|
||||||
schemas = _schemas[:]
|
schemas = _schemas[:]
|
||||||
schemas.extend(e.get_config_schema() for e in extensions)
|
schemas.extend(e.get_config_schema() for e in extensions)
|
||||||
return _format(config, comments or {}, schemas, display)
|
return _format(config, comments or {}, schemas, display, False)
|
||||||
|
|
||||||
|
|
||||||
def _load(files, defaults, overrides):
|
def _load(files, defaults, overrides):
|
||||||
@ -128,7 +128,7 @@ def _validate(raw_config, schemas):
|
|||||||
return config, errors
|
return config, errors
|
||||||
|
|
||||||
|
|
||||||
def _format(config, comments, schemas, display):
|
def _format(config, comments, schemas, display, disable):
|
||||||
output = []
|
output = []
|
||||||
for schema in schemas:
|
for schema in schemas:
|
||||||
serialized = schema.serialize(
|
serialized = schema.serialize(
|
||||||
@ -142,9 +142,11 @@ def _format(config, comments, schemas, display):
|
|||||||
if value is not None:
|
if value is not None:
|
||||||
output[-1] += b' ' + value
|
output[-1] += b' ' + value
|
||||||
if comment:
|
if comment:
|
||||||
output[-1] += b' # ' + comment.capitalize()
|
output[-1] += b' ; ' + comment.capitalize()
|
||||||
|
if disable:
|
||||||
|
output[-1] = re.sub(r'^', b'#', output[-1], flags=re.M)
|
||||||
output.append(b'')
|
output.append(b'')
|
||||||
return b'\n'.join(output)
|
return b'\n'.join(output[:-1])
|
||||||
|
|
||||||
|
|
||||||
def _preprocess(config_string):
|
def _preprocess(config_string):
|
||||||
|
|||||||
@ -167,7 +167,7 @@ class List(ConfigValue):
|
|||||||
return tuple(values)
|
return tuple(values)
|
||||||
|
|
||||||
def serialize(self, value, display=False):
|
def serialize(self, value, display=False):
|
||||||
return b'\n ' + b'\n '.join(encode(v) for v in value if v)
|
return b'\n ' + b'\n '.join(encode(v) for v in value if v)
|
||||||
|
|
||||||
|
|
||||||
class LogLevel(ConfigValue):
|
class LogLevel(ConfigValue):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user