From 605abaf177c3dfc8070facbce7edd18013c56fda Mon Sep 17 00:00:00 2001 From: redxef Date: Wed, 23 Nov 2022 02:00:16 +0100 Subject: [PATCH] Fix template generation. --- main.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index ae04670..60a2bda 100755 --- a/main.py +++ b/main.py @@ -39,12 +39,12 @@ class BaseConfig(dict): def _load(self): try: if self.file == '-': - config = yaml.load(sys.stdin, Loader=Loader) + config = yaml.safe_load(sys.stdin) else: if os.stat(self.file).st_mode & 0o777 & ~0o600: raise Exception('refusing to load insecure configuration file, file must have permission 0o600') with open(self.file) as fp: - config = yaml.load(fp, Loader=Loader) + config = yaml.safe_load(fp) if config is None: config = {} for k, v in config.items(): @@ -65,7 +65,7 @@ class BaseConfig(dict): def _save(self): with open(self.file, 'w') as fp: - yaml.dump(self, fp, Dumper=Dumper) + yaml.safe_dump(dict(self), fp) def exception(self): return self._ex @@ -164,16 +164,23 @@ def init_logging(): def set_logging_level(level: str): - allowed_values = {'NOTSET', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'} + levels = { + 'NOTSET': logging.NOTSET, + 'DEBUG': logging.DEBUG, + 'INFO': logging.INFO, + 'WARNING': logging.WARNING, + 'WARN': logging.WARNING, + 'ERROR': logging.ERROR, + 'CRITICAL': logging.CRITICAL, + } log_levels = [x.split(':') for x in level.split(',')] for module, level in log_levels: module = module.strip() if module else None level = level.strip().upper() - if level not in allowed_values: - raise ValueError(f'invalid log level, allowed values: {repr(allowed_values)}') - level = getattr(logging, level) - logging.getLogger(module).setLevel(level) + if level not in levels: + raise ValueError(f'invalid log level, allowed values: {repr(set(levels.keys()))}') + logging.getLogger(module).setLevel(levels[level]) @click.command() @click.option('--config', '-c', envvar='WP_CAL_CONFIG', default='-', help='The configuration file')