Browse Source

Bugfixes and enhancement in slim.py

Now slim is able to create an instance, run make all, and start an interactive python without errors
refs #145
Yann Weber 8 years ago
parent
commit
ef2f8e3b30

+ 41
- 6
progs/slim.py View File

@@ -8,6 +8,8 @@ CREATION_SCRIPT='../scripts/create_instance.sh'
8 8
 INSTALL_TPL = './slim_ressources/slim_install_model'
9 9
 EMFILE = './slim_ressources/emfile.pickle'
10 10
 
11
+CONFFILE='conf.d/lodel2.ini'
12
+
11 13
 import os, os.path
12 14
 import sys
13 15
 import shutil
@@ -129,13 +131,34 @@ def save_datas(datas):
129 131
     with open(STORE_FILE, 'w+') as sfp:
130 132
         json.dump(datas, sfp)
131 133
 
134
+##@return conffile path
135
+def get_conffile(name):
136
+    validate_names([name])
137
+    store_datas = get_store_datas()
138
+    return os.path.join(store_datas[name]['path'], CONFFILE)
139
+
132 140
 ##@brief Print the list of instances and exit
133 141
 def list_instances(verbosity):
142
+    verbosity = 0 if verbosity is None else verbosity
134 143
     if not os.path.isfile(STORE_FILE):
135 144
         print("No store file, no instances are existing. Exiting...",
136 145
             file=sys.stderr)
137 146
         exit(0)
147
+    store_datas = get_store_datas()
138 148
     print('Instances list :')
149
+    for name in store_datas:
150
+        msg = "\t- '%s'" % name
151
+        if verbosity > 0:
152
+            msg += ' path = "%s"' % store_datas[name]['path']
153
+        if verbosity > 1:
154
+            ruler = (''.join(['=' for _ in range(20)])) + "\n"
155
+            msg += "\n\t\t====conf.d/lodel2.ini====\n"
156
+            with open(get_conffile(name)) as cfp:
157
+                for line in cfp:
158
+                    msg += "\t\t"+line
159
+            msg += "\t\t=========================\n"
160
+
161
+        print(msg)
139 162
     exit(0)
140 163
 
141 164
 ##@brief Returns instanciated parser
@@ -148,6 +171,13 @@ def get_parser():
148 171
         help='list existing instances and exit', action='store_const',
149 172
         const=True, default=False)
150 173
     parser.add_argument('-v', '--verbose', action='count')
174
+
175
+    selector.add_argument('-a', '--all', action='store_const',
176
+        default=False, const=True,
177
+        help='Select all instances')
178
+    selector.add_argument('-n', '--name', metavar='NAME', type=str, nargs='*',
179
+        help="Specify an instance name")
180
+
151 181
     actions.add_argument('-c', '--create', action='store_const',
152 182
         default=False, const=True,
153 183
         help="Create a new instance with given name (see -n --name)")
@@ -157,11 +187,9 @@ def get_parser():
157 187
     actions.add_argument('-e', '--edit-config', action='store_const',
158 188
         default=False, const=True,
159 189
         help='Edit configuration of specified instance')
160
-    selector.add_argument('-a', '--all', action='store_const',
190
+    actions.add_argument('-i', '--interactive', action='store_const',
161 191
         default=False, const=True,
162
-        help='Select all instances')
163
-    selector.add_argument('-n', '--name', metavar='NAME', type=str, nargs='*',
164
-        help="Specify an instance name")
192
+        help='Run a loader.py from ONE instance in foreground')
165 193
     actions.add_argument('--stop', action='store_const', 
166 194
         default=False, const=True, help="Stop instances")
167 195
     actions.add_argument('--start', action='store_const', 
@@ -213,7 +241,14 @@ specified")
213 241
         validate_names(names)
214 242
         name = names[0]
215 243
         store_datas = get_store_datas()
216
-        conffile = os.path.join(store_datas[name]['path'], 'conf.d')
217
-        conffile = os.path.join(conffile, 'lodel2.ini')
244
+        conffile = get_conffile(name)
218 245
         os.system('editor "%s"' % conffile)
219 246
         exit(0)
247
+    elif args.interactive:
248
+        if args.name is None or len(args.name) != 1:
249
+            print("\n-i option only allowed with ONE instance name")
250
+        validate_names(args.name)
251
+        name = args.name[0]
252
+        store_datas = get_store_datas()
253
+        os.chdir(store_datas[name]['path'])
254
+        os.execl('/usr/bin/env', '/usr/bin/env', 'python3', 'loader.py')

BIN
progs/slim_ressources/emfile.pickle View File


+ 12
- 16
progs/slim_ressources/slim_install_model/conf.d/lodel2.ini View File

@@ -1,3 +1,13 @@
1
+[lodel2]
2
+debug = False
3
+sitename = noname
4
+datasource_connectors = dummy_datasource
5
+
6
+[lodel2.editorialmodel]
7
+groups = base_group, editorial_abstract, editorial_person, users
8
+emfile = editorial_model.pickle
9
+dyncode = leapi_dyncode.py
10
+
1 11
 [lodel2.datasources.default]
2 12
 identifier = dummy_datasource.example
3 13
 
@@ -8,27 +18,13 @@ identifier = dummy_datasource.dummy2
8 18
 dummy =
9 19
 [lodel2.datasource.dummy_datasource.dummy2]
10 20
 dummy =
11
-[lodel2.section1]
12
-key1 = 42
13
-[lodel2]
14
-debug = False
15
-sitename = noname
16 21
 
17 22
 [lodel2.logging.stderr]
18 23
 level = DEBUG
19 24
 filename = -
20 25
 context = True
21 26
 
22
-[lodel2.editorialmodel]
23
-groups = base_group, editorial_abstract, editorial_person
24
-emfile = editorial_model.pickle
25
-dyncode = leapi_dyncode.py
26
-
27
-[lodel2.webui]
28
-standalone=False
27
+#[lodel2.webui]
28
+#standalone=False
29 29
 #listen_address=127.0.0.1
30 30
 #listen_port=9090
31
-[lodel2.webui.sessions]
32
-directory=./sessions
33
-expiration=900
34
-file_template=lodel2_%s.sess

+ 1
- 1
progs/slim_ressources/slim_install_model/loader.py View File

@@ -15,7 +15,7 @@ if LODEL2_LIB_ABS_PATH is not None:
15 15
     if not os.path.isdir(LODEL2_LIB_ABS_PATH):
16 16
         print("FATAL ERROR : the LODEL2_LIB_ABS_PATH variable in loader.py is \
17 17
 not correct : '%s'" % LODEL2_LIB_ABS_PATH, file=sys.stderr)
18
-    sys.path.append(os.path.dirname(LODEL2_LIB_ABS_PATH))
18
+    sys.path.append(LODEL2_LIB_ABS_PATH)
19 19
 
20 20
 try:
21 21
     import lodel

Loading…
Cancel
Save