load CUSTOMTYPES every time with all modules

This commit is contained in:
Emmanuel Garette 2020-03-16 14:49:36 +01:00
parent efb8f22872
commit 963fe2a9b6

View File

@ -15,8 +15,6 @@ from .utils import _
MESSAGE_ROOT_PATH = get_config()['global']['message_root_path']
CUSTOMTYPES = {}
groups.addgroup('message')
@ -388,13 +386,14 @@ class CustomType:
return self.title
def load_customtypes(current_module_names: str) -> None:
def load_customtypes() -> None:
versions = listdir(MESSAGE_ROOT_PATH)
versions.sort()
ret = {}
for version in versions:
if version not in CUSTOMTYPES:
CUSTOMTYPES[version] = {}
for current_module_name in current_module_names:
if version not in ret:
ret[version] = {}
for current_module_name in listdir(join(MESSAGE_ROOT_PATH, version)):
types_path = join(MESSAGE_ROOT_PATH,
version,
current_module_name,
@ -407,10 +406,10 @@ def load_customtypes(current_module_names: str) -> None:
with open(path, "r") as message_file:
try:
custom_type = CustomType(load(message_file, Loader=SafeLoader))
CUSTOMTYPES[version][custom_type.getname()] = custom_type
ret[version][custom_type.getname()] = custom_type
except Exception as err:
raise Exception(_(f'enable to load type {err}: {message}'))
return ret
def _get_description(description,
@ -577,7 +576,6 @@ def get_messages(current_module_names,
uris=None):
"""generate description from yml files
"""
global CUSTOMTYPES
optiondescriptions = {}
optiondescriptions_info = {}
messages = list(list_messages(uris,
@ -589,14 +587,6 @@ def get_messages(current_module_names,
'Nom du message.',
tuple(optiondescriptions_name),
properties=frozenset(['mandatory', 'positional']))
if current_module_names is None:
CUSTOMTYPES = {}
if not CUSTOMTYPES:
if current_module_names is None:
for version in listdir(MESSAGE_ROOT_PATH):
load_customtypes(listdir(join(MESSAGE_ROOT_PATH, version)))
else:
load_customtypes(current_module_names)
for uri in messages:
message_def = get_message(uri,
current_module_names,
@ -620,6 +610,7 @@ def get_messages(current_module_names,
root = _get_root_option(select_option,
optiondescriptions)
if current_module_names is None:
CUSTOMTYPES = {}
return optiondescriptions_info, root
CUSTOMTYPES = load_customtypes()