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
 INSTALL_TPL = './slim_ressources/slim_install_model'
8
 INSTALL_TPL = './slim_ressources/slim_install_model'
9
 EMFILE = './slim_ressources/emfile.pickle'
9
 EMFILE = './slim_ressources/emfile.pickle'
10
 
10
 
11
+CONFFILE='conf.d/lodel2.ini'
12
+
11
 import os, os.path
13
 import os, os.path
12
 import sys
14
 import sys
13
 import shutil
15
 import shutil
129
     with open(STORE_FILE, 'w+') as sfp:
131
     with open(STORE_FILE, 'w+') as sfp:
130
         json.dump(datas, sfp)
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
 ##@brief Print the list of instances and exit
140
 ##@brief Print the list of instances and exit
133
 def list_instances(verbosity):
141
 def list_instances(verbosity):
142
+    verbosity = 0 if verbosity is None else verbosity
134
     if not os.path.isfile(STORE_FILE):
143
     if not os.path.isfile(STORE_FILE):
135
         print("No store file, no instances are existing. Exiting...",
144
         print("No store file, no instances are existing. Exiting...",
136
             file=sys.stderr)
145
             file=sys.stderr)
137
         exit(0)
146
         exit(0)
147
+    store_datas = get_store_datas()
138
     print('Instances list :')
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
     exit(0)
162
     exit(0)
140
 
163
 
141
 ##@brief Returns instanciated parser
164
 ##@brief Returns instanciated parser
148
         help='list existing instances and exit', action='store_const',
171
         help='list existing instances and exit', action='store_const',
149
         const=True, default=False)
172
         const=True, default=False)
150
     parser.add_argument('-v', '--verbose', action='count')
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
     actions.add_argument('-c', '--create', action='store_const',
181
     actions.add_argument('-c', '--create', action='store_const',
152
         default=False, const=True,
182
         default=False, const=True,
153
         help="Create a new instance with given name (see -n --name)")
183
         help="Create a new instance with given name (see -n --name)")
157
     actions.add_argument('-e', '--edit-config', action='store_const',
187
     actions.add_argument('-e', '--edit-config', action='store_const',
158
         default=False, const=True,
188
         default=False, const=True,
159
         help='Edit configuration of specified instance')
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
         default=False, const=True,
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
     actions.add_argument('--stop', action='store_const', 
193
     actions.add_argument('--stop', action='store_const', 
166
         default=False, const=True, help="Stop instances")
194
         default=False, const=True, help="Stop instances")
167
     actions.add_argument('--start', action='store_const', 
195
     actions.add_argument('--start', action='store_const', 
213
         validate_names(names)
241
         validate_names(names)
214
         name = names[0]
242
         name = names[0]
215
         store_datas = get_store_datas()
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
         os.system('editor "%s"' % conffile)
245
         os.system('editor "%s"' % conffile)
219
         exit(0)
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
+[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
 [lodel2.datasources.default]
11
 [lodel2.datasources.default]
2
 identifier = dummy_datasource.example
12
 identifier = dummy_datasource.example
3
 
13
 
8
 dummy =
18
 dummy =
9
 [lodel2.datasource.dummy_datasource.dummy2]
19
 [lodel2.datasource.dummy_datasource.dummy2]
10
 dummy =
20
 dummy =
11
-[lodel2.section1]
12
-key1 = 42
13
-[lodel2]
14
-debug = False
15
-sitename = noname
16
 
21
 
17
 [lodel2.logging.stderr]
22
 [lodel2.logging.stderr]
18
 level = DEBUG
23
 level = DEBUG
19
 filename = -
24
 filename = -
20
 context = True
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
 #listen_address=127.0.0.1
29
 #listen_address=127.0.0.1
30
 #listen_port=9090
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
     if not os.path.isdir(LODEL2_LIB_ABS_PATH):
15
     if not os.path.isdir(LODEL2_LIB_ABS_PATH):
16
         print("FATAL ERROR : the LODEL2_LIB_ABS_PATH variable in loader.py is \
16
         print("FATAL ERROR : the LODEL2_LIB_ABS_PATH variable in loader.py is \
17
 not correct : '%s'" % LODEL2_LIB_ABS_PATH, file=sys.stderr)
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
 try:
20
 try:
21
     import lodel
21
     import lodel

Loading…
Cancel
Save