Browse Source

Deleting old stuff + bugfix in install/Makefile and in install/lodel_admin.py

Yann Weber 8 years ago
parent
commit
006b0c4bc0

+ 3
- 3
Doxyfile View File

@@ -51,7 +51,7 @@ PROJECT_BRIEF          = "Logiciel d'edition electronique v2"
51 51
 # and the maximum width should not exceed 200 pixels. Doxygen will copy the logo
52 52
 # to the output directory.
53 53
 
54
-PROJECT_LOGO           = "doc/img/openedition_logo.png"
54
+PROJECT_LOGO           = doc/img/openedition_logo.png
55 55
 
56 56
 # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
57 57
 # into which the generated documentation will be written. If a relative path is
@@ -763,7 +763,7 @@ WARN_LOGFILE           =
763 763
 # spaces.
764 764
 # Note: If this tag is empty the current directory is searched.
765 765
 
766
-INPUT                  =
766
+INPUT                  = .
767 767
 
768 768
 # This tag can be used to specify the character encoding of the source files
769 769
 # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
@@ -909,7 +909,7 @@ IMAGE_PATH             = doc/img
909 909
 # code is scanned, but not when the output code is generated. If lines are added
910 910
 # or removed, the anchors will not be placed correctly.
911 911
 
912
-INPUT_FILTER           = "doxypy"
912
+INPUT_FILTER           = doxypy
913 913
 
914 914
 # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
915 915
 # basis. Doxygen will compare the file name with each pattern and apply the

+ 0
- 7
__init__.py View File

@@ -1,7 +0,0 @@
1
-## @package install Contains the base files for a lodel2 instance
2
-#
3
-# An instance is composed of multiple things :
4
-#- a configuration directory ( @ref install/conf.d/ )
5
-#- a bootstraping script ( @ref install/loader.py )
6
-#- an utilities source code ( @ref install/lodel_admin.py )
7
-#- a Makefile that allow to run common instance operations (only refresh the dynamic code for now)

BIN
examples/em_test.pickle View File


+ 1
- 1
install/Makefile View File

@@ -6,4 +6,4 @@ dyncode:
6 6
 	$(python) -c 'import lodel_admin; lodel_admin.refresh_dyncode()'
7 7
 
8 8
 init_all_dbs:
9
-    $(python) -c 'import lodel_admin; lodel_admin.init_all_dbs()'
9
+	$(python) -c 'import lodel_admin; lodel_admin.init_all_dbs()'

+ 2
- 2
install/lodel_admin.py View File

@@ -6,7 +6,6 @@ import loader
6 6
 
7 7
 from lodel.settings import Settings
8 8
 from lodel import logger
9
-from .leapi_dyncode import *
10 9
 
11 10
 ## @brief Utility method to generate python code given an emfile and a
12 11
 # translator
@@ -48,5 +47,6 @@ def refresh_dyncode():
48 47
 
49 48
 
50 49
 def init_all_dbs():
50
+    import leapi_dyncode
51 51
     #TODO
52
-    pass
52
+    pass

+ 0
- 1
lodel/datasource/__init__.py View File

@@ -1 +0,0 @@
1
-__author__ = 'roland'

+ 0
- 1
lodel/datasource/generic/__init__.py View File

@@ -1 +0,0 @@
1
-# -*- coding: utf-8 -*-

+ 0
- 51
lodel/datasource/generic/datasource.py View File

