Browse Source

Modifies lodel site install paths

Quentin Bonaventure 8 years ago
parent
commit
c6ec0aba2a

+ 1
- 0
lodel/buildconf.py.am.in View File

@@ -11,3 +11,4 @@ import os
11 11
 
12 12
 MULTISITE_DATADIR = os.path.join(LODEL2VARDIR, 'sites_datas')
13 13
 MULTISITE_CONTEXTDIR = os.path.join(LODEL2VARDIR, '.sites_context')
14
+LODEL_PKG_PATH = '/usr/lib/python3/dist-package/lodel'

+ 48
- 22
lodel/plugins/lodelsite_datasource/fs_utils.py View File

@@ -1,6 +1,7 @@
1 1
 ##@brief This module contains usefull functions to handle lodelsites on FS
2 2
 
3 3
 import os
4
+import os.symlink
4 5
 import os.path
5 6
 import shutil
6 7
 
@@ -15,17 +16,15 @@ LodelContext.expose_modules(globals(), {
15 16
 
16 17
 from .exceptions import *
17 18
 
18
-LODELSITE_DATAS_PATH = os.path.join(
19
-    buildconf.MULTISITE_DATADIR, Settings.sitename)
20
-LODELSITE_CONTEXTS_PATH = os.path.join(
21
-    buildconf.MULTISITE_CONTEXTDIR, Settings.sitename)
19
+LODELSITE_DATA_PATH, LODELSITE_CONTEXTS_PATH = LodelContext.lodelsites_paths()
20
+
22 21
 
23 22
 ##@brief Define directories architecture
24 23
 #
25 24
 #@note useless because a lot of those stuff would be hardcoded
26 25
 LODELSITE_INSTALL_MODEL = {
27 26
     'datas' : ['uploads', 'conf.d'], #For datadir
28
-    'ctx': ['lodel_pkg'] #for context dir
27
+    'ctx': ['leapi_dyncode'] #for context dir
29 28
 }
30 29
 
31 30
 CONF_MODELS = os.path.join(os.path.dirname(__file__),'model_conf.d/')
@@ -34,10 +33,9 @@ CONF_AUTOCONF_FILENAME = 'lodelsites_autoconfig.ini'
34 33
 ##@brief Util function that returns both datadir and contextdir paths
35 34
 #@param name str : the site shortname
36 35
 #@return a tuple (datadir, contextdir)
37
-def name2paths(name):
38
-    return (os.path.join(LODELSITE_DATAS_PATH, name),
39
-        os.path.join(LODELSITE_CONTEXTS_PATH, name))
40
-
36
+def name2path(name):
37
+    return (os.path.join(LODELSITE_DATA_PATH, name),
38
+            os.path.join(LODELSITE_CONTEXTS_PATH, name))
41 39
 ##@brief Util function that indicates if a site exists or not
42 40
 #
43 41
 #This function only checks that both paths returned by name2path are
@@ -49,7 +47,7 @@ def site_exists(name):
49 47
     paths = name2paths(name)
50 48
     
51 49
     if name == Settings.sitename:
52
-        msg = 'Site shortname "%s" is conflicting with the Lodelsites isntance name' % name
50
+        msg = 'Site shortname "%s" is conflicting with the Lodelsites instance name' % name
53 51
         raise LodelSiteDatasourceError(msg)
54 52
     
55 53
     for path in paths:
@@ -102,25 +100,53 @@ directory does not exist. BAILOUT !')
102 100
         logger.critical('This should never happen ! We just checked that this \
103 101
 directory does not exist. BAILOUT !')
104 102
         raise LodelFatalError('Unable to create context directory for \
105
-lodelsite "%s", file exists')
103
+lodelsite "%s", file exists' % name)
106 104
     except Exception as e:
107 105
         raise LodelFatalError('Unable to create context directory for \
108 106
 lodelsite "%s" : %s' % (name, e))
109 107
     
110
-    #Child directories
111
-    for mname, ccd in [('datas', data_path), ('ctx', ctx_path)]:
112
-        ccd = data_path
113
-        for d in LODELSITE_INSTALL_MODEL[mname]:
114
-            to_create = os.path.join(ccd, d)
115
-            try:
116
-                os.mkdir(to_create)
117
-            except FileExistsError:
118
-                logger.critical('This should never happen ! We just checked that this \
108
+    #Creates lodel site data subdirectories
109
+    for data_subdirectory in LODELSITE_INSTALL_MODEL['datas']:
110
+        to_create = os.path.join(data_path, data_subdirectory)
111
+        try:
112
+            os.mkdir(to_create)
113
+        except FileExistsError:
114
+            logger.critical('This should never happen ! We just checked that this \
119 115
 directory does not exist. BAILOUT !')
120
-            except Exception as e:
121
-                raise LodelFatalError('Unable to create %s directory for \
116
+        except Exception as e:
117
+            raise LodelFatalError('Unable to create %s directory for \
122 118
 lodelsite "%s" : %s' % (d,name, e))
123 119
     
120
+    
121
+def site_lodelpkg_link_creation(name):
122
+    dst_path = os.path.join(name2path(name)[1], lodel)
123
+    src_path = LODEL_PKG_PATH
124
+    
125
+    try:
126
+        os.symlink(src_path, dst_path)
127
+    except FileExistsError:
128
+        logger.critical('This should never happen ! We just checked that this \
129
+directory does not exist. BAILOUT !')
130
+        raise LodelFatalError('Unable to create lodel package symlink for \
131
+lodelsite "%s", link exists in dir %s' % (name, directory))
132
+    except Exception as e:
133
+        raise LodelFatalError('Unable to create lodel package symlink for \
134
+lodelsite "%s" : %s' % (name, e))
135
+    
136
+def site_context_init_creation(name):
137
+    directory = name2path(name)[1]
138
+    try:
139
+        open('x', os.path.join(directory, '__init__.py')).close()
140
+    except FileExistsError:
141
+        logger.critical('This should never happen ! We just checked that this \
142
+directory does not exist. BAILOUT !')
143
+        raise LodelFatalError('Unable to create python __init__ file for \
144
+lodelsite context "%s", file exists in dir %s' % (name, directory))
145
+    except Exception as e:
146
+        raise LodelFatalError('Unable to create python _init__ file for \
147
+lodelsite "%s" : %s' % (name, e))
148
+    
149
+    
124 150
 ##@brief Generate conffile containing informations set by lodelsites EM
125 151
 #
126 152
 #@param sitename str : site shortname

+ 2
- 0
lodel/plugins/lodelsite_datasource/main.py View File

@@ -136,6 +136,8 @@ existing site with a new name')
136 136
             raise LodelSiteDatasourceError('A site with "%s" as shortname \
137 137
 already exists' % (new_datas['shortname']))
138 138
         site_directories_creation(new_datas['shortname'])
139
+        site_lodelpkg_link_creation(new_datas['shortname'])
140
+        site_context_init_creation(new_datas['shortname'])
139 141
         generate_conf(
140 142
             new_datas['shortname'],
141 143
             new_datas['em_groups'],

Loading…
Cancel
Save