staticoso/Source/Modules/Config.py

55 lines
1.2 KiB
Python
Raw Normal View History

2022-07-11 17:28:59 +02:00
""" ================================= |
| This file is part of |
| staticoso |
| Just a simple Static Site Generator |
| |
| Licensed under the AGPLv3 license |
| Copyright (C) 2022, OctoSpacc |
| ================================= """
2022-07-28 16:27:37 +02:00
import io
2022-07-11 17:28:59 +02:00
import configparser
from ast import literal_eval
2022-07-28 16:27:37 +02:00
def LoadConfFile(File):
2022-07-11 17:28:59 +02:00
Conf = configparser.ConfigParser()
2022-07-28 16:27:37 +02:00
Conf.optionxform = lambda option: option
2022-07-11 17:28:59 +02:00
Conf.read(File)
return Conf
2022-07-28 16:27:37 +02:00
def LoadConfStr(Str):
Conf = configparser.ConfigParser()
Conf.optionxform = lambda option: option
Conf.read_string(Str)
return Conf
2022-07-11 17:28:59 +02:00
def ReadConf(Conf, Sect, Opt=None):
if Opt:
if Conf.has_option(Sect, Opt):
return Conf[Sect][Opt]
else:
if Conf.has_section(Sect):
return Conf[Sect]
return None
def EvalOpt(Opt):
if Opt:
return literal_eval(Opt)
else:
return None
2022-07-25 16:11:39 +02:00
def StringBoolChoose(Default, Primary, Secondary):
Var = Default
if Primary != None:
Check = Primary
else:
Check = Secondary
if type(Check) == bool:
Var = Check
elif type(Check) == str:
if Check in ('True', 'All', '*'):
Var = True
elif Check in ('False', 'None'):
Var = False
return Var