@@ -1,51 +0,0 @@
1
-# -*- coding: utf-8 -*-
2
-
3
-class GenericDataSource(object):
4
-
5
-    def __init__(self, *conn_args, **conn_kwargs):
6
-        self.conn_args = conn_args
7
-        self.conn_kwargs = conn_kwargs
8
-
9
-    ## @brief returns a selection of documents from the datasource
10
-    # @param target_cls Emclass
11
-    # @param field_list list
12
-    # @param filters list : List of filters
13
-    # @param rel_filters list : List of relational filters
14
-    # @param order list : List of column to order. ex: order = [('title', 'ASC'),]
15
-    # @param group list : List of tupple representing the column to group together. ex: group = [('title', 'ASC'),]
16
-    # @param limit int : Number of records to be returned
17
-    # @param offset int: used with limit to choose the start record
18
-    # @param instanciate bool : If true, the records are returned as instances, else they are returned as dict
19
-    # @return list
20
-    def select(self, target_cls, field_list, filters, rel_filters=None, order=None, group=None, limit=None, offset=0,
21
-               instanciate=True):
22
-        pass
23
-
24
-    ## @brief Deletes one record defined by its uid
25
-    # @param target_cls Emclass : class of the record to delete
26
-    # @param uid dict|list : a dictionary of fields and values composing the unique identifier of the record or a list of several dictionaries
27
-    # @return int : number of deleted records
28
-    def delete(self, target_cls, uid):
29
-        pass
30
-
31
-    ## @brief updates one or a list of records
32
-    # @param target_cls Emclass : class of the object to insert
33
-    # @param uids list : list of uids to update
34
-    # @param datas dict : datas to update (new values)
35
-    # @return int : Number of updated records
36
-    def update(self, target_cls, uids, **datas):
37
-        pass
38
-
39
-    ## @brief Inserts a record in a given collection
40
-    # @param target_cls Emclass : class of the object to insert
41
-    # @param datas dict : datas to insert
42
-    # @return bool
43
-    def insert(self, target_cls, **datas):
44
-        pass
45
-
46
-    ## @brief Inserts a list of records in a given collection
47
-    # @param target_cls Emclass : class of the objects inserted
48
-    # @param datas_list
49
-    # @return list : list of the inserted records' ids
50
-    def insert_multi(self, target_cls, datas_list):
51
-        pass

+ 0
- 46
lodel/datasource/generic/migrationhandler.py View File

@@ -1,46 +0,0 @@
1
-# -*- coding: utf-8 -*-
2
-
3
-## @package lodel.datasource.migrationhandler.generic
4
-# @brief A generic migration handler
5
-#
6
-# According to it, every moditification is possible
7
-#
8
-
9
-
10
-## Manage model changes
11
-class GenericMigrationHandler(object):
12
-
13
-    def __init__(self, debug=False):
14
-        self.debug = debug
15
-
16
-    ## @brief Records a change in the EditorialModel and indicates whether or not it is possible to make it
17
-    # @note The states (initial_state and new_state) contains only fields that changes
18
-    def register_change(self, em, uid, initial_state, new_state):
19
-        if self.debug:
20
-            print("\n##############")
21
-            print("GenericMigrationHandler debug. Changes for component with uid %s :" % uid)
22
-            if initial_state is None:
23
-                print("Component creation (uid = %s): \n\t" % uid, new_state)
24
-            elif new_state is None:
25
-                print("Component deletion (uid = %s): \n\t" % uid, initial_state)
26
-            else:
27
-                field_list = set(initial_state.keys()).union(set(new_state.keys()))
28
-                for field_name in field_list:
29
-                    str_chg = "\t%s " % field_name
30
-                    if field_name in initial_state:
31
-                        str_chg += "'" + str(initial_state[field_name]) + "'"
32
-                    else:
33
-                        str_chg += " creating "
34
-                    str_chg += " => "
35
-                    if field_name in new_state:
36
-                        str_chg += "'" + str(new_state[field_name]) + "'"
37
-                    else:
38
-                        str_chg += " deletion "
39
-                    print(str_chg)
40
-
41
-            print("##############\n")
42
-
43
-    ## @brief Not usefull for the moment
44
-    def register_model_state(self, em, state_hash):
45
-        if self.debug:
46
-            print("New EditorialModel state registered : '%s'" % state_hash)

+ 0
- 0
lodel/datasource/mongodb/__init__.py View File


+ 0
- 135
lodel/datasource/mongodb/datasource.py View File

