Hicham Benjelloun 7 years ago
parent
commit
1eb20f794d

+ 3
- 6
lodel/leapi/datahandlers/base_classes.py View File

391
             logger.warning('Class of the back_reference given is not an allowed class')
391
             logger.warning('Class of the back_reference given is not an allowed class')
392
             return False
392
             return False
393
         value = datas[fname]
393
         value = datas[fname]
394
-        if not target_class.is_exist(value):
394
+        target_uidfield = target_class.uid_fieldname()[0]  # multi uid broken here
395
+        obj = target_class.get([(target_uidfield, '=', value)])
396
+        if len(obj) == 0:
395
             logger.warning('Object referenced does not exist')
397
             logger.warning('Object referenced does not exist')
396
             return False
398
             return False
397
-        # target_uidfield = target_class.uid_fieldname()[0] #multi uid broken here
398
-        # obj = target_class.get([(target_uidfield, '=', value)])
399
-        # if len(obj) == 0:
400
-        #    logger.warning('Object referenced does not exist')
401
-        #    return False
402
         return True
399
         return True
403
 
400
 
404
     # @brief Utility method designed to fetch referenced objects
401
     # @brief Utility method designed to fetch referenced objects

+ 0
- 9
lodel/leapi/leobject.py View File

654
         elif len(res) == 0:
654
         elif len(res) == 0:
655
             return None
655
             return None
656
         return res[0]
656
         return res[0]
657
-
658
-    # @brief Checks if an object exists
659
-    @classmethod
660
-    def is_exist(cls, uid):
661
-        if cls.uid_fieldname() is None:
662
-            raise LodelFatalError(
663
-                "No uid defined for class %s" % cls.__name__)
664
-        from .query import is_exist
665
-        return is_exist(cls, uid)

+ 19
- 33
lodel/leapi/query.py View File

7
 
7
 
8
 from lodel.context import LodelContext
8
 from lodel.context import LodelContext
9
 LodelContext.expose_modules(globals(), {
9
 LodelContext.expose_modules(globals(), {
10
-    'lodel.leapi.exceptions': ['LeApiError', 'LeApiErrors', 
10
+    'lodel.leapi.exceptions': ['LeApiError', 'LeApiErrors',
11
         'LeApiDataCheckError', 'LeApiDataCheckErrors', 'LeApiQueryError',
11
         'LeApiDataCheckError', 'LeApiDataCheckErrors', 'LeApiQueryError',
12
         'LeApiQueryErrors'],
12
         'LeApiQueryErrors'],
13
     'lodel.plugin.hooks': ['LodelHook'],
13
     'lodel.plugin.hooks': ['LodelHook'],
14
     'lodel.logger': ['logger']})
14
     'lodel.logger': ['logger']})
15
 
15
 
16
-##@brief Tool to check if a target_class's object exists and is stored
17
-#@param target_class : class where the object is supposed to be
18
-#@param uid : a unique id in target_class
19
-#@returns true if an object with unique id uid exists in target_class, false if not
20
-def is_exist(target_class, uid):
21
-	from .leobject import LeObject
22
-	if not inspect.isclass(target_class) or not issubclass(target_class, LeObject):
23
-		raise TypeError("target class has to be a child class of LeObject but %s was given"% target_class)
24
-	datasource = target_class._ro_datasource
25
-	return datasource.is_exist(target_class,uid)
26
-
27
-
28
 ##@todo check datas when running query
16
 ##@todo check datas when running query
29
 class LeQuery(object):
17
 class LeQuery(object):
30
-    
18
+
31
     ##@brief Hookname prefix
19
     ##@brief Hookname prefix
32
     _hook_prefix = None
20
     _hook_prefix = None
33
     ##@brief arguments for the LeObject.check_data_value()
21
     ##@brief arguments for the LeObject.check_data_value()
73
     #@return query result
61
     #@return query result
74
     def _query(self, **datas):
62
     def _query(self, **datas):
75
         raise NotImplementedError("Asbtract method")
63
         raise NotImplementedError("Asbtract method")
76
-    
64
+
77
     ##@return a dict with query infos
65
     ##@return a dict with query infos
78
     def dump_infos(self):
66
     def dump_infos(self):
79
         return {'target_class': self._target_class}
67
         return {'target_class': self._target_class}
118
         self.subqueries = None
106
         self.subqueries = None
119
         query_filters = [] if query_filters is None else query_filters
107
         query_filters = [] if query_filters is None else query_filters
120
         self.set_query_filter(query_filters)
108
         self.set_query_filter(query_filters)
121
-    
109
+
122
     ##@brief Abstract FilteredQuery execution method
110
     ##@brief Abstract FilteredQuery execution method
123
     #
111
     #
124
     # This method takes care to execute subqueries before calling super execute
112
     # This method takes care to execute subqueries before calling super execute
439
     #<pre>contributeur IN (1,2,3,5)</pre> will be transformed into :
427
     #<pre>contributeur IN (1,2,3,5)</pre> will be transformed into :
440
     #<pre>(
428
     #<pre>(
441
     #       (
429
     #       (
442
-    #           contributeur, 
430
+    #           contributeur,
443
     #           {
431
     #           {
444
     #               auteur: 'lodel_id',
432
     #               auteur: 'lodel_id',
445
     #               traducteur: 'lodel_id'
433
     #               traducteur: 'lodel_id'
