Browse Source

Bugfixes in LodelSiteDatasource

Now we are able to insert a lodelsite
Yann Weber 7 years ago
parent
commit
d202a55773

+ 0
- 1
lodel/plugins/lodelsite_datasource/__init__.py View File

@@ -14,7 +14,6 @@ from lodel.context import LodelContext
14 14
 LodelContext.expose_modules(globals(), {
15 15
     'lodel.settings.validator': ['SettingValidator'],
16 16
     'lodel.logger': 'logger'})
17
-from .datasource import DummyDatasource as Datasource
18 17
 from .specs import check
19 18
 
20 19
 __plugin_type__ = 'datasource'

+ 1
- 1
lodel/plugins/lodelsite_datasource/exceptions.py View File

@@ -1,5 +1,5 @@
1 1
 class LodesSiteDatasourceError(Exception):
2 2
     pass
3 3
 
4
-class LodelSiteDatasourceInconsistency(LodelSiteDatasourceError):
4
+class LodelSiteDatasourceInconsistency(LodesSiteDatasourceError):
5 5
     pass

+ 15
- 15
lodel/plugins/lodelsite_datasource/fs_utils.py View File

@@ -7,7 +7,7 @@ import shutil
7 7
 from lodel.context import LodelContext
8 8
 from lodel import buildconf #No need to protect it in Contexts
9 9
 