@@ -1,135 +0,0 @@
1
-# -*- coding: utf-8 -*-
2
-
3
-import bson
4
-from bson.son import SON
5
-from collections import OrderedDict
6
-import pymongo
7
-# from pymongo import MongoClient
8
-from pymongo.errors import BulkWriteError
9
-import urllib
10
-
11
-import lodel.datasource.mongodb.utils as utils
12
-
13
-from lodel.datasource.generic.datasource import GenericDataSource
14
-
15
-
16
-class MongoDbDataSourceError(Exception):
17
-    pass
18
-
19
-
20
-class MongoDbDataSource(GenericDataSource):
21
-
22
-    ## @brief Instanciates a Database object given a connection name
23
-    # @param connection_name str
24
-    def __init__(self, connection_name='default'):
25
-        self.database = utils.mongodbconnect(connection_name)
26
-
27
-    ## @brief returns a selection of documents from the datasource
28
-    # @param target_cls Emclass
29
-    # @param field_list list
30
-    # @param filters list : List of filters
31
-    # @param rel_filters list : List of relational filters
32
-    # @param order list : List of column to order. ex: order = [('title', 'ASC'),]
33
-    # @param group list : List of tupple representing the column used as "group by" fields. ex: group = [('title', 'ASC'),]
34
-    # @param limit int : Number of records to be returned
35
-    # @param offset int: used with limit to choose the start record
36
-    # @param instanciate bool : If true, the records are returned as instances, else they are returned as dict
37
-    # @return list
38
-    # @todo Implement the relations
39
-    def select(self, target_cls, field_list, filters, rel_filters=None, order=None, group=None, limit=None, offset=0,
40
-               instanciate=True):
41
-        collection_name = utils.object_collection_name(target_cls.__class__)
42
-        collection = self.database[collection_name]
43
-        query_filters = utils.parse_query_filters(filters)
44
-        query_result_ordering = utils.parse_query_order(order) if order is not None else None
45
-        results_field_list = None if len(field_list) == 0 else field_list
46
-        limit = limit if limit is not None else 0
47
-
48
-        if group is None:
49
-            cursor = collection.find(
50
-                filter=query_filters,
51
-                projection=results_field_list,
52
-                skip=offset,
53
-                limit=limit,
54
-                sort=query_result_ordering
55
-            )
56
-        else:
57
-            pipeline = list()
58
-            unwinding_list = list()
59
-            grouping_dict = OrderedDict()
60
-            sorting_list = list()
61
-            for group_param in group:
62
-                field_name = group_param[0]
63
-                field_sort_option = group_param[1]
64
-                sort_option = utils.MONGODB_SORT_OPERATORS_MAP[field_sort_option]
65
-                unwinding_list.append({'$unwind': '$%s' % field_name})
66
-                grouping_dict[field_name] = '$%s' % field_name
67
-                sorting_list.append((field_name, sort_option))
68
-
69
-            sorting_list.extends(query_result_ordering)
70
-
71
-            pipeline.append({'$match': query_filters})
72
-            if results_field_list is not None:
73
-                pipeline.append({'$project': SON([{field_name: 1} for field_name in field_list])})
74
-            pipeline.extend(unwinding_list)
75
-            pipeline.append({'$group': grouping_dict})
76
-            pipeline.extend({'$sort': SON(sorting_list)})
77
-            if offset > 0:
78
-                pipeline.append({'$skip': offset})
79
-            if limit is not None:
80
-                pipeline.append({'$limit': limit})
81
-
82
-        results = list()
83
-        for document in cursor:
84
-            results.append(document)
85
-
86
-        return results
87
-
88
-    ## @brief Deletes one record defined by its uid
89
-    # @param target_cls Emclass : class of the record to delete
90
-    # @param uid dict|list : a dictionary of fields and values composing the unique identifier of the record or a list of several dictionaries
91
-    # @return int : number of deleted records
92
-    # @TODO Implement the error management
93
-    def delete(self, target_cls, uid):
94
-        if isinstance(uid, dict):
95
-            uid = [uid]
96
-        collection_name = utils.object_collection_name(target_cls.__class__)
97
-        collection = self.database[collection_name]
98
-        result = collection.delete_many(uid)
99
-        return result.deleted_count
100
-
101
-    ## @brief updates one or a list of records
102
-    # @param target_cls Emclass : class of the object to insert
103
-    # @param uids list : list of uids to update
104
-    # @param datas dict : datas to update (new values)
105
-    # @return int : Number of updated records
106
-    # @todo check if the values need to be parsed
107
-    def update(self, target_cls, uids, **datas):
108
-        if not isinstance(uids, list):
109
-            uids = [uids]
110
-        collection_name = utils.object_collection_name(target_cls.__class__)
111
-        collection = self.database[collection_name]
112
-        results = collection.update_many({'uid': {'$in': uids}}, datas)
113
-        return results.modified_count()
114
-
115
-    ## @brief Inserts a record in a given collection
116
-    # @param target_cls Emclass : class of the object to insert
117
-    # @param datas dict : datas to insert
118
-    # @return bool
119
-    # @TODO Implement the error management
120
-    def insert(self, target_cls, **datas):
121
-        collection_name = utils.object_collection_name(target_cls.__class__)
122
-        collection = self.database[collection_name]
123
-        result = collection.insert_one(datas)
124
-        return len(result.inserted_id)
125
-
126
-    ## @brief Inserts a list of records in a given collection
127
-    # @param target_cls Emclass : class of the objects inserted
128
-    # @param datas_list
129
-    # @return list : list of the inserted records' ids
130
-    # @TODO Implement the error management
131
-    def insert_multi(self, target_cls, datas_list):
132
-        collection_name = utils.object_collection_name(target_cls.__class__)
133
-        collection = self.database[collection_name]
134
-        result = collection.insert_many(datas_list)
135
-        return len(result.inserted_ids)

