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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
import os
import re
import string
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]
def get_module_description(module_path):
"""Return software homepage URL and description"""
url = ""
description = " "
with open(module_path) as f:
content = f.read()
data = re.search(r"module-whatis\s{(Description: )?(.+)\s-\sHomepage:\s(\S+)}",
content, re.DOTALL)
try:
description = data.group(2)
url = data.group(3)
except AttributeError:
pass
return url, description
if __name__ == "__main__":
HTML_SOURCE_DATA = {}
subdirs = os.environ['MODULEPATH'].split(':')
print "# Available Modules"
for dir in sorted(subdirs):
available_software = software_list(dir)
print "\n## %s\n" % os.path.basename(dir).title()
print "| Module | Description |"
print "| ------ | ----------- |"
HTML_SOURCE_DATA[dir] = {}
for soft in sorted(available_software, key=str.lower):
software_path = os.path.join(dir, soft)
software_path1 = software_path
software_path = software_path.replace(os.path.basename(dir)+'/', 'all/')
software_versions = get_software_versions(software_path)
while ".common" in software_versions: software_versions.remove(".common")
while ".common-6" in software_versions: software_versions.remove(".common-6")
while ".version" in software_versions: software_versions.remove(".version")
if not software_versions:
continue
first_module_path = os.path.join(software_path, software_versions[0])
software_url, software_description = get_module_description(first_module_path)
HTML_SOURCE_DATA[dir][soft] = {'versions': [],
'url': software_url,
'description': software_description}
for version in software_versions:
HTML_SOURCE_DATA[dir][soft]['versions'].append(version)
if software_url=="":
print "| %s | %s |" % (soft," ".join(software_description.split()))
else:
print "| [%s](%s) | %s |" % (soft,software_url," ".join(software_description.split()))