| Conditions | 6 |
| Total Lines | 18 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | from pathlib import Path |
||
| 11 | def load_config_file(): |
||
| 12 | """ |
||
| 13 | Load the configuration file |
||
| 14 | """ |
||
| 15 | fpath = Path(XDG_CONFIG_HOME, 'ocrd', 'config.yml') |
||
| 16 | if not fpath.parent.exists(): |
||
| 17 | fpath.parent.mkdir() |
||
| 18 | obj = DEFAULT_CONFIG |
||
| 19 | if not fpath.exists(): |
||
| 20 | with open(str(fpath), 'w', encoding='utf-8') as f_out: |
||
| 21 | f_out.write("# Generated by OCR-D/core %s on %s\n" % (VERSION, datetime.now())) |
||
| 22 | f_out.write(safe_dump(obj)) |
||
| 23 | with open(str(fpath), 'r', encoding='utf-8') as f_in: |
||
| 24 | obj = {**obj, **safe_load(f_in.read())} |
||
| 25 | report = OcrdConfigValidator.validate(obj) |
||
| 26 | if not report.is_valid: |
||
| 27 | raise ValueError("The configuration is invalid: %s" % report.errors) |
||
| 28 | return OcrdConfig(obj) |
||
| 29 |