Browse Source

Adding datasourc boostrapîng instructions in leaftory generated dyncode

+ better log message for datasource bootstrap
Yann Weber 9 years ago
parent
commit
b683d68d83
2 changed files with 12 additions and 3 deletions
  1. 7
    1
      lodel/leapi/lefactory.py
  2. 5
    2
      lodel/leapi/leobject.py

+ 7
- 1
lodel/leapi/lefactory.py View File

125
     datasource_name = repr(datasource_name),
125
     datasource_name = repr(datasource_name),
126
 )
126
 )
127
         res += em_cls_code
127
         res += em_cls_code
128
-        # Dyncode bootstrap instructions
128
+        # Dyncode fields bootstrap instructions
129
         bootstrap += """{classname}._set__fields({fields})
129
         bootstrap += """{classname}._set__fields({fields})
130
 """.format(
130
 """.format(
131
     classname = LeObject.name2objname(em_class.uid),
131
     classname = LeObject.name2objname(em_class.uid),
132
     fields = '{' + (', '.join(['\n\t%s: %s' % (repr(emfield.uid),data_handler_constructor(emfield)) for emfield in em_class.fields()])) + '}',
132
     fields = '{' + (', '.join(['\n\t%s: %s' % (repr(emfield.uid),data_handler_constructor(emfield)) for emfield in em_class.fields()])) + '}',
133
 )
133
 )
134
+    bootstrap += "\n"
135
+    for em_class in get_classes(model):
136
+        # Dyncode datasource bootstrap instructions
137
+        bootstrap += """{classname}._init_datasource()
138
+""".format(
139
+            classname = LeObject.name2objname(em_class.uid))
134
     return res, set(imports), bootstrap
140
     return res, set(imports), bootstrap
135
     
141
     

+ 5
- 2
lodel/leapi/leobject.py View File

192
     @classmethod
192
     @classmethod
193
     def _init_datasource(cls):
193
     def _init_datasource(cls):
194
         expt_msg = "In LeAPI class '%s' " % cls.__name__
194
         expt_msg = "In LeAPI class '%s' " % cls.__name__
195
+        datasource_orig_name = cls._datasource
195
         if cls._datasource not in Settings.datasources._fields:
196
         if cls._datasource not in Settings.datasources._fields:
196
             expt_msg += "Unknow or unconfigured datasource %s"
197
             expt_msg += "Unknow or unconfigured datasource %s"
197
             expt_msg %= (cls._datasource, cls.__name__)
198
             expt_msg %= (cls._datasource, cls.__name__)
198
             raise SettingsError(expt_msg)
199
             raise SettingsError(expt_msg)
199
-
200
+        
200
         ds_identifier = getattr(Settings.datasources, cls._datasource)
201
         ds_identifier = getattr(Settings.datasources, cls._datasource)
201
         try:
202
         try:
202
             ds_identifier = getattr(ds_identifier, 'identifier')
203
             ds_identifier = getattr(ds_identifier, 'identifier')
228
             expt_msg += "The datasource plugin %s seems to be invalid. Error raised when trying to import Datasource"
229
             expt_msg += "The datasource plugin %s seems to be invalid. Error raised when trying to import Datasource"
229
             expt_msg %= ds_identifier
230
             expt_msg %= ds_identifier
230
             raise SettingsError(expt_msg)
231
             raise SettingsError(expt_msg)
231
-        logger.debug("Datasource initialized for LeObject %s" % cls.__name__)
232
+        log_msg = "Datasource %s initialized for LeObject %s"
233
+        log_msg %= (datasource_orig_name, cls.__name__)
234
+        logger.debug(log_msg)
232
 
235
 
233
     ##@brief Read only access to all datas
236
     ##@brief Read only access to all datas
234
     # @note for fancy data accessor use @ref LeObject.g attribute @ref LeObjectValues instance
237
     # @note for fancy data accessor use @ref LeObject.g attribute @ref LeObjectValues instance

Loading…
Cancel
Save