494
             raise LeApiQueryError("Trying to create an insert query on an \
482
             raise LeApiQueryError("Trying to create an insert query on an \
495
 abstract LeObject : %s" % target_class)
483
 abstract LeObject : %s" % target_class)
496
         super().__init__(target_class)
484
         super().__init__(target_class)
497
-    
485
+
498
     ## @brief Implements an insert query operation, with only one insertion
486
     ## @brief Implements an insert query operation, with only one insertion
499
     # @param datas : datas to be inserted
487
     # @param datas : datas to be inserted
500
     def _query(self, datas):
488
     def _query(self, datas):
536
     #@todo change strategy with instance update. We have to accept datas for
524
     #@todo change strategy with instance update. We have to accept datas for
537
     #the execute method
525
     #the execute method
538
     def __init__(self, target, query_filters=None):
526
     def __init__(self, target, query_filters=None):
539
-        ##@brief This attr is set only if the target argument is an 
527
+        ##@brief This attr is set only if the target argument is an
540
         #instance of a LeObject subclass
528
         #instance of a LeObject subclass
541
         self.__leobject_instance_datas = None
529
         self.__leobject_instance_datas = None
542
         target_class = target
530
         target_class = target
565
             #Instance update
553
             #Instance update
566
             #Building query_filter
554
             #Building query_filter
567
             filters = [(
555
             filters = [(
568
-                uid_name, 
569
-                '=', 
556
+                uid_name,
557
+                '=',
570
                 str(self.__leobject_instance_datas[uid_name]))]
558
                 str(self.__leobject_instance_datas[uid_name]))]
571
             res = self._rw_datasource.update(
559
             res = self._rw_datasource.update(
572
                 self._target_class, filters, [],
560
                 self._target_class, filters, [],
712
         l_datas=self._ro_datasource.select(
700
         l_datas=self._ro_datasource.select(
713
             target = self._target_class,
701
             target = self._target_class,
714
             field_list = fl,
702
             field_list = fl,
715
-            filters = self._query_filter[0], 
716
-            relational_filters = self._query_filter[1], 
717
-            order = self._order, 
718
-            group = self._group, 
719
-            limit = self._limit, 
703
+            filters = self._query_filter[0],
704
+            relational_filters = self._query_filter[1],
705
+            order = self._order,
706
+            group = self._group,
707
+            limit = self._limit,
720
             offset = self._offset)
708
             offset = self._offset)
721
         return l_datas
709
         return l_datas
722
 
710
 
723
     ##@return a dict with query infos
711
     ##@return a dict with query infos
724
     def dump_infos(self):
712
     def dump_infos(self):
725
         ret = super().dump_infos()
713
         ret = super().dump_infos()
726
-        ret.update({  'field_list' : self._field_list, 
727
-                        'order' : self._order, 
728
-                        'group' : self._group, 
729
-                        'limit' : self._limit, 
730
-                        'offset': self._offset, 
714
+        ret.update({  'field_list' : self._field_list,
715
+                        'order' : self._order,
716
+                        'group' : self._group,
717
+                        'limit' : self._limit,
718
+                        'offset': self._offset,
731
        })
719
        })
732
         return ret
720
         return ret
733
 
721
 
742
                 res %= (n, subq)
730
                 res %= (n, subq)
743
         res += ">"
731
         res += ">"
744
         return res
732
         return res
745
-
746
-

+ 44
- 46
lodel/plugin/plugins.py View File

33
 #
33
 #
34
 #@todo Check if the symlink in the lodelcontext dir is obsolete !!!
34
 #@todo Check if the symlink in the lodelcontext dir is obsolete !!!
35
 #@warning The plugins dir is at two locations : in lodel package and in
35
 #@warning The plugins dir is at two locations : in lodel package and in
36
-#instance directory. Some stuff seems to still needs plugins to be in 
36
+#instance directory. Some stuff seems to still needs plugins to be in
37
 #the instance directory but it seems to be a really bad idea...
37
 #the instance directory but it seems to be a really bad idea...
38
 
38
 
39
 ##@defgroup plugin_init_specs Plugins __init__.py specifications
39
 ##@defgroup plugin_init_specs Plugins __init__.py specifications
67
 
67
 
68
 ##@brief List storing the mandatory variables expected in a plugin __init__.py
68
 ##@brief List storing the mandatory variables expected in a plugin __init__.py
69
 #file
69
 #file
70
-MANDATORY_VARNAMES = [PLUGIN_NAME_VARNAME, LOADER_FILENAME_VARNAME, 
70
+MANDATORY_VARNAMES = [PLUGIN_NAME_VARNAME, LOADER_FILENAME_VARNAME,
71
     PLUGIN_VERSION_VARNAME]
71
     PLUGIN_VERSION_VARNAME]
72
 
72
 
73
 ##@brief Default plugin type
73
 ##@brief Default plugin type
122
         elif len(args) > 3:
122
         elif len(args) > 3:
123
             raise PluginError("Expected between 1 and 3 positional arguments \
123
             raise PluginError("Expected between 1 and 3 positional arguments \
124
 but %d arguments found" % len(args))
124
 but %d arguments found" % len(args))
125
-        else: 
125
+        else:
126
             for i,v in enumerate(args):
126
             for i,v in enumerate(args):
127
                 self.__version[i] = int(v)
127
                 self.__version[i] = int(v)
128
         #Checks that version numbering is correct
128
         #Checks that version numbering is correct
144
     @property
144
     @property
145
     def revision(self):
145
     def revision(self):
146
         return self.__version[2]
146
         return self.__version[2]
147
-    
147
+
148
     ##@brief Check and prepare comparisoon argument
148
     ##@brief Check and prepare comparisoon argument
149
     #@return A PluginVersion instance
149
     #@return A PluginVersion instance
150
     #@throw PluginError if invalid argument provided
150
     #@throw PluginError if invalid argument provided
157
                 raise PluginError("Cannot compare argument '%s' with \
157
                 raise PluginError("Cannot compare argument '%s' with \
158
 a PluginVerison instance" % other)
158
 a PluginVerison instance" % other)
159
         return other
159
         return other
160
-    
160
+
161
     ##@brief Allow accessing to versions parts using interger index
161
     ##@brief Allow accessing to versions parts using interger index
162
     #@param key int : index
162
     #@param key int : index
163
     #@return major for key == 0, minor for key == 1, revision for key == 2
163
     #@return major for key == 0, minor for key == 1, revision for key == 2
213
 #
213
 #
214
 #Automatic script registration on child class declaration
214
 #Automatic script registration on child class declaration
215
 class MetaPlugType(type):
215
 class MetaPlugType(type):
216
-        
216
+
217
     ##@brief Dict storing all plugin types
217
     ##@brief Dict storing all plugin types
218
     #
218
     #
219
     #key is the _type_conf_name and value is the class
219
     #key is the _type_conf_name and value is the class
227
             return
227
             return
228
         #Regitering a new plugin type
228
         #Regitering a new plugin type
229
         MetaPlugType._all_ptypes[self._type_conf_name] = self
229
         MetaPlugType._all_ptypes[self._type_conf_name] = self
230
-    
230
+
231
     ##@brief Accessor to the list of plugin types
231
     ##@brief Accessor to the list of plugin types
232
     #@return A copy of _all_ptypes attribute (a dict with typename as key
232
     #@return A copy of _all_ptypes attribute (a dict with typename as key
233
     #and the class as value)
233
     #and the class as value)
234
     @classmethod
234
     @classmethod
235
     def all_types(cls):
235
     def all_types(cls):
236
         return copy.copy(cls._all_ptypes)
236
         return copy.copy(cls._all_ptypes)
237
-    
237
+
238
     ##@brief Accessor to the list of plugin names
238
     ##@brief Accessor to the list of plugin names
239
     #@return a list of plugin name
239
     #@return a list of plugin name
240
     @classmethod
240
     @classmethod
241
     def all_ptype_names(cls):
241
     def all_ptype_names(cls):
242
         return list(cls._all_ptypes.keys())
242
         return list(cls._all_ptypes.keys())
243
-    
243
+
244
     ##@brief Given a plugin type name return a Plugin child class
244
     ##@brief Given a plugin type name return a Plugin child class
245
     #@param ptype_name str : a plugin type name
245
     #@param ptype_name str : a plugin type name
246
     #@return A Plugin child class
246
     #@return A Plugin child class
250
         if ptype_name not in cls._all_ptypes:
250
         if ptype_name not in cls._all_ptypes:
251
             raise PluginError("Unknown plugin type '%s'" % ptype_name)
251
             raise PluginError("Unknown plugin type '%s'" % ptype_name)
252
         return cls._all_ptypes[ptype_name]
252
         return cls._all_ptypes[ptype_name]
253
-    
253
+
254
     ##@brief Call the clear classmethod on each child classes
254
     ##@brief Call the clear classmethod on each child classes
255
     @classmethod
255
     @classmethod
256
     def clear_cls(cls):
256
     def clear_cls(cls):
257
         for pcls in cls._all_ptypes.values():
257
         for pcls in cls._all_ptypes.values():
258
             pcls.clear_cls()
258
             pcls.clear_cls()
259
-        
259
+
260
 
260
 
261
 ##@brief Handle plugins
261
 ##@brief Handle plugins
262
 #@ingroup lodel2_plugins
262
 #@ingroup lodel2_plugins
269
 # 2. Settings fetch all confspecs
269
 # 2. Settings fetch all confspecs
270
 # 3. the loader call load_all to register hooks etc
270
 # 3. the loader call load_all to register hooks etc
271
 class Plugin(object, metaclass=MetaPlugType):
271
 class Plugin(object, metaclass=MetaPlugType):
272
-    
272
+
273
     ##@brief Stores Plugin instances indexed by name
273
     ##@brief Stores Plugin instances indexed by name
274
     _plugin_instances = dict()
274
     _plugin_instances = dict()
275
-    
275
+
276
     ##@brief Attribute used by load_all and load methods to detect circular
276
     ##@brief Attribute used by load_all and load methods to detect circular
277
     #dependencies
277
     #dependencies
278
     _load_called = []
278
     _load_called = []
279
 
279
 
280
     ##@brief Attribute that stores plugins list from discover cache file
280
     ##@brief Attribute that stores plugins list from discover cache file
281
     _plugin_list = None
281
     _plugin_list = None
282
-    
282
+
283
     #@brief Designed to store, in child classes, the confspec indicating \
283
     #@brief Designed to store, in child classes, the confspec indicating \
284
     #where plugin list is stored
284
     #where plugin list is stored
285
     _plist_confspecs = None
285
     _plist_confspecs = None
303
     # @param plugin_name str : plugin name
303
     # @param plugin_name str : plugin name
304
     # @throw PluginError
304
     # @throw PluginError
305
     def __init__(self, plugin_name):
305
     def __init__(self, plugin_name):
306
-        
306
+
307
         ##@brief The plugin name
307
         ##@brief The plugin name
308
         self.name = plugin_name
308
         self.name = plugin_name
309
         ##@brief The plugin package path
309
         ##@brief The plugin package path
310
         self.path = self.plugin_path(plugin_name)
310
         self.path = self.plugin_path(plugin_name)
311
-        
311
+
312
         ##@brief Stores the plugin module
312
         ##@brief Stores the plugin module
313
         self.module = None
313
         self.module = None
314
         ##@brief Stores the plugin loader module
314
         ##@brief Stores the plugin loader module
317
         self.__confspecs = dict()
317
         self.__confspecs = dict()
318
         ##@brief Boolean flag telling if the plugin is loaded or not
318
         ##@brief Boolean flag telling if the plugin is loaded or not
319
         self.loaded = False
319
         self.loaded = False
320
-        
320
+
321
         # Importing __init__.py infos in it
321
         # Importing __init__.py infos in it
322
         plugin_module = self.module_name()
322
         plugin_module = self.module_name()
323
         self.module = LodelContext.module(plugin_module)
323
         self.module = LodelContext.module(plugin_module)
398
     #@throw PluginError if the filename was not valid
398
     #@throw PluginError if the filename was not valid
399
     #@todo Some strange things append :
399
     #@todo Some strange things append :
400
     #when loading modules in test self.module.__name__ does not contains
400
     #when loading modules in test self.module.__name__ does not contains
401
-    #the package... but in prod cases the self.module.__name__ is 
401
+    #the package... but in prod cases the self.module.__name__ is
402
     #the module fullname... Just a reminder note to explain the dirty
402
     #the module fullname... Just a reminder note to explain the dirty
403
     #if on self_modname
403
     #if on self_modname
404
     def _import_from_init_var(self, varname):
404
     def _import_from_init_var(self, varname):
428
         base_mod = '.'.join(filename.split('.')[:-1])
428
         base_mod = '.'.join(filename.split('.')[:-1])
429
         module_name = self_modname+"."+base_mod
429
         module_name = self_modname+"."+base_mod
430
         return importlib.import_module(module_name)
430
         return importlib.import_module(module_name)
431
-   
431
+
432
     ##@brief Return associated module name
432
     ##@brief Return associated module name
433
     def module_name(self):
433
     def module_name(self):
434
-        path_array = self.path.split('/')
435
-        if not self.path.startswith('./plugins'):
436
-            raise PluginError("Bad path for plugin %s : %s" % (
437
-                self.name, self.path))
438
-        return '.'.join(['lodel'] + path_array[path_array.index('plugins'):])
434
+        #WOOT WE LOVE DIRTY WORKAROUNDS !!!
435
+        return "lodel.plugins."+os.path.basename(self.path)
436
+        #END OF DIRTY WORKAROUND
439
 
437
 
440
     ##@brief Check dependencies of plugin
438
     ##@brief Check dependencies of plugin
441
     #@return A list of plugin name to be loaded before
439
     #@return A list of plugin name to be loaded before
455
             raise PluginError(  "Bad dependencie for '%s' :"%self.name,
453
             raise PluginError(  "Bad dependencie for '%s' :"%self.name,
456
                                 ', '.join(errors))
454
                                 ', '.join(errors))
457
         return result
455
         return result
458
-    
456
+
459
     ##@brief Check if the plugin should be activated
457
     ##@brief Check if the plugin should be activated
460
     #
458
     #
461
     #Try to fetch a function called @ref ACTIVATE_METHOD_NAME in __init__.py
459
     #Try to fetch a function called @ref ACTIVATE_METHOD_NAME in __init__.py
473
             logger.debug(msg)
471
             logger.debug(msg)
474
             test_fun = lambda:True
472
             test_fun = lambda:True
475
         return test_fun()
473
         return test_fun()
476
-        
474
+
477
     ##@brief Load a plugin
475
     ##@brief Load a plugin
478
     #
476
     #
479
-    #Loading a plugin means importing a file. The filename is defined in the 
477
+    #Loading a plugin means importing a file. The filename is defined in the
480
     #plugin's __init__.py file in a LOADER_FILENAME_VARNAME variable.
478
     #plugin's __init__.py file in a LOADER_FILENAME_VARNAME variable.
481
     #
479
     #
482
     #The loading process has to take care of other things :
480
     #The loading process has to take care of other things :
498
             raise PluginError("Circular dependencie in Plugin detected. Abording")
496
             raise PluginError("Circular dependencie in Plugin detected. Abording")
499
         else:
497
         else:
500
             self._load_called.append(self.name)
498
             self._load_called.append(self.name)
501
-        
499
+
502
         #Dependencie load
500
         #Dependencie load
503
         for dependencie in self.check_deps():
501
         for dependencie in self.check_deps():
504
             activable = dependencie.activable()
502
             activable = dependencie.activable()
510
                     plugin_name = self.name,
508
                     plugin_name = self.name,
511
                     dep_name = dependencie.name,
509
                     dep_name = dependencie.name,
512
                     reason = activable)
510
                     reason = activable)
513
-        
511
+
514
         #Loading the plugin
512
         #Loading the plugin
515
         try:
513
         try:
516
             self.__loader_module = self._import_from_init_var(LOADER_FILENAME_VARNAME)
514
             self.__loader_module = self._import_from_init_var(LOADER_FILENAME_VARNAME)
524
             raise PluginError(msg)
522
             raise PluginError(msg)
525
         logger.debug("Plugin '%s' loaded" % self.name)
523
         logger.debug("Plugin '%s' loaded" % self.name)
526
         self.loaded = True
524
         self.loaded = True
527
-    
525
+
528
     ##@brief Returns the loader module
526
     ##@brief Returns the loader module
529
     #
527
     #
530
     #Accessor for the __loader__ python module
528
     #Accessor for the __loader__ python module
559
             raise PluginError(msg)
557
             raise PluginError(msg)
560
         LodelHook.call_hook(
558
         LodelHook.call_hook(
561
             "lodel2_plugins_loaded", cls, cls._plugin_instances)
559
             "lodel2_plugins_loaded", cls, cls._plugin_instances)
562
-   
560
+
563
 
561
 
564
     ##@return a copy of __confspecs attr
562
     ##@return a copy of __confspecs attr
565
     @property
563
     @property
593
         return res
591
         return res
594
 
592
 
595
     ##@brief Register a new plugin
593
     ##@brief Register a new plugin
596
-    # 
594
+    #
597
     #@param plugin_name str : The plugin name
595
     #@param plugin_name str : The plugin name
598
     #@return a Plugin instance
596
     #@return a Plugin instance
599
     #@throw PluginError
597
     #@throw PluginError
627
             msg = "No plugin named '%s' loaded"
625
             msg = "No plugin named '%s' loaded"
628
             msg %= plugin_name
626
             msg %= plugin_name
629
             raise PluginError(msg)
627
             raise PluginError(msg)
630
-    
628
+
631
     ##@brief Given a plugin name returns the plugin path
629
     ##@brief Given a plugin name returns the plugin path
632
     # @param plugin_name str : The plugin name
630
     # @param plugin_name str : The plugin name
633
     # @return the plugin directory path
631
     # @return the plugin directory path
643
             pass
641
             pass
644
 
642
 
645
         return plist[plugin_name]['path']
643
         return plist[plugin_name]['path']
646
-    
644
+
647
     ##@brief Return the plugin module name
645
     ##@brief Return the plugin module name
648
     #
646
     #
649
     #This module name is the "virtual" module where we imported the plugin.
647
     #This module name is the "virtual" module where we imported the plugin.
659
         return "%s.%s" % (VIRTUAL_PACKAGE_NAME, plugin_name)
657
         return "%s.%s" % (VIRTUAL_PACKAGE_NAME, plugin_name)
660
 
658
 
661
     ##@brief Start the Plugin class
659
     ##@brief Start the Plugin class
662
-    # 
660
+    #
663
     # Called by Settings.__bootstrap()
661
     # Called by Settings.__bootstrap()
664
     #
662
     #
665
     # This method load path and preload plugins
663
     # This method load path and preload plugins
667
     def start(cls, plugins):
665
     def start(cls, plugins):
668
         for plugin_name in plugins:
666
         for plugin_name in plugins:
669
             cls.register(plugin_name)
667
             cls.register(plugin_name)
670
-    
668
+
671
     ##@brief Attempt to "restart" the Plugin class
669
     ##@brief Attempt to "restart" the Plugin class
672
     @classmethod
670
     @classmethod
673
     def clear(cls):
671
     def clear(cls):
676
         if cls._load_called != []:
674
         if cls._load_called != []:
677
             cls._load_called = []
675
             cls._load_called = []
678
         MetaPlugType.clear_cls()
676
         MetaPlugType.clear_cls()
679
-    
677
+
680
     ##@brief Designed to be implemented by child classes
678
     ##@brief Designed to be implemented by child classes
681
     @classmethod
679
     @classmethod
682
     def clear_cls(cls):
680
     def clear_cls(cls):
683
         pass
681
         pass
684
-    
682
+
685
     ##@brief Reccursively walk throught paths to find plugin, then stores
683
     ##@brief Reccursively walk throught paths to find plugin, then stores
686
     #found plugin in a static var
684
     #found plugin in a static var
687
     #
685
     #
699
         result = dict()
697
         result = dict()
700
         for pinfos in tmp_res:
698
         for pinfos in tmp_res:
701
             pname = pinfos['name']
699
             pname = pinfos['name']
702
-            if (    pname in result 
700
+            if (    pname in result
703
                     and pinfos['version'] > result[pname]['version'])\
701
                     and pinfos['version'] > result[pname]['version'])\
704
                 or pname not in result:
702
                 or pname not in result:
705
                 result[pname] = pinfos
703
                 result[pname] = pinfos
708
                 pass
706
                 pass
709
         cls._plugin_list = result
707
         cls._plugin_list = result
710
         return result
708
         return result
711
-    
709
+
712
     ##@brief Return discover result
710
     ##@brief Return discover result
713
     #@param refresh bool : if true invalidate all plugin list cache
711
     #@param refresh bool : if true invalidate all plugin list cache
714
     #@note If discover cache file not found run discover first
712
     #@note If discover cache file not found run discover first
780
             'version': PluginVersion(pversion),
778
             'version': PluginVersion(pversion),
781
             'path': path,
779
             'path': path,
782
             'type': ptype}
780
             'type': ptype}
783
-    
781
+
784
     ##@brief Import init file from a plugin path
782
     ##@brief Import init file from a plugin path
785
     #@param path str : Directory path
783
     #@param path str : Directory path
786
     #@return a tuple (init_module, module_name)
784
     #@return a tuple (init_module, module_name)
857
     ##@brief Decorator constructor
855
     ##@brief Decorator constructor
858
     #@param component_name str : the name of the component to enhance
856
     #@param component_name str : the name of the component to enhance
859
     #@param method_name str : the name of the method to inject (if None given
857
     #@param method_name str : the name of the method to inject (if None given
860
-    #@param method_type int : take value in one of 
858
+    #@param method_type int : take value in one of
861
     #CustomMethod::INSTANCE_METHOD CustomMethod::CLASS_METHOD or
859
     #CustomMethod::INSTANCE_METHOD CustomMethod::CLASS_METHOD or
862
     #CustomMethod::STATIC_METHOD
860
     #CustomMethod::STATIC_METHOD
863
     #use the function name
861
     #use the function name
875
             raise ValueError("Excepted value for method_type was one of \
873
             raise ValueError("Excepted value for method_type was one of \
876
 CustomMethod::INSTANCE_METHOD CustomMethod::CLASS_METHOD or \
874
 CustomMethod::INSTANCE_METHOD CustomMethod::CLASS_METHOD or \
877
 CustomMethod::STATIC_METHOD, but got %s" % self._type)
875
 CustomMethod::STATIC_METHOD, but got %s" % self._type)
878
-    
876
+
879
     ##@brief called just after __init__
877
     ##@brief called just after __init__
880
     #@param fun function : the decorated function
878
     #@param fun function : the decorated function
881
     def __call__(self, fun):
879
     def __call__(self, fun):
891
                 self._custom_methods[self._comp_name].__module__))
889
                 self._custom_methods[self._comp_name].__module__))
892
         self._fun = fun
890
         self._fun = fun
893
         self._custom_methods[self._comp_name].append(self)
891
         self._custom_methods[self._comp_name].append(self)
894
-    
892
+
895
     ##@brief Textual representation
893
     ##@brief Textual representation
896
     #@return textual representation of the CustomMethod instance
894
     #@return textual representation of the CustomMethod instance
897
     def __repr__(self):
895
     def __repr__(self):
902
             classname = self._comp_name,
900
             classname = self._comp_name,
903
             module_name = self._fun.__module__,
901
             module_name = self._fun.__module__,
904
             fun_name = self._fun.__name__)
902
             fun_name = self._fun.__name__)
