832e46bf1d
polishing signal reception, creation of ap class, added time class,further work on logging and features. Hidden Dragon is unfinished, do not use.
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
# Copyright (c) 2024 Anoduck
|
|
#
|
|
# This software is released under the MIT License.
|
|
# https://opensource.org/licenses/MIT
|
|
|
|
from configobj import ConfigObj, validate
|
|
from spec import cfg
|
|
import os
|
|
import sys
|
|
|
|
|
|
class ParseConfig:
|
|
|
|
def get_config(self, config_file):
|
|
config_path = os.path.realpath(config_file)
|
|
spec = cfg.split("\n")
|
|
if not os.path.isfile(config_file):
|
|
if not os.path.exists(os.path.dirname(config_file)):
|
|
os.mkdir(os.path.dirname(config_file))
|
|
config = ConfigObj(config_file, configspec=spec)
|
|
config.filename = config_file
|
|
validator = validate.Validator()
|
|
config.validate(validator, copy=True)
|
|
config.write()
|
|
print("configuration file written to ", config_path)
|
|
sys.exit()
|
|
config = ConfigObj(config_file, configspec=spec)
|
|
validator = validate.Validator()
|
|
test = config.validate(validator, preserve_errors=True)
|
|
if not test:
|
|
print("Configuration file is invalid")
|
|
sys.exit()
|
|
return config
|