forked from s3lph/matemat
Fixed: Expand ~ in config file parsing.
This commit is contained in:
parent
23e6662ca8
commit
758a2eb018
1 changed files with 4 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
|
|
||||||
|
import os
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,14 +31,14 @@ def parse_config_file(path: str) -> Dict[str, Any]:
|
||||||
# Replace the original option transformation by a string constructor to preserve the case of config keys
|
# Replace the original option transformation by a string constructor to preserve the case of config keys
|
||||||
parser.optionxform = str
|
parser.optionxform = str
|
||||||
# Read the configuration file
|
# Read the configuration file
|
||||||
parser.read(path, 'utf-8')
|
parser.read(os.path.expanduser(path), 'utf-8')
|
||||||
|
|
||||||
# Read values from the [Matemat] section, if present, falling back to default values
|
# Read values from the [Matemat] section, if present, falling back to default values
|
||||||
if 'Matemat' in parser.sections():
|
if 'Matemat' in parser.sections():
|
||||||
config['listen'] = parser['Matemat'].get('Address', config['listen'])
|
config['listen'] = parser['Matemat'].get('Address', config['listen'])
|
||||||
config['port'] = int(parser['Matemat'].get('Port', config['port']))
|
config['port'] = int(parser['Matemat'].get('Port', config['port']))
|
||||||
config['staticroot'] = parser['Matemat'].get('StaticPath', config['staticroot'])
|
config['staticroot'] = parser['Matemat'].get('StaticPath', os.path.expanduser(config['staticroot']))
|
||||||
config['templateroot'] = parser['Matemat'].get('TemplatePath', config['templateroot'])
|
config['templateroot'] = parser['Matemat'].get('TemplatePath', os.path.expanduser(config['templateroot']))
|
||||||
|
|
||||||
# Read all values from the [Pagelets] section, if present. These values are passed to pagelet functions
|
# Read all values from the [Pagelets] section, if present. These values are passed to pagelet functions
|
||||||
if 'Pagelets' in parser.sections():
|
if 'Pagelets' in parser.sections():
|
||||||
|
|
Loading…
Reference in a new issue