Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
#
# Copyright (C) 2016 IT4Innovations
#
import os
def software_list(class_path):
"""List software from given module class"""
os.chdir(class_path)
software_list = next(os.walk('.'))[1]
# In case that there is 'all' module
if 'all' in software_list:
software_list.remove('all')
return software_list
def get_software_versions(software_path):
"""List available versions of software"""
os.chdir(software_path)
return next(os.walk('.'))[2]
if __name__ == "__main__":
BASE_MODULES_DIR = '/apps/modules/'
SKIP_DIRS = ['all']
HTML_SOURCE_DATA = {}
os.chdir(BASE_MODULES_DIR)
subdirs = next(os.walk('.'))[1]
# Delete unwanted directories
for dir in SKIP_DIRS:
subdirs.remove(dir)
# Create module class structure
for dir in sorted(subdirs):
class_path = os.path.join(BASE_MODULES_DIR, dir)
available_software = software_list(class_path)
HTML_SOURCE_DATA[dir] = {}
for soft in sorted(available_software, key=str.lower):
software_path = os.path.join(class_path, soft)
software_versions = get_software_versions(software_path)
# In case that there's not any available software version
if not software_versions:
continue
first_module_path = os.path.join(software_path, software_versions[0])
HTML_SOURCE_DATA[dir][soft] = {'versions': []}
for version in software_versions:
HTML_SOURCE_DATA[dir][soft]['versions'].append(version)
print "%s|%s" % (soft.lower(),';'.join(software_versions))