|
@@ -16,3 +16,58 @@ def generate_dyncode(model_file, translator):
|
16
|
16
|
model = EditorialModel.load(translator, filename=model_file)
|
17
|
17
|
dyncode = lefactory.dyncode_from_em(model)
|
18
|
18
|
return dyncode
|
|
19
|
+
|
|
20
|
+def init_all_datasources(dyncode):
|
|
21
|
+ from lodel.plugin.datasource_plugin import DatasourcePlugin
|
|
22
|
+ from lodel import logger
|
|
23
|
+
|
|
24
|
+ ds_cls = dict() # EmClass indexed by rw_datasource
|
|
25
|
+ for cls in dyncode.dynclasses:
|
|
26
|
+ ds = cls._datasource_name
|
|
27
|
+ if ds not in ds_cls:
|
|
28
|
+ ds_cls[ds] = [cls]
|
|
29
|
+ else:
|
|
30
|
+ ds_cls[ds].append(cls)
|
|
31
|
+
|
|
32
|
+ for ds_name in ds_cls:
|
|
33
|
+ mh = DatasourcePlugin.init_migration_handler(ds_name)
|
|
34
|
+ #Retrieve plugin_name & ds_identifier for logging purpose
|
|
35
|
+ plugin_name, ds_identifier = DatasourcePlugin.plugin_name(
|
|
36
|
+ ds_name, False)
|
|
37
|
+ try:
|
|
38
|
+ mh.init_db(ds_cls[ds_name])
|
|
39
|
+ except Exception as e:
|
|
40
|
+ msg = "Migration failed for datasource %s(%s.%s) when running \
|
|
41
|
+init_db method: %s"
|
|
42
|
+ msg %= (ds_name, plugin_name, ds_identifier, e)
|
|
43
|
+ logger.info("Database initialisation done for %s(%s.%s)" % (
|
|
44
|
+ ds_name, plugin_name, ds_identifier))
|
|
45
|
+
|
|
46
|
+def list_registered_hooks():
|
|
47
|
+ from lodel.plugin.hooks import LodelHook
|
|
48
|
+ from lodel.plugin.plugins import Plugin
|
|
49
|
+
|
|
50
|
+ Plugin.load_all()
|
|
51
|
+ hlist = LodelHook.hook_list()
|
|
52
|
+ print("Registered hooks are : ")
|
|
53
|
+ for name in sorted(hlist.keys()):
|
|
54
|
+ print("\t- %s is registered by : " % name)
|
|
55
|
+ for reg_hook in hlist[name]:
|
|
56
|
+ hook, priority = reg_hook
|
|
57
|
+ msg = "\t\t- {modname}.{funname} with priority : {priority}"
|
|
58
|
+ msg = msg.format(
|
|
59
|
+ modname = hook.__module__,
|
|
60
|
+ funname = hook.__name__,
|
|
61
|
+ priority = priority)
|
|
62
|
+ print(msg)
|
|
63
|
+ print("\n")
|
|
64
|
+
|
|
65
|
+##@brief update plugin's discover cache
|
|
66
|
+def update_plugin_discover_cache(path_list = None):
|
|
67
|
+ os.environ['LODEL2_NO_SETTINGS_LOAD'] = 'True'
|
|
68
|
+ from lodel.plugin.plugins import Plugin
|
|
69
|
+ res = Plugin.discover(path_list)
|
|
70
|
+ print("Plugin discover result in %s :\n" % res['path_list'])
|
|
71
|
+ for pname, pinfos in res['plugins'].items():
|
|
72
|
+ print("\t- %s %s -> %s" % (
|
|
73
|
+ pname, pinfos['version'], pinfos['path']))
|