905
-    
903
+
906
     ##@brief Return a well formed method
904
     ##@brief Return a well formed method
907
     #
905
     #
908
     #@note the type of method depends on the _type attribute
906
     #@note the type of method depends on the _type attribute
924
 
922
 
925
     ##@brief Handle custom method dynamic injection in LeAPI dyncode
923
     ##@brief Handle custom method dynamic injection in LeAPI dyncode
926
     #
924
     #
927
-    #Called by lodel2_dyncode_loaded hook defined at 
925
+    #Called by lodel2_dyncode_loaded hook defined at
928
     #lodel.plugin.core_hooks.lodel2_plugin_custom_methods()
926
     #lodel.plugin.core_hooks.lodel2_plugin_custom_methods()
929
     #
927
     #
930
     #@param cls
928
     #@param cls

+ 1
- 2
lodel/plugins/Makefile.am View File

5
 
5
 
6
 install-data-hook:
6
 install-data-hook:
7
 	mkdir -p ${DESTDIR}$(pluginsdir); cp -R * ${DESTDIR}$(pluginsdir) && rm ${DESTDIR}$(pluginsdir)/Makefile* ;\
7
 	mkdir -p ${DESTDIR}$(pluginsdir); cp -R * ${DESTDIR}$(pluginsdir) && rm ${DESTDIR}$(pluginsdir)/Makefile* ;\
8
-	cd ${DESTDIR}; \
9
-	mkdir -p $(lodel2confdir); \
8
+	mkdir -p ${DESTDIR}$(lodel2confdir); \
10
 	if [ ! -d ${DESTDIR}$(lodel2confdir)/plugins ]; \
9
 	if [ ! -d ${DESTDIR}$(lodel2confdir)/plugins ]; \
11
     then \
10
     then \
12
         ln -rs -t ${DESTDIR}$(lodel2confdir) $(pluginsdir); \
11
         ln -rs -t ${DESTDIR}$(lodel2confdir) $(pluginsdir); \

+ 19
- 17
lodel/plugins/webui/interface/controllers/admin.py View File

19
 ##@brief These functions are called by the rules defined in ../urls.py
19
 ##@brief These functions are called by the rules defined in ../urls.py
20
 ## To administrate the instance of the editorial model
20
 ## To administrate the instance of the editorial model
21
 
21
 
22
-##@brief Controller's function to redirect on the home page of the admin 
22
+##@brief Controller's function to redirect on the home page of the admin
23
 # @param request : the request (get or post)
23
 # @param request : the request (get or post)
24
 # @note the response is given in a html page called in get_response_function
24
 # @note the response is given in a html page called in get_response_function
25
 def index_admin(request):
25
 def index_admin(request):
26
     # We have to be identified to admin the instance
26
     # We have to be identified to admin the instance
27
-    # temporary, the acl will be more restrictive 
27
+    # temporary, the acl will be more restrictive
28
     #if WebUiClient.is_anonymous():
28
     #if WebUiClient.is_anonymous():
29
     #    return get_response('users/signin.html')
29
     #    return get_response('users/signin.html')
30
     return get_response('admin/admin.html')
30
     return get_response('admin/admin.html')
31
 
31
 
32
-##@brief Controller's function to update an object of the editorial model 
32
+##@brief Controller's function to update an object of the editorial model
33
 # @param request : the request (get or post)
33
 # @param request : the request (get or post)
34
 # @note the response is given in a html page (in templates/admin) called in get_response_function
34
 # @note the response is given in a html page (in templates/admin) called in get_response_function
35
 def admin_update(request):
35
 def admin_update(request):
38
     #if WebUiClient.is_anonymous():
38
     #if WebUiClient.is_anonymous():
39
     #    return get_response('users/signin.html')
39
     #    return get_response('users/signin.html')
40
     msg=''
40
     msg=''
41
-    
41
+
42
     datas = process_form(request)
42
     datas = process_form(request)
43
     if not(datas is False):
43
     if not(datas is False):
44
         if 'lodel_id' not in datas:
44
         if 'lodel_id' not in datas:
55
         except LeApiDataCheckErrors as e:
55
         except LeApiDataCheckErrors as e:
56
             raise HttpErrors(
56
             raise HttpErrors(
57
                 title='Form validation errors', errors = e._exceptions)
57
                 title='Form validation errors', errors = e._exceptions)
58
-            
59
-            
58
+
59
+
60
 
60
 
61
     # Display of the form with the object's values to be updated
61
     # Display of the form with the object's values to be updated
62
     if 'classname' in request.GET:
62
     if 'classname' in request.GET:
72
             raise HttpException(400)
72
             raise HttpException(400)
73
         logger.warning('Composed uids broken here')
73
         logger.warning('Composed uids broken here')
74
         uid_field = target_leo.uid_fieldname()[0]
74
         uid_field = target_leo.uid_fieldname()[0]
75
-    
75
+
76
     # We need the uid of the object
76
     # We need the uid of the object
77
     test_valid = 'lodel_id' in request.GET \
77
     test_valid = 'lodel_id' in request.GET \
78
         and len(request.GET['lodel_id']) == 1
78
         and len(request.GET['lodel_id']) == 1
91
     else:
91
     else:
92
         # Check if the object actually exists
92
         # Check if the object actually exists
93
         # We get it from the database
93
         # We get it from the database
94
-        if not target_leo.is_exist(lodel_id):
94
+        query_filters = list()
95
+        query_filters.append((uid_field,'=',lodel_id))
96
+        obj = target_leo.get(query_filters)
97
+        if len(obj) == 0:
95
             raise HttpException(404)
98
             raise HttpException(404)
96
     return get_response('admin/admin_edit.html', target=target_leo, lodel_id =lodel_id)
99
     return get_response('admin/admin_edit.html', target=target_leo, lodel_id =lodel_id)
97
 
100
 
98
-##@brief Controller's function to create an object of the editorial model 
101
+##@brief Controller's function to create an object of the editorial model
99
 # @param request : the request (get or post)
102
 # @param request : the request (get or post)
100
 # @note the response is given in a html page (in templates/admin) called in get_response_function
103
 # @note the response is given in a html page (in templates/admin) called in get_response_function
101
 def admin_create(request):
104
 def admin_create(request):
138
         raise HttpException(400)
141
         raise HttpException(400)
139
     return get_response('admin/admin_create.html', target=target_leo)
142
     return get_response('admin/admin_create.html', target=target_leo)
140
 
143
 
141
-##@brief Controller's function to delete an object of the editorial model 
144
+##@brief Controller's function to delete an object of the editorial model
142
 # @param request : the request (get)
145
 # @param request : the request (get)
143
 # @note the response is given in a html page (in templates/admin) called in get_response_function
146
 # @note the response is given in a html page (in templates/admin) called in get_response_function
144
 def admin_delete(request):
147
 def admin_delete(request):
161
             raise HttpException(400)
164
             raise HttpException(400)
162
         logger.warning('Composed uids broken here')
165
         logger.warning('Composed uids broken here')
163
         uid_field = target_leo.uid_fieldname()[0]
166
         uid_field = target_leo.uid_fieldname()[0]
164
-        
167
+
165
     # We also need the uid of the object to delete
168
     # We also need the uid of the object to delete
166
     test_valid = 'lodel_id' in request.GET \
169
     test_valid = 'lodel_id' in request.GET \
167
         and len(request.GET['lodel_id']) == 1
170
         and len(request.GET['lodel_id']) == 1
186
             msg = 'Object successfully deleted';
189
             msg = 'Object successfully deleted';
187
     else:
190
     else:
188
             msg = 'Oops something wrong happened...object still here'
191
             msg = 'Oops something wrong happened...object still here'
189
-            
192
+
190
     return get_response('admin/admin_delete.html', target=target_leo, lodel_id =lodel_id, msg = msg)
193
     return get_response('admin/admin_delete.html', target=target_leo, lodel_id =lodel_id, msg = msg)
191
 
194
 
192
-        
193
-        
195
+
196
+
194
 def admin_classes(request):
197
 def admin_classes(request):
195
     # We have to be identified to admin the instance
198
     # We have to be identified to admin the instance
196
     # temporary, the acl will be more restrictive
199
     # temporary, the acl will be more restrictive
211
     #if WebUiClient.is_anonymous():
214
     #if WebUiClient.is_anonymous():
212
     #    return get_response('users/signin.html')
215
     #    return get_response('users/signin.html')
213
     return get_response('admin/list_classes_delete.html', my_classes = dyncode.dynclasses)
216
     return get_response('admin/list_classes_delete.html', my_classes = dyncode.dynclasses)
214
-    
217
+
215
 def admin_class(request):
218
 def admin_class(request):
216
     # We have to be identified to admin the instance
219
     # We have to be identified to admin the instance
217
     # temporary, the acl will be more restrictive
220
     # temporary, the acl will be more restrictive
313
                 if hasattr(dh, 'default'):
316
                 if hasattr(dh, 'default'):
314
                     value = dh.default
317
                     value = dh.default
315
                 else:
318
                 else:
316
-                    #if not explicit default value, enforcing default as 
319
+                    #if not explicit default value, enforcing default as
317
                     #an empty list
320
                     #an empty list
318
                     value = []
321
                     value = []
319
             else:
322
             else:
328
         del(res)
331
         del(res)
329
         raise HttpErrors(errors, title="Form validation error")
332
         raise HttpErrors(errors, title="Form validation error")
330
     return res
333
     return res
331
-

+ 11
- 5
lodel/plugins/webui/interface/controllers/listing.py View File

32
 def issue(request):
32
 def issue(request):
33
     lodel_id = request.GET['lodel_id']
33
     lodel_id = request.GET['lodel_id']
34
     return get_response('listing/issue.html', lodel_id=lodel_id[0], my_classes=dyncode )
34
     return get_response('listing/issue.html', lodel_id=lodel_id[0], my_classes=dyncode )
35
-    
35
+
36
 ##@brief Controller's function to display a type (class) of the editorial model
36
 ##@brief Controller's function to display a type (class) of the editorial model
37
 # @param request : the request (get or post)
37
 # @param request : the request (get or post)
38
 # @note the response is given in a html page called in get_response_function
38
 # @note the response is given in a html page called in get_response_function
65
             classname = None
65
             classname = None
66
     else:
66
     else:
67
         raise HttpException(400)
67
         raise HttpException(400)
68
-    
68
+
69
     logger.warning('Composed uids broken here')
69
     logger.warning('Composed uids broken here')
70
     uid_field = target_leo.uid_fieldname()[0]
70
     uid_field = target_leo.uid_fieldname()[0]
71
 
71
 
82
     if not test_valid:
82
     if not test_valid:
83
         raise HttpException(400)
83
         raise HttpException(400)
84
     else:
84
     else:
85
-        if not target_leo.is_exist(lodel_id):
85
+        query_filters = list()
86
+        query_filters.append((uid_field,'=',lodel_id))
87
+        obj = target_leo.get(query_filters)
88
+        if len(obj) == 0:
86
             raise HttpException(404)
89
             raise HttpException(404)
87
     return get_response('listing/show_object.html', lodel_id=lodel_id, classname=classname)
90
     return get_response('listing/show_object.html', lodel_id=lodel_id, classname=classname)
88
 
91
 
101
             classname = None
104
             classname = None
102
     else:
105
     else:
103
         raise HttpException(400)
106
         raise HttpException(400)
104
-    
107
+
105
     logger.warning('Composed uids broken here')
108
     logger.warning('Composed uids broken here')
106
     uid_field = target_leo.uid_fieldname()[0]
109
     uid_field = target_leo.uid_fieldname()[0]
107
 
110
 
118
     if not test_valid:
121
     if not test_valid:
119
         raise HttpException(400)
122
         raise HttpException(400)
120
     else:
123
     else:
121
-        if not target_leo.is_exist(lodel_id):
124
+        query_filters = list()
125
+        query_filters.append((uid_field,'=',lodel_id))
126
+        obj = target_leo.get(query_filters)
127
+        if len(obj) == 0:
122
             raise HttpException(404)
128
             raise HttpException(404)
123
 
129
 
124
     return get_response('listing/show_object_detailled.html', lodel_id=lodel_id, classname=classname)
130
     return get_response('listing/show_object_detailled.html', lodel_id=lodel_id, classname=classname)

+ 4
- 0
lodel/plugins/webui/templates/admin/editable_component.html View File

10
             <input id="{{fieldname}}" name="field_input_{{fieldname}}" class="form-control" type="password"  value="{{sval}}" >
10
             <input id="{{fieldname}}" name="field_input_{{fieldname}}" class="form-control" type="password"  value="{{sval}}" >
11
     {% elif field.base_type == 'char' or field.base_type == 'int' %}
11
     {% elif field.base_type == 'char' or field.base_type == 'int' %}
12
 		<input id="{{fieldname}}" class="form-control" name="field_input_{{fieldname}}" type="text" value="{{value}}" >
12
 		<input id="{{fieldname}}" class="form-control" name="field_input_{{fieldname}}" type="text" value="{{value}}" >
13
+		{% elif field.base_type == 'text' %}
14
+			<textarea class="form-control" name="field_input_{{fieldname}}">{{value}}</textarea>
15
+		{% elif field.base_type == 'datetime' %}
16
+			<input class="form-control" type="date" value="{{value}}" name="field_input_{{fieldname}}">
13
     {% elif field.base_type == 'ref' %}
17
     {% elif field.base_type == 'ref' %}
14
         {% if value is iterable %}
18
         {% if value is iterable %}
15
             {% set sval=value|join(',') %}
19
             {% set sval=value|join(',') %}

progs/create_datas.sh → progs/create_data.sh View File


progs/create_datas_simpleem.sh → progs/create_data_simpleem.sh View File

2
 
2
 
3
 usage() {
3
 usage() {
4
     echo -e "Usage : $0 host_of_server instance_name host_of_db number_of_iterations >&2"
4
     echo -e "Usage : $0 host_of_server instance_name host_of_db number_of_iterations >&2"
5
-    echo -e "Example : create_datas locahost instance_00001 localhost:28015 1000"
6
-    echo -e "Example : create_datas locahost instance_00001 localhost 1000"
5
+    echo -e "Example : create_data_simpleem locahost instance_00001 localhost:28015 1000"
6
+    echo -e "Example : create_data_simpleem locahost instance_00001 localhost 1000"
7
     exit 1
7
     exit 1
8
 }
8
 }
9
 
9
 
18
 N=$4
18
 N=$4
19
 HOSTDB=$3
19
 HOSTDB=$3
20
 dbname=lodel2_$instance
20
 dbname=lodel2_$instance
21
-dbuser=admin 
21
+dbuser=admin
22
 dbpwd=pass
22
 dbpwd=pass
23
 curl_options='--silent -o /dev/null -s -w %{url_effective};%{http_code};%{time_connect};%{time_starttransfer};%{time_total}\n'
23
 curl_options='--silent -o /dev/null -s -w %{url_effective};%{http_code};%{time_connect};%{time_starttransfer};%{time_total}\n'
24
 
24
 
30
     FN=$(lenmax=20;wcount=1; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
30
     FN=$(lenmax=20;wcount=1; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
31
     LC=''
31
     LC=''
32
     curl -o /dev/null -s -d "field_input_lastname=$LN&field_input_firstname=$FN&field_input_linked_containers=$LC&classname=Person" http://$host/$instance/admin/create?classname=Person
32
     curl -o /dev/null -s -d "field_input_lastname=$LN&field_input_firstname=$FN&field_input_linked_containers=$LC&classname=Person" http://$host/$instance/admin/create?classname=Person
33
-    
33
+
34
     # Classe User
34
     # Classe User
35
     PWD='pwgen 10'
35
     PWD='pwgen 10'
36
     LOGIN="${FN,,}$(printf "%d" $RANDOM)"
36
     LOGIN="${FN,,}$(printf "%d" $RANDOM)"
37
     curl -o /dev/null -s -d "field_input_lastname=$LN&field_input_firstname=$FN&field_input_password=$PWD&field_input_login=$LOGIN&classname=User" http://$host/$instance/admin/create?classname=User
37
     curl -o /dev/null -s -d "field_input_lastname=$LN&field_input_firstname=$FN&field_input_password=$PWD&field_input_login=$LOGIN&classname=User" http://$host/$instance/admin/create?classname=User
38
-    
38
+
39
     # Classe Entry, champs à remplir : name, description, role, linked_texts
39
     # Classe Entry, champs à remplir : name, description, role, linked_texts
40
     ENLT='' #$(printf "use $dbname\nDBQuery.shellBatchSize = 30000\n db.Article.find({}, {lodel_id:1, _id:0})" | mongo  $HOSTDB/admin -u $dbuser -p $dbpwd | sed "1,3d" | sed -e "s/{ \"lodel_id\" : //g" | sed -e "s/ }//g" | shuf | head -n 3; )
40
     ENLT='' #$(printf "use $dbname\nDBQuery.shellBatchSize = 30000\n db.Article.find({}, {lodel_id:1, _id:0})" | mongo  $HOSTDB/admin -u $dbuser -p $dbpwd | sed "1,3d" | sed -e "s/{ \"lodel_id\" : //g" | sed -e "s/ }//g" | shuf | head -n 3; )
41
     ENROLE=$(shuf -e 'geography' 'subject' 'keywords' | head -n 1)
41
     ENROLE=$(shuf -e 'geography' 'subject' 'keywords' | head -n 1)
62
         fi
62
         fi
63
     done
63
     done
64
     COLLD=$tmp
64
     COLLD=$tmp
65
-    COLT=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
66
-    COLST=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
65
+    COLT=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
66
+    COLST=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
67
     LG=$(shuf -e 'fr' 'en' 'es' 'ger' 'it'| head -n 1)
67
     LG=$(shuf -e 'fr' 'en' 'es' 'ger' 'it'| head -n 1)
68
-    DESC=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
69
-    PBN=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
68
+    DESC=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
69
+    PBN=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
70
     ISSN=$(</dev/urandom tr -dc 0-9 | head -c8;echo;)
70
     ISSN=$(</dev/urandom tr -dc 0-9 | head -c8;echo;)
71
     curl $curl_options -d "field_input_title=$COLT&field_input_subtitle=$COLST&field_input_language=$LG&field_input_linked_directors=$COLLD&field_input_description=$DESC&field_input_publisher_note=$PBN&field_input_issn=$ISSN&classname=Collection" http://$host/$instance/admin/create?classname=Collection
71
     curl $curl_options -d "field_input_title=$COLT&field_input_subtitle=$COLST&field_input_language=$LG&field_input_linked_directors=$COLLD&field_input_description=$DESC&field_input_publisher_note=$PBN&field_input_issn=$ISSN&classname=Collection" http://$host/$instance/admin/create?classname=Collection
72
     collection=$(printf "use $dbname\n db.Collection.find({}, {lodel_id:1, _id:0}).sort({_id:-1}).limit(1)" | mongo  $HOSTDB/admin -u $dbuser -p $dbpwd | sed "1,3d" | sed -e "s/{ \"lodel_id\" : //g" | sed -e "s/ }//g" | sed "\$d";)
72
     collection=$(printf "use $dbname\n db.Collection.find({}, {lodel_id:1, _id:0}).sort({_id:-1}).limit(1)" | mongo  $HOSTDB/admin -u $dbuser -p $dbpwd | sed "1,3d" | sed -e "s/{ \"lodel_id\" : //g" | sed -e "s/ }//g" | sed "\$d";)
77
         NB=$(shuf -e '25' '30' '35' '40' '45' '50' '55' '60' '65' | head -n 1) # Nombre de textes pour le numéro
77
         NB=$(shuf -e '25' '30' '35' '40' '45' '50' '55' '60' '65' | head -n 1) # Nombre de textes pour le numéro
78
         NBR=$(($NB/3)) # Nombre de reviews
78
         NBR=$(($NB/3)) # Nombre de reviews
79
         NBA=$(($NBR*2)) # Nombre d'articles
79
         NBA=$(($NBR*2)) # Nombre d'articles
80
-        
80
+
81
         # Classe Issue, champs à remplir : title, subtitle, language, linked_directors, description, publisher_note, isbn, print_isbn, number, cover, print_pub_date, e_pub_date, abstract, collection, linked_parts, linked_texts
81
         # Classe Issue, champs à remplir : title, subtitle, language, linked_directors, description, publisher_note, isbn, print_isbn, number, cover, print_pub_date, e_pub_date, abstract, collection, linked_parts, linked_texts
82
         NBLD=$(shuf -e '1' '2' '3' '4' | head -n 1)
82
         NBLD=$(shuf -e '1' '2' '3' '4' | head -n 1)
83
         directors=$(printf "use $dbname\n DBQuery.shellBatchSize = 30000\n db.Person.find({}, {lodel_id:1, _id:0})" | mongo  $HOSTDB/admin -u $dbuser -p $dbpwd | sed "1,4d" | sed -e "s/{ \"lodel_id\" : //g" | sed -e "s/ }//g" | sed "\$d" | shuf | head -n $NBLD;)
83
         directors=$(printf "use $dbname\n DBQuery.shellBatchSize = 30000\n db.Person.find({}, {lodel_id:1, _id:0})" | mongo  $HOSTDB/admin -u $dbuser -p $dbpwd | sed "1,4d" | sed -e "s/{ \"lodel_id\" : //g" | sed -e "s/ }//g" | sed "\$d" | shuf | head -n $NBLD;)
92
             fi
92
             fi
93
         done
93
         done
94
         ISSLD=$tmp
94
         ISSLD=$tmp
95
-        ISST=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
96
-        ISSST=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
95
+        ISST=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
96
+        ISSST=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
97
         LG=$(shuf -e 'fr' 'en' 'es' 'ger' 'it'| head -n 1)
97
         LG=$(shuf -e 'fr' 'en' 'es' 'ger' 'it'| head -n 1)
98
-        DESC=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
99
-        PBN=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
98
+        DESC=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
99
+        PBN=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
100
         ISBN=$(</dev/urandom tr -dc 0-9 | head -c10;echo;)
100
         ISBN=$(</dev/urandom tr -dc 0-9 | head -c10;echo;)
101
         PISBN=$(</dev/urandom tr -dc 0-9 | head -c10;echo;)
101
         PISBN=$(</dev/urandom tr -dc 0-9 | head -c10;echo;)
102
-        ISSNU=$(lenmax=30;wcount=10; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
103
-        ISSCOV=$(lenmax=100;wcount=15; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
102
+        ISSNU=$(lenmax=30;wcount=10; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
103
+        ISSCOV=$(lenmax=100;wcount=15; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
104
         M=$(shuf -e '01' '02' '03' '04' '05' '06' '07' '08' '09' '10' '11' '12' | head -n 1)
104
         M=$(shuf -e '01' '02' '03' '04' '05' '06' '07' '08' '09' '10' '11' '12' | head -n 1)
105
         JJ=$(shuf -e '01' '02' '03' '04' '05' '06' '07' '08' '09' '10' '11' '12' '13' '14' '15' '16' '17' '18' '19' '20' '21' '22' '23' '24' '25' '26' '27' '28'  | head -n 1)
105
         JJ=$(shuf -e '01' '02' '03' '04' '05' '06' '07' '08' '09' '10' '11' '12' '13' '14' '15' '16' '17' '18' '19' '20' '21' '22' '23' '24' '25' '26' '27' '28'  | head -n 1)
106
         AA=$(shuf -e '2012' '2005' '2010' '2015' '2016'| head -n 1)
106
         AA=$(shuf -e '2012' '2005' '2010' '2015' '2016'| head -n 1)
115
         ISSLTXT=''
115
         ISSLTXT=''
116
         curl $curl_options -d "field_input_title=$ISST&field_input_subtitle=$ISSST&field_input_language=$LG&field_input_linked_directors=$ISSLD&field_input_description=$DESC&field_input_publisher_note=$PBN&field_input_isbn=$ISBN&field_input_print_isbn=$PISBN&field_input_number=$ISSNU&field_input_cover=$ISSCOV&field_input_print_pub_date=$PPDATE&field_input_e_pub_date=$EPDATE&field_input_abstract=$ISSAB&field_input_collection=$collection&field_input_linked_parts=$ISSLPA&field_input_linked_texts=$ISSLTXT&classname=Issue" http://$host/$instance/admin/create?classname=Issue
116
         curl $curl_options -d "field_input_title=$ISST&field_input_subtitle=$ISSST&field_input_language=$LG&field_input_linked_directors=$ISSLD&field_input_description=$DESC&field_input_publisher_note=$PBN&field_input_isbn=$ISBN&field_input_print_isbn=$PISBN&field_input_number=$ISSNU&field_input_cover=$ISSCOV&field_input_print_pub_date=$PPDATE&field_input_e_pub_date=$EPDATE&field_input_abstract=$ISSAB&field_input_collection=$collection&field_input_linked_parts=$ISSLPA&field_input_linked_texts=$ISSLTXT&classname=Issue" http://$host/$instance/admin/create?classname=Issue
117
         issue=$(printf "use $dbname\n db.Issue.find({}, {lodel_id:1, _id:0}).sort({_id:-1}).limit(1)" | mongo  $HOSTDB/admin -u $dbuser -p $dbpwd | sed "1,3d" | sed -e "s/{ \"lodel_id\" : //g" | sed -e "s/ }//g" | sed "\$d" )
117
         issue=$(printf "use $dbname\n db.Issue.find({}, {lodel_id:1, _id:0}).sort({_id:-1}).limit(1)" | mongo  $HOSTDB/admin -u $dbuser -p $dbpwd | sed "1,3d" | sed -e "s/{ \"lodel_id\" : //g" | sed -e "s/ }//g" | sed "\$d" )
118
-       
118
+
119
         # On entre les textes correspondants aux numéros indépendemment des parts
119
         # On entre les textes correspondants aux numéros indépendemment des parts
120
         NBT=$(shuf -e '2' '3' '4' '5' '6' '8' | head -n 1)
120
         NBT=$(shuf -e '2' '3' '4' '5' '6' '8' | head -n 1)
121
         for i in `eval echo {1..$NBT}`;
121
         for i in `eval echo {1..$NBT}`;
231
                 fi
231
                 fi
232
             done
232
             done
233
             PALD=$tmp
233
             PALD=$tmp
234
-            PAT=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
235
-            PAST=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
234
+            PAT=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
235
+            PAST=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
236
             LG=$(shuf -e 'fr' 'en' 'es' 'ger' 'it'| head -n 1)
236
             LG=$(shuf -e 'fr' 'en' 'es' 'ger' 'it'| head -n 1)
237
-            DESC=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
238
-            PBN=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
237
+            DESC=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
238
+            PBN=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
239
             issue=$(printf "use $dbname\nDBQuery.shellBatchSize = 1000\n db.Issue.find({collection:$collection}, {lodel_id:1, _id:0})" | mongo  $HOSTDB/admin -u $dbuser -p $dbpwd | sed "1,4d" | sed -e "s/{ \"lodel_id\" : //g" | sed -e "s/ }//g" | sed "\$d" | shuf | head -n 1;)
239
             issue=$(printf "use $dbname\nDBQuery.shellBatchSize = 1000\n db.Issue.find({collection:$collection}, {lodel_id:1, _id:0})" | mongo  $HOSTDB/admin -u $dbuser -p $dbpwd | sed "1,4d" | sed -e "s/{ \"lodel_id\" : //g" | sed -e "s/ }//g" | sed "\$d" | shuf | head -n 1;)
240
             PALTXT=''
240
             PALTXT=''
241
             PALP=''
241
             PALP=''
242
             curl $curl_options -d "field_input_title=$PAT&field_input_subtitle=$PAST&field_input_language=$LG&field_input_linked_directors=$PALD&field_input_description=$DESC&field_input_publisher_note=$PBN&field_input_publication=$issue&field_input_linked_parts=$PALP&field_input_linked_texts=$PALTXT&classname=Part" http://$host/$instance/admin/create?classname=Part
242
             curl $curl_options -d "field_input_title=$PAT&field_input_subtitle=$PAST&field_input_language=$LG&field_input_linked_directors=$PALD&field_input_description=$DESC&field_input_publisher_note=$PBN&field_input_publication=$issue&field_input_linked_parts=$PALP&field_input_linked_texts=$PALTXT&classname=Part" http://$host/$instance/admin/create?classname=Part
243
             part=$(printf "use $dbname\n db.Part.find({}, {lodel_id:1, _id:0}).sort({_id:-1}).limit(1)" | mongo  $HOSTDB/admin -u $dbuser -p $dbpwd | sed "1,3d" | sed -e "s/{ \"lodel_id\" : //g" | sed -e "s/ }//g" | sed "\$d" )
243
             part=$(printf "use $dbname\n db.Part.find({}, {lodel_id:1, _id:0}).sort({_id:-1}).limit(1)" | mongo  $HOSTDB/admin -u $dbuser -p $dbpwd | sed "1,3d" | sed -e "s/{ \"lodel_id\" : //g" | sed -e "s/ }//g" | sed "\$d" )
244
-       
244
+
245
             # On entre les textes correspondants aux  parts
245
             # On entre les textes correspondants aux  parts
246
             NBPANBT=$(shuf -e '2' '3' '4' | head -n 1)
246
             NBPANBT=$(shuf -e '2' '3' '4' | head -n 1)
247
             for i in `eval echo {1..$NBPANBT}`;
247
             for i in `eval echo {1..$NBPANBT}`;
357
                         fi
357
                         fi
358
                 done
358
                 done
359
                 PALD=$tmp
359
                 PALD=$tmp
360
-                PAT=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
361
-                PAST=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
360
+                PAT=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
361
+                PAST=$(lenmax=100;wcount=20; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
362
                 LG=$(shuf -e 'fr' 'en' 'es' 'ger' 'it'| head -n 1)
362
                 LG=$(shuf -e 'fr' 'en' 'es' 'ger' 'it'| head -n 1)
363
-                DESC=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
364
-                PBN=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/") 
363
+                DESC=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
364
+                PBN=$(lenmax=500;wcount=100; rlenmax=$(expr $lenmax - 1); echo $(shuf /usr/share/dict/words | head -n $wcount | tr -s "\n" " ") | sed -E "s/^(.{$rlenmax}).*$/\1/")
365
                 PALTXT=''
365
                 PALTXT=''
366
                 PALP=''
366
                 PALP=''
367
                 curl $curl_options -d "field_input_title=$PAT
367
                 curl $curl_options -d "field_input_title=$PAT
371
                 &field_input_description=$DESC&field_input_publisher_note=$PBN&field_input_publication=$part
371
                 &field_input_description=$DESC&field_input_publisher_note=$PBN&field_input_publication=$part
372
                 &field_input_linked_parts=$PALP&field_input_linked_texts=$PALTXT&classname=Part" http://$host/$instance/admin/create?classname=Part
372
                 &field_input_linked_parts=$PALP&field_input_linked_texts=$PALTXT&classname=Part" http://$host/$instance/admin/create?classname=Part
373
                 part=$(printf "use $dbname\n db.Part.find({}, {lodel_id:1, _id:0}).sort({_id:-1}).limit(1)" | mongo  $HOSTDB/admin -u $dbuser -p $dbpwd | sed "1,3d" | sed -e "s/{ \"lodel_id\" : //g" | sed -e "s/ }//g" | sed "\$d" )
373
                 part=$(printf "use $dbname\n db.Part.find({}, {lodel_id:1, _id:0}).sort({_id:-1}).limit(1)" | mongo  $HOSTDB/admin -u $dbuser -p $dbpwd | sed "1,3d" | sed -e "s/{ \"lodel_id\" : //g" | sed -e "s/ }//g" | sed "\$d" )
374
-       
374
+
375
                 # On entre les textes correspondants aux numéros indépendemment des parts
375
                 # On entre les textes correspondants aux numéros indépendemment des parts
376
                 for i in `eval echo {1..$NBA}`;
376
                 for i in `eval echo {1..$NBA}`;
377
                 do
377
                 do
471
             done
471
             done
472
         done
472
         done
473
     done
473
     done
474
-done
474
+done

Loading…
Cancel
Save