Skip to content

Commit c6f97e9

Browse files
authored
Merge pull request #40 from CESNET/devel
* Finalize logic config.json files for modules and bootstrapping * Change default DB provider to SQLite3
2 parents c6b8f9b + 9cfa02b commit c6f97e9

4 files changed

Lines changed: 69 additions & 42 deletions

File tree

backend/config-sample.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ssl = false
4848
; mysql: server, port and database must be specified, user and password
4949
; are for authentication to the db
5050
; mongodb: server, port and database must be set
51-
provider = mongodb
51+
provider = sqlite
5252
users = users
5353
configuration = configuration
5454

bootstrap.py

Lines changed: 66 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import re
66
import logging
7+
import fnmatch
78
import glob
89

910
logging.basicConfig()
@@ -48,6 +49,19 @@ def dicts(dst, add):
4849
dst[key] = add[key]
4950
return conflicts
5051

52+
def recursive_glob(rootdir='.', pattern='*'):
53+
"""Search recursively for files matching a specified pattern.
54+
Adapted from http://stackoverflow.com/questions/2186525/use-a-glob-to-find-files-recursively-in-python
55+
"""
56+
57+
matches = []
58+
for root, dirnames, filenames in os.walk(rootdir):
59+
for filename in fnmatch.filter(filenames, pattern):
60+
matches.append(os.path.join(root, filename))
61+
62+
return matches
63+
64+
5165
def mergeNpmDeps(base, module, modulename):
5266
"""
5367
Adds dependencies from module into base and reports any conflicts that happen.
@@ -169,63 +183,76 @@ def updateModuleList(moduleList, config, modulename):
169183
return True
170184

171185
def createSymlink(src, dst):
186+
log.debug("Symlinking src: %s, dst: %s" % (src, dst))
172187
try:
173188
# Using lexists to detect and remove broken symlinks as well as removing symlinks that
174189
# will be overwritten.
175190
if os.path.lexists(dst):
176191
os.remove(dst)
177192
os.symlink(src, dst)
178193
except (OSError, IOError) as e: # Insufficient privileges
179-
log.warn(str(e))
194+
log.warn("Cannot create symlink (target: %s) %s" % (src, str(e)))
180195

181196
def bootstrapModules(basedeps, moduleList):
182197
"""
183198
Build moduleList, update basedeps with module specific dependencies and create symlinks into
184199
module folders of both backend and frontend.
185200
"""
186201
#modules = getImmediateSubdirs('modules')
187-
cfgfiles = glob.glob(os.path.join(BASE_PATH, 'modules', '*.config.json'))
188-
for cfgpath in cfgfiles:
189-
#cfgpath = os.path.join(BASE_PATH, 'modules', module, 'config.json')
190-
191-
config = None
202+
cfgfiles = glob.glob(os.path.join(BASE_PATH, 'modules', '*/*config.json'))
192203

204+
for cfgpath in cfgfiles:
193205
try:
194-
with open(cfgpath, 'r') as fh:
195-
config = json.load(fh)
196-
except (OSError, IOError):
197-
log.warn(module + ': Cannot find ' + cfgpath + ', skipping module')
198-
continue
206+
config = None
207+
208+
try:
209+
with open(cfgpath, 'r') as fh:
210+
config = json.load(fh)
211+
except (OSError, IOError):
212+
log.warn(module + ': Cannot find ' + cfgpath + ', skipping module')
213+
continue
214+
215+
try:
216+
name = config['module']['name']
217+
except KeyError as e:
218+
log.warn("Cannot find name in module, skipping config %s" % cfgpath)
219+
220+
if not updateModuleList(moduleList, config, name):
221+
continue
222+
223+
module_dir = os.path.dirname(cfgpath)
224+
225+
# Module might not have dependencies, their absence is not an error
226+
if 'dependencies' in config:
227+
updateDeps(basedeps, config['dependencies'], name)
228+
229+
if 'backend' in config['module']:
230+
src = os.path.join(module_dir, config['module']['backend'])
231+
dst = os.path.join(BASE_PATH, 'backend/liberouterapi/modules', name)
232+
createSymlink(src, dst)
233+
234+
if 'assets' in config['module']:
235+
"""
236+
Link assets for frontend to frontend/src/assets folder
237+
Each module must contain key 'name' and 'assets', after importing assets are available
238+
via /name/ path on frontend
239+
"""
240+
if not 'name' in config['module']:
241+
log.warn("No 'name' specified, skipping inclusion of assets.")
242+
break
243+
src = os.path.join(module_dir, config['module']['assets'])
244+
dst = os.path.join(BASE_PATH, 'frontend/src/assets', name)
245+
createSymlink(src, dst)
246+
247+
# Frontend key presence tested by updateModuleList
248+
src = os.path.join(module_dir, config['module']['frontend'])
249+
dst = os.path.join(BASE_PATH, 'frontend/src/app/modules', name)
199250

200-
if not updateModuleList(moduleList, config, config['name']):
201-
continue
202-
203-
# Module might not have dependencies, their absence is not an error
204-
if 'dependencies' in config:
205-
updateDeps(basedeps, config['dependencies'], config['name'])
206-
207-
if 'backend' in config['module']:
208-
src = os.path.join(BASE_PATH, 'modules', config['module']['backend'])
209-
dst = os.path.join(BASE_PATH, 'backend/liberouterapi/modules', config['name'])
210251
createSymlink(src, dst)
211-
212-
if 'assets' in config['module']:
213-
"""
214-
Link assets for frontend to frontend/src/assets folder
215-
Each module must contain key 'name' and 'assets', after importing assets are available
216-
via /name/ path on frontend
217-
"""
218-
if not 'name' in config['module']:
219-
log.warn("No 'name' specified, skipping inclusion of assets.")
220-
break
221-
src = os.path.join(BASE_PATH, 'modules', config['name'], config['module']['assets'])
222-
dst = os.path.join(BASE_PATH, 'frontend/src/assets', config['module']['name'])
223-
createSymlink(src, dst)
224-
225-
# Frontend key presence tested by updateModuleList
226-
src = os.path.join(BASE_PATH, 'modules', config['name'], config['module']['frontend'])
227-
dst = os.path.join(BASE_PATH, 'frontend/src/app/modules', config['name'])
228-
createSymlink(src, dst)
252+
except Exception as e:
253+
log.warn("Skipping configuration in {0}. Reason: {1} ({2})"
254+
.format(cfgpath, str(e), type(e)))
255+
continue
229256

230257
def registerModules(modules):
231258
"""

modules/example/backend/config.json

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"name" : "example",
32
"dependencies": {
43
"npm": "frontend/package.json",
54
"ngc": "frontend/.angular-cli.json",
@@ -9,6 +8,7 @@
98
"class": "ExampleModule",
109
"file": "frontend/example.module.ts",
1110
"frontend": "frontend/",
12-
"backend": "backend/"
11+
"backend": "backend/",
12+
"name" : "example"
1313
}
1414
}

0 commit comments

Comments
 (0)