10
-LodelContext.expose_module(globals(), {
10
+LodelContext.expose_modules(globals(), {
11 11
     'lodel.plugin.datasource_plugin': ['AbstractDatasource', 'DatasourcePlugin'],
12 12
     'lodel.exceptions': ['LodelFatalError'],
13 13
     'lodel.settings': 'Settings'})
@@ -16,7 +16,7 @@ from .exceptions import *
16 16
 
17 17
 LODELSITE_DATAS_PATH = os.path.join(buildconf.LODEL2VARDIR,'sites_datas')
18 18
 LODELSITE_CONTEXTS_PATH = os.path.join(
19
-    buildconf.LODEL2VARDIRE, '.sites_contexts')
19
+    buildconf.LODEL2VARDIR, '.sites_contexts')
20 20
 
21 21
 ##@brief Define directories architecture
22 22
 #
@@ -46,14 +46,14 @@ def name2paths(name):
46 46
 def site_exists(name):
47 47
     paths = name2paths(name)
48 48
     for path in paths:
49
-        if os.path.is_file(path):
49
+        if os.path.isfile(path):
50 50
             msg = 'Will trying to determine if a lodesite "%s" exists we \
51 51
 found that "%s" is a file, but a directory was expected' % (name, path)
52 52
             raise LodelSiteDatasourceInconsistency(msg)
53 53
 
54 54
     res = [False, False]
55
-    res = [os.is_dir(paths[0]),
56
-        os.is_dir(paths[1])]
55
+    res = [os.path.isdir(paths[0]),
56
+        os.path.isdir(paths[1])]
57 57
     if res[0] != res[1]:
58 58
         msg = 'Inconsistency detected on filesystem will trying to determine \
59 59
 wether a lodelsite exists or not : '
@@ -81,24 +81,24 @@ allready exists' % name)
81 81
     try:
82 82
         os.mkdir(data_path)
83 83
     except FileExistsError:
84
-        logger.fatal('This should never append ! We just checked that this \
84
+        logger.critical('This should never append ! We just checked that this \
85 85
 directory do not exists. BAILOUT !')
86 86
         raise LodelFatalError('Unable to create data directory for lodelsite \
87 87
 "%s", file exists')
88 88
     except Exception as e:
89
-        raise LodelFataError(('Unable to create data directory for lodelsite \
90
-"%s" : ' % name) + e)
89
+        raise LodelFatalError('Unable to create data directory for lodelsite \
90
+"%s" : %s' % (name,e))
91 91
     #Context dir
92 92
     try:
93 93
         os.mkdir(ctx_path)
94
-    except FileExistsErrpr:
95
-        logger.fatal('This should never append ! We just checked that this \
94
+    except FileExistsError:
95
+        logger.critical('This should never append ! We just checked that this \
96 96
 directory do not exists. BAILOUT !')
97 97
         raise LodelFatalError('Unable to create context directory for \
98 98
 lodelsite "%s", file exists')
99 99
     except Exception as e:
100
-        raise LodelFataError(('Unable to create context directory for \
101
-lodelsite "%s" : ' % name) + e)
100
+        raise LodelFatalError('Unable to create context directory for \
101
+lodelsite "%s" : %s' % (name, e))
102 102
     
103 103
     #Child directories
104 104
     for mname, ccd in (('datas', data_path), ('ctx', ctx_path)):
@@ -108,11 +108,11 @@ lodelsite "%s" : ' % name) + e)
108 108
             try:
109 109
                 os.mkdir(to_create)
110 110
             except FileExistsError:
111
-                logger.fatal('This should never append ! We just created parent \
111
+                logger.critical('This should never append ! We just created parent \
112 112
 directory. BAILOUT !')
113 113
             except Exception as e:
114
-                raise LodelFatalError(('Unable to create %s directory for \
115
-lodelsite "%s" : ' % (d,name)) + e)
114
+                raise LodelFatalError('Unable to create %s directory for \
115
+lodelsite "%s" : %s' % (d,name, e))
116 116
     
117 117
 ##@brief Generate conffile containing informations set by lodelsites EM
118 118
 #

+ 9
- 9
lodel/plugins/lodelsite_datasource/main.py View File

@@ -1,7 +1,7 @@
1 1
 import os.path
2 2
 from lodel.context import LodelContext
3 3
 
4
-LodelContext.expose_module(globals(), {
4
+LodelContext.expose_modules(globals(), {
5 5
     'lodel.plugin.datasource_plugin': ['AbstractDatasource', 'DatasourcePlugin'],
6 6
     'lodel.logger': 'logger',
7 7
     'lodel.exceptions': ['LodelFatalError'],
@@ -24,7 +24,7 @@ class Datasource(AbstractDatasource):
24 24
     #@param db_datasource_ro str : read only datasource identitifer
25 25
     def __init__(self, db_datasource, db_datasource_ro = None):
26 26
         if db_datasource_ro is None:
27
-            db_datasource = db_datasource_ro
27
+            db_datasource_ro = db_datasource
28 28
         self._child_ds = DatasourcePlugin.init_datasource(
29 29
             db_datasource, False)
30 30
         self._child_ds_ro = DatasourcePlugin.init_datasource(
@@ -41,7 +41,7 @@ class Datasource(AbstractDatasource):
41 41
         res, reason = check_leo(leo)
42 42
         if not res:
43 43
             msg = 'Bad leo given : %s because %s' % (leo, reason)
44
-            logger.fatal(msg)
44
+            logger.critical(msg)
45 45
             raise LodelFatalError(msg)
46 46
 
47 47
     ##@brief Provide a new uniq numeric ID
@@ -104,15 +104,15 @@ existing site with a new name')
104 104
         
105 105
         datas = self.select(
106 106
             target,
107
-            ['shortname', 'groups', 'extensions'],
107
+            ['shortname', 'em_groups', 'extensions'],
108 108
             filters,
109 109
             relational_filters)
110 110
 
111 111
         for data in datas:
112
-            if 'groups' in upd_datas:
113
-                groups = upd_datas['groups']
112
+            if 'em_groups' in upd_datas:
113
+                groups = upd_datas['em_groups']
114 114
             else:
115
-                groups = data['groups']
115
+                groups = data['em_groups']
116 116
             if 'extensions' in upd_datas:
117 117
                 extensions = upd_datas['extensions']
118 118
             else:
@@ -120,7 +120,7 @@ existing site with a new name')
120 120
 
121 121
             update_conf(**{
122 122
                 'sitename': data['shortname'],
123
-                'groups': groups,
123
+                'em_groups': groups,
124 124
                 'extensions': extensions})
125 125
         
126 126
         return self._child_ds.update(
@@ -138,7 +138,7 @@ allready exists' % (new_datas['shortname']))
138 138
         site_directories_creation(new_datas['shortname'])
139 139
         generate_conf(
140 140
             new_datas['shortname'],
141
-            new_datas['groups'],
141
+            new_datas['em_groups'],
142 142
             new_datas['extensions'])
143 143
         return self._child_ds.insert(target, new_datas)
144 144
 

+ 3
- 3
lodel/plugins/lodelsite_datasource/specs.py View File

@@ -4,7 +4,7 @@
4 4
 #@note isolated in order to be usable by __init__.py and main.py
5 5
 
6 6
 LEO_NAME = 'Lodelsite'
7
-MANDATORY_FIELDNAMES = [ 'shortname', 'extensions', 'groups' ]
7
+MANDATORY_FIELDNAMES = [ 'shortname', 'extensions', 'em_groups' ]
8 8
 
9 9
 ##@brief Checks that given emcomponent is compatible with datasource
10 10
 #behavior
@@ -12,11 +12,11 @@ MANDATORY_FIELDNAMES = [ 'shortname', 'extensions', 'groups' ]
12 12
 #@param emcomp LeObject subclass (or instance)
13 13
 #@return a tuple (bool, reason_str)
14 14
 def check(leo):
15
-    if hasattr(leo, '__class__'):
15
+    if not hasattr(leo, '__name__'):
16 16
         leo = leo.__class__
17 17
     if leo.__name__ != LEO_NAME:
18 18
         return (False, 'bad name')
19
-    missings = MANDATORY_FIELDNAMES - set(leo.fieldnames())
19
+    missings = set(MANDATORY_FIELDNAMES) - set(leo.fieldnames())
20 20
     if len(missings) > 0:
21 21
         return (False, 'missing fields : ' + (', '.join(missings)))
22 22
     return (True, 'ok')

Loading…
Cancel
Save