Compare commits
2 commits
fd8ed776d4
...
d629e8fb71
Author | SHA1 | Date | |
---|---|---|---|
d629e8fb71 | |||
605abaf177 |
3 changed files with 39 additions and 8 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,4 @@
|
||||||
__pycache__
|
__pycache__
|
||||||
|
wp-cal-integration
|
||||||
|
*.c
|
||||||
|
*.o
|
||||||
|
|
21
Makefile
Normal file
21
Makefile
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
CC ?= cc
|
||||||
|
CFLAGS ?= $(shell python-config --embed --cflags)
|
||||||
|
LDFLAGS ?= $(shell python-config --embed --ldflags)
|
||||||
|
|
||||||
|
SRC := main.py adapters/*.py
|
||||||
|
OBJ := $(SRC:%.py=%.o)
|
||||||
|
|
||||||
|
wp-cal-integration: $(OBJ)
|
||||||
|
$(CC) $(LDFLAGS) -o $@ $^
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) $(OBJ)
|
||||||
|
|
||||||
|
main.c: main.py
|
||||||
|
cython -3 --embed -o $@ $<
|
||||||
|
%.c: %.py
|
||||||
|
cython -3 -o $@ $<
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) -c $(CFLAGS) -o $@ $<
|
||||||
|
|
23
main.py
23
main.py
|
@ -39,12 +39,12 @@ class BaseConfig(dict):
|
||||||
def _load(self):
|
def _load(self):
|
||||||
try:
|
try:
|
||||||
if self.file == '-':
|
if self.file == '-':
|
||||||
config = yaml.load(sys.stdin, Loader=Loader)
|
config = yaml.safe_load(sys.stdin)
|
||||||
else:
|
else:
|
||||||
if os.stat(self.file).st_mode & 0o777 & ~0o600:
|
if os.stat(self.file).st_mode & 0o777 & ~0o600:
|
||||||
raise Exception('refusing to load insecure configuration file, file must have permission 0o600')
|
raise Exception('refusing to load insecure configuration file, file must have permission 0o600')
|
||||||
with open(self.file) as fp:
|
with open(self.file) as fp:
|
||||||
config = yaml.load(fp, Loader=Loader)
|
config = yaml.safe_load(fp)
|
||||||
if config is None:
|
if config is None:
|
||||||
config = {}
|
config = {}
|
||||||
for k, v in config.items():
|
for k, v in config.items():
|
||||||
|
@ -65,7 +65,7 @@ class BaseConfig(dict):
|
||||||
|
|
||||||
def _save(self):
|
def _save(self):
|
||||||
with open(self.file, 'w') as fp:
|
with open(self.file, 'w') as fp:
|
||||||
yaml.dump(self, fp, Dumper=Dumper)
|
yaml.safe_dump(dict(self), fp)
|
||||||
|
|
||||||
def exception(self):
|
def exception(self):
|
||||||
return self._ex
|
return self._ex
|
||||||
|
@ -164,16 +164,23 @@ def init_logging():
|
||||||
|
|
||||||
|
|
||||||
def set_logging_level(level: str):
|
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(',')]
|
log_levels = [x.split(':') for x in level.split(',')]
|
||||||
for module, level in log_levels:
|
for module, level in log_levels:
|
||||||
module = module.strip() if module else None
|
module = module.strip() if module else None
|
||||||
level = level.strip().upper()
|
level = level.strip().upper()
|
||||||
if level not in allowed_values:
|
if level not in levels:
|
||||||
raise ValueError(f'invalid log level, allowed values: {repr(allowed_values)}')
|
raise ValueError(f'invalid log level, allowed values: {repr(set(levels.keys()))}')
|
||||||
level = getattr(logging, level)
|
logging.getLogger(module).setLevel(levels[level])
|
||||||
logging.getLogger(module).setLevel(level)
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('--config', '-c', envvar='WP_CAL_CONFIG', default='-', help='The configuration file')
|
@click.option('--config', '-c', envvar='WP_CAL_CONFIG', default='-', help='The configuration file')
|
||||||
|
|
Loading…
Reference in a new issue