2013-09-27 18:09:38 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
|
2017-04-16 08:36:27 +00:00
|
|
|
"""
|
|
|
|
Producing then compiling templates
|
|
|
|
"""
|
|
|
|
|
2022-05-05 12:35:01 +00:00
|
|
|
import importlib.util
|
2022-07-19 13:15:06 +00:00
|
|
|
import os
|
2022-05-05 12:35:01 +00:00
|
|
|
from pathlib import Path
|
2022-04-09 14:18:56 +00:00
|
|
|
from bopytex.scheduler import Scheduler
|
2022-05-05 12:35:01 +00:00
|
|
|
from bopytex import default_config
|
2017-04-16 15:46:14 +00:00
|
|
|
|
2017-04-17 14:10:38 +00:00
|
|
|
|
2022-04-10 04:45:10 +00:00
|
|
|
def orcherstrator(
|
|
|
|
options: dict,
|
|
|
|
planner,
|
2022-04-10 12:37:19 +00:00
|
|
|
dispatcher,
|
2019-10-15 17:50:54 +00:00
|
|
|
):
|
2022-04-10 04:45:10 +00:00
|
|
|
tasks = planner(options)
|
2022-04-09 14:18:56 +00:00
|
|
|
|
2022-04-13 13:09:08 +00:00
|
|
|
scheduler = Scheduler(dispatcher, [options["template"]])
|
2022-04-09 14:18:56 +00:00
|
|
|
scheduler.append(tasks)
|
|
|
|
|
2022-04-13 13:09:08 +00:00
|
|
|
for message in scheduler.backlog():
|
|
|
|
yield message
|
2014-01-19 20:37:46 +00:00
|
|
|
|
2022-05-05 12:35:01 +00:00
|
|
|
|
|
|
|
def load_module(modulefile: str):
|
|
|
|
spec = importlib.util.spec_from_file_location("module.name", modulefile)
|
|
|
|
module = importlib.util.module_from_spec(spec)
|
|
|
|
spec.loader.exec_module(module)
|
|
|
|
return module
|
|
|
|
|
|
|
|
|
|
|
|
def clean_vars_keys(
|
|
|
|
vars: dict,
|
|
|
|
keys: list[str] = [
|
|
|
|
"__name__",
|
|
|
|
"__doc__",
|
|
|
|
"__package__",
|
|
|
|
"__loader__",
|
|
|
|
"__spec__",
|
|
|
|
"__file__",
|
|
|
|
"__cached__",
|
|
|
|
"__builtins__",
|
|
|
|
],
|
|
|
|
) -> dict:
|
|
|
|
new_dict = vars.copy()
|
|
|
|
for k in keys:
|
|
|
|
del new_dict[k]
|
|
|
|
return new_dict
|
|
|
|
|
|
|
|
|
2022-07-19 13:15:06 +00:00
|
|
|
def config_from_file(filename: str) -> dict:
|
|
|
|
if Path(filename).exists():
|
|
|
|
local_config = vars(load_module(filename))
|
|
|
|
return clean_vars_keys(local_config)
|
|
|
|
else:
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|
def build_config(options: dict) -> dict:
|
|
|
|
"""Look for options["configfile"] to load it with default_config and options"""
|
|
|
|
configfile = ""
|
2022-05-05 12:35:01 +00:00
|
|
|
try:
|
2022-07-19 13:15:06 +00:00
|
|
|
configfile = options["configfile"]
|
2022-05-05 12:35:01 +00:00
|
|
|
except KeyError:
|
2022-07-19 13:15:06 +00:00
|
|
|
pass
|
|
|
|
try:
|
|
|
|
configfile = os.environ["BOPYTEXCONFIG"]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
local_config = config_from_file(configfile)
|
2022-05-05 12:35:01 +00:00
|
|
|
|
|
|
|
config = clean_vars_keys(vars(default_config))
|
|
|
|
config.update(local_config)
|
|
|
|
config.update(options)
|
|
|
|
return config
|
|
|
|
|
|
|
|
|
2022-05-04 19:16:27 +00:00
|
|
|
def main(**options):
|
|
|
|
|
2022-07-19 13:15:06 +00:00
|
|
|
config = build_config(options)
|
2022-05-04 19:16:27 +00:00
|
|
|
|
|
|
|
orcherstre = orcherstrator(
|
2022-05-05 12:35:01 +00:00
|
|
|
config, planner=default_config.planner, dispatcher=default_config.dispatcher
|
2022-05-04 19:16:27 +00:00
|
|
|
)
|
|
|
|
for message in orcherstre:
|
|
|
|
yield message
|
2017-04-16 08:36:27 +00:00
|
|
|
|
2022-05-05 12:35:01 +00:00
|
|
|
|
2013-09-27 18:09:38 +00:00
|
|
|
# -----------------------------
|
|
|
|
# Reglages pour 'vim'
|
|
|
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
2017-04-16 08:36:27 +00:00
|
|
|
# cursor: 16 del
|