+ 0
- 164
lodel/datasource/mongodb/migration_handler.py View File

@@ -1,164 +0,0 @@
1
-# -*- coding: utf-8 -*-
2
-
3
-import datetime
4
-
5
-from lodel.leapi.datahandlers.base_classes import DataHandler
6
-from lodel.datasource.generic.migrationhandler import GenericMigrationHandler
7
-import lodel.datasource.mongodb.utils as utils
8
-from lodel.editorial_model.components import EmClass, EmField
9
-from lodel.editorial_model.model import EditorialModel
10
-
11
-class MigrationHandlerChangeError(Exception):
12
-    pass
13
-
14
-class MongoDbMigrationHandler(GenericMigrationHandler):
15
-
16
-    COMMANDS_IFEXISTS_DROP = 'drop'
17
-    COMMANDS_IFEXISTS_NOTHING = 'nothing'
18
-
19
-    INIT_COLLECTIONS_NAMES = ['object', 'relation', 'entitie', 'person', 'text', 'entry']
20
-
21
-    ## @brief constructs a MongoDbMigrationHandler
22
-    # @param conn_args dict : a dictionary containing the connection options
23
-    # @param **kwargs : extra arguments
24
-    def __init__(self, conn_args=None, **kwargs):
25
-
26
-        if conn_args is None:
27
-            conn_args = utils.get_connection_args()
28
-
29
-        self.connection_name = conn_args['name']
30
-        self.database = utils.mongodbconnect(self.connection_name)
31
-
32
-        # TODO : get the following parameters in the settings ?
33
-        migrationhandler_settings = {'dry_run': False, 'foreign_keys': True, 'drop_if_exists': False}
34
-
35
-        self.dryrun = kwargs['dryrun'] if 'dryrun' in kwargs else migrationhandler_settings['dry_run']
36
-        self.foreign_keys = kwargs['foreign_keys'] if 'foreign_keys' in kwargs else migrationhandler_settings['foreign_keys']
37
-        self.drop_if_exists = kwargs['drop_if_exists'] if 'drop_if_exists' in kwargs else migrationhandler_settings['drop_if_exists']
38
-
39
-        self._install_collections()
40
-
41
-    def _install_collections(self):
42
-        for collection_name in MongoDbMigrationHandler.INIT_COLLECTIONS_NAMES:
43
-            collection_to_create = "%s%s" % ('class_', collection_name)
44
-            self._create_collection(collection_name=collection_to_create)
45
-
46
-    ## @brief Performs a change in the EditorialModel and indicates
47
-    # @note The states contains only the changing fields in the form of a dict : {field_name1: fieldvalue1, ...}
48
-    # @param model EditorialModel
49
-    # @param uid str : the uid of the changing component
50
-    # @param initial_state dict|None: dict representing the original state, None means the component will be created
51
-    # @param new_state dict|None: dict representing the new state, None means the component will be deleted
52
-    def register_change(self, model, uid, initial_state, new_state):
53
-        if initial_state is not None and new_state is not None:
54
-            if initial_state is None:
55
-                state_change = 'new'
56
-            elif new_state is None:
57
-                state_change = 'del'
58
-            else:
59
-                state_change = 'upgrade'
60
-
61
-            component_class_name = model.classes(uid).__class__.name
62
-            handler_func(component_class_name.lower() + '_' + state_change)
63
-            if hasattr(self, handler_func):
64
-                getattr(self, handler_func)(model, uid, initial_state, new_state)
65
-        else:
66
-            pass  # TODO manage the case where no state at all was given
67
-
68
-    def register_model_state(self, em, state_hash):
69
-        pass
70
-
71
-    ## @brief creates a new collection corresponding to a given uid
72
-    def emclass_new(self, model, uid, initial_state, new_state):
73
-        emclass = model.classes(uid)
74
-        if not isinstance(emclass, EmClass):
75
-            raise ValueError("The given uid is not an EmClass uid")
76
-        collection_name = utils.object_collection_name(emclass)
77
-        self._create_collection(collection_name)
78
-
79
-    ## @brief deletes a collection corresponding to a given uid
80
-    def emclass_del(self, model, uid, initial_state, new_state):
81
-        emclass = model.classes(uid)
82
-        if not isinstance(emclass, EmClass):
83
-            raise ValueError("The given uid is not an EmClass uid")
84
-        collection_name = utils.object.collection_name(emclass)
85
-        self._delete_collection(collection_name)
86
-
87
-    ## @brief creates a new field in a collection
88
-    # @param model EditorialModel
89
-    # @param uid str
90
-    # @param initial_state dict|None: dict representing the original state
91
-    # @param new_state dict|None: dict representing the new state
92
-    def emfield_new(self, model, uid, initial_state, new_state):
93
-        if new_state['data_handler'] == 'relation':
94
-            # find relational_type name, and class_name of the field
95
-            class_name = self._class_collection_name_from_field(model, new_state)
96
-            self._create_field_in_collection(class_name, uid, new_state)
97
-        else:
98
-            collection_name = self._class_collection_name_from_field(model, new_state)
99
-            field_definition = self._field_defition(new_state['data_handler'], new_state)
100
-            self._create_field_in_collection(collection_name, uid, field_definition)
101
-
102
-    ## @brief deletes a field in a collection
103
-    # @param model EditorialModel
104
-    # @param uid str
105
-    # @param initial_state dict|None: dict representing the original state
106
-    # @param new_state dict|None: dict representing the new state
107
-    def emfield_del(self, model, uid, initial_state, new_state):
108
-        collection_name = self._class_collection_name_from_field(model, initial_state)
109
-        field_name = model.field(uid).name
110
-        self._delete_field_in_collection(collection_name, field_name)
111
-
112
-    ## @brief Defines the default value when a new field is added to a collection's items
113
-    # @param fieldtype str : name of the field's type
114
-    # @param options dict : dictionary giving the options to use to initiate the field's value.
115
-    # @return dict (containing a 'default' key with the default value)
116
-    def _field_definition(self, fieldtype, options):
117
-        basic_type = DataHandler.from_name(fieldtype).ftype
118
-        if basic_type == 'datetime':
119
-            if 'now_on_create' in options and options['now_on_create']:
120
-                return {'default': datetime.datetime.utcnow()}
121
-        if basic_type == 'relation':
122
-            return {'default': []}
123
-
124
-        return {'default': ''}
125
-
126
-    def _class_collection_name_from_field(self, model, field):
127
-        class_id = field['class_id']
128
-        component_class = model.classes(class_id)
129
-        component_collection = utils.object_collection_name(component_class)
130
-        return component_collection
131
-
132
-    ## @brief Creates a new collection in MongoDb Database
133
-    # @param collection_name str
134
-    # @param charset str
135
-    # @param if_exists str : defines the behavior when the collection already exists (default : 'nothing')
136
-    def _create_collection(self, collection_name, charset='utf8', if_exists=MongoDbMigrationHandler.COMMANDS_IFEXISTS_NOTHING):
137
-        if collection_name in self.database.collection_names(include_system_collections=False):
138
-            # The collection already exists
139
-            if if_exists == MongoDbMigrationHandler.COMMANDS_IFEXISTS_DROP:
140
-                self._delete_collection(collection_name)
141
-                self.database.create_collection(name=collection_name)
142
-        else:
143
-            self.database.create_collection(name=collection_name)
144
-
145
-    ## @brief Delete an existing collection in MongoDb Database
146
-    # @param collection_name str
147
-    def _delete_collection(self, collection_name):
148
-        collection = self.database[collection_name]
149
-        collection.drop_indexes()
150
-        collection.drop()
151
-
152
-    ## @brief Creates a new field in a collection
153
-    # @param collection_name str
154
-    # @param field str
155
-    # @param options dict
156
-    def _create_field_in_collection(self, collection_name, field, options):
157
-        self.database[collection_name].update_many({field: {'$exists': False}}, {'$set': {field: options['default']}}, False)
158
-
159
-    ## @brief Deletes a field in a collection
160
-    # @param collection_name str
161
-    # @param field_name str
162
-    def _delete_field_in_collection(self, collection_name, field_name):
163
-        if field_name != '_id':
164
-            self.database[collection_name].update_many({field_name:{'$exists': True}}, {'$unset':{field_name:1}}, False)

+ 0
- 190
lodel/datasource/mongodb/utils.py View File

@@ -1,190 +0,0 @@
1
-# -*- coding: utf-8 -*-
2
-
3
-import pymongo
4
-from pymongo import MongoClient
5
-
6
-from lodel.settings.settings import Settings as settings
7
-
8
-common_collections = {
9
-    'object': 'object',
10
-    'relation': 'relation'
11
-}
12
-
13
-collection_prefix = {
14
-    'relation': 'rel_',
15
-    'object': 'class_'
16
-}
17
-
18
-LODEL_OPERATORS_MAP = {
19
-    '=': {'name': '$eq', 'value_type': None},
20
-    '<=': {'name': '$lte', 'value_type': None},
21
-    '>=': {'name': '$gte', 'value_type': None},
22
-    '!=': {'name': '$ne', 'value_type': None},
23
-    '<': {'name': '$lt', 'value_type': None},
24
-    '>': {'name': '$gt', 'value_type': None},
25
-    'in': {'name': '$in', 'value_type': list},
26
-    'not in': {'name': '$nin', 'value_type': list},
27
-    'OR': {'name': '$or', 'value_type': list},
28
-    'AND': {'name': '$and', 'value_type': list}
29
-}
30
-
31
-LODEL_SORT_OPERATORS_MAP = {
32
-    'ASC': pymongo.ASCENDING,
33
-    'DESC': pymongo.DESCENDING
34
-}
35
-
36
-MONGODB_SORT_OPERATORS_MAP = {
37
-    'ASC': 1,
38
-    'DESC': -1
39
-}
40
-
41
-
42
-MANDATORY_CONNECTION_ARGS = ('host', 'port', 'username', 'password', 'db_name')
43
-
44
-
45
-class MongoDbConnectionError(Exception):
46
-    pass
47
-
48
-
49
-## @brief Creates a connection to a MongoDb database
50
-def mongodbconnect(connection_name):
51
-    connection_args = get_connection_args(connection_name)
52
-    checked_connection_args = check_connection_args(connection_args)
53
-    if len(checked_connection_args['errors']) > 0:
54
-        raise MongoDbConnectionError("\r\n-".join(checked_connection_args['errors']))
55
-
56
-    # connection arguments are parsed after the check
57
-    login, password, host, port, dbname = checked_connection_args['params']
58
-
59
-    # Connection creation
60
-    connection_string = 'mongodb://%s:%s@%s:%s' % (login, password, host, port)
61
-    connection = MongoClient(connection_string)
62
-
63
-    # Setting the database
64
-    database = connection[dbname]
65
-
66
-    return database
67
-
68
-
69
-## @brief gets the settings given a connection name
70
-# @param connection_name str
71
-# @return dict
72
-# @todo Use the settings module to store the connections parameters
73
-def get_connection_args(connnection_name='default'):
74
-    return {'host': 'localhost', 'port': 28015, 'username': 'lodel_admin', 'password': 'lapwd', 'db_name': 'lodel'}
75
-
76
-
77
-## @brief Checks the settings given a connection name
78
-# @param connection_args dict
79
-# @return dict
80
-# @throw MongoDbDataSourceError with the list of all the found errors
81
-# @todo optimize the error management
82
-def check_connection_args(connection_args):
83
-    check_result = {'params': connection_args, 'errors': []}
84
-    for connection_arg in MANDATORY_CONNECTION_ARGS:
85
-        if connection_arg not in connection_args:
86
-            check_result['errors'].append('Datasource connection error: %s parameter is missing.' % connection_arg)
87
-    return check_result
88
-
89
-
90
-## @brief Returns a collection name given a Emclass
91
-# @param class_object EmClass
92
-# @return str
93
-def object_collection_name(class_object):
94
-    if class_object.pure_abstract == False:
95
-        class_parent = class_object.parents[0].uid
96
-        collection_name = ("%s%s" % (collection_prefix['object'], class_parent)).lower()
97
-    else:
98
-        collection_name = ("%s%s" % (collection_prefix['object'], class_object.name)).lower()
99
-
100
-    return collection_name
101
-
102
-
103
-## @brief converts the query filters into MongoDB filters
104
-# @param query_filters list : list of query_filters as tuples or dicts
105
-# @param as_list bool : defines if the output will be a list (default: False)
106
-# @return dict|list
107
-# @todo refactor this function by adding a return_type argument (default= dict) which can be a dict or a list, then delete the convert_filter_list function
108
-def parse_query_filters(query_filters, as_list=False):
109
-    parsed_filters = dict() if not as_list else list()
110
-    for query_filter in query_filters:
111
-        if isinstance(query_filter, tuple):
112
-            if as_list:
113
-                parsed_filters.append(convert_filter(query_filter))
114
-            else:
115
-                parsed_filters.update(convert_filter(query_filter))
116
-        elif isinstance(query_filter, dict):
117
-            query_item = list(query_filter.items())[0]
118
-            key = LODEL_OPERATORS_MAP[query_item[0]]
119
-            if as_list:
120
-                parsed_filters.append({key: parse_query_filters(query_item[1], as_list=True)})
121
-            else:
122
-                parsed_filters.update({key: parse_query_filters(query_item[1], as_list=True)})
123
-        else:
124
-            # TODO Add an exception management here in case the filter is neither a tuple nor a dict
125
-            pass
126
-    return parsed_filters
127
-
128
-
129
-## @brief converts a Lodel query filter into a MongoDB filter
130
-# @param filter_params tuple : (FIELD, OPERATOR, VALUE) representing the query filter to convert
131
-# @return dict : {KEY: {OPERATOR:VALUE}}
132
-# @todo Add an error management for the operator mismatch
133
-def convert_filter(filter_params):
134
-    key, operator, value = filter_params
135
-    if operator not in ('like', 'not like'):
136
-        if operator == 'in' and not isinstance(value, list):
137
-            raise ValueError('A list should be used as value for an IN operator, %s given' % value.__class__)
138
-
139
-        converted_operator = LODEL_OPERATORS_MAP[operator]['name']
140
-        converted_filter = {key: {converted_operator: value}}
141
-    else:
142
-        converted_filter = convert_like_filter(filter_params)
143
-    return converted_filter
144
-
145
-
146
-## @brief Returns a list of sorting options
147
-# @param query_filters_order list
148
-# @return list
149
-def parse_query_order(query_filters_order):
150
-    ordering = list()
151
-    for query_filter_order in query_filters_order:
152
-        field, direction = query_filter_order
153
-        ordering.append((field, LODEL_SORT_OPERATORS_MAP[direction]))
154
-    return ordering
155
-
156
-
157
-## @brief Converts "like" and "not like" filters into MongotDb filters
158
-# @param like_filter tuple
159
-# @return dict
160
-def convert_like_filter(like_filter):
161
-    key, operator, value = like_filter
162
-
163
-    is_starting_with = value.endswith('*')
164
-    is_ending_with = value.startswith('*')
165
-
166
-    if is_starting_with and not is_ending_with:
167
-        regex_pattern = value.replace('*', '^')
168
-    elif is_ending_with and not is_starting_with:
169
-        regex_pattern = value.replace('*', '$')
170
-    elif is_starting_with and is_ending_with:
171
-        regex_pattern = '%s' % value
172
-    else:
173
-        regex_pattern = '^%s$' % value
174
-
175
-    regex_condition = {'$regex': regex_pattern, '$options': 'i'}
176
-    converted_filter = {key: regex_condition}
177
-    if operator.startswith('not'):
178
-        converted_filter = {key: {'$not': regex_condition}}
179
-
180
-    return converted_filter
181
-
182
-
183
-## @brief identifier escaping
184
-# @param idname str: An identifier
185
-# @return str
186
-def escape_idname(idname):
187
-    if '`' in idname:
188
-        raise ValueError("Invalid name : '%s'" % idname)
189
-    return '`%s`' % idname
190
-

+ 2
- 2
lodel/editorial_model/translator/xmlfile.py View File

@@ -7,8 +7,8 @@ from lodel.editorial_model.model import EditorialModel
7 7
 from lodel.editorial_model.components import *
8 8
 from lodel.utils.mlstring import MlString
9 9
 
10
-## @package lodel.editorial_model.translator Lodel 2 Editorial Model Translators
11
-## @brief Packahg for saving a Editorial µModel in a xml fiel and loading an Editorial Model from a xml file
10
+##@package lodel.editorial_model.translator.xmlfile Translator module designed
11
+#to load & save EM in XML
12 12
 #
13 13
 # Structure of a xml file which represents an editorial model:
14 14
 # <ul>

Loading…
Cancel
Save