diff --git a/get_modules.sh b/get_modules.sh index 993008486ede3ad3dbb835d9c1949c175ca0328a..3f13caf27b577186df4f6809329fab4ded5c4f90 100755 --- a/get_modules.sh +++ b/get_modules.sh @@ -1,4 +1,4 @@ -# !/bin/bash +#!/bin/bash PWD="/home/easybuild/git/it4i-modules" cd $PWD @@ -66,6 +66,6 @@ else ./modules.py > phi.md fi -DATE=`date -R` +DATE=$(date -R) git diff --exit-code || git commit -am "$DATE" git push origin master diff --git a/modules.py b/modules.py index 9b6d48c9c8b6da9722926680f43e131e80eae770..cfe785b413d667f6fc1fc189a03026156e42a024 100755 --- a/modules.py +++ b/modules.py @@ -2,86 +2,76 @@ import os import re -import socket -def software_list(class_path): +def get_software_list(path): """List software from given module class""" - os.chdir(class_path) + os.chdir(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): +def get_software_versions(path): """List available versions of software""" - os.chdir(software_path) + os.chdir(path) return next(os.walk('.'))[2] def get_module_description(module_path): """Return software homepage URL and description""" url = "" - url_position = 0 description = "Old module, description not available." - with open(module_path) as f: - content = f.read() + with open(module_path) as _file: + content = _file.read() if module_path.endswith('lua'): - data = re.search(r"whatis\((\[\[|\[==\[)Description: ?([\s\S]+)(\]\]|\]==\])\)\s+whatis\((\[\[|\[==\[)Homepage:\s(\S+)(\]\]|\]==\])\)", - content, re.DOTALL) - url_position = 5 + data = re.search(r"whatis\((\[\[|\[==\[)Description: ?([\s\S]+)(?>\]\]|\]==\])\)\s+whatis\((?>\[\[|\[==\[)Homepage:\s(\S+)(?>\]\]|\]==\])\)", + content, re.DOTALL) else: data = re.search(r"module-whatis\s{(Description: )?(.+)\s-\sHomepage:\s(\S+)}", - content, re.DOTALL) - url_position = 3 + content, re.DOTALL) try: description = data.group(2) - url = data.group(url_position) + url = data.group(3) except AttributeError: pass return url, description if __name__ == "__main__": HTML_SOURCE_DATA = {} - subdirs = os.environ['MODULEPATH'].split(':') + SUBDIRS = os.environ['MODULEPATH'].split(':') - if os.getenv('CLUSTER')=="ANSELM": - subdirs.remove("/apps/modules/init") - subdirs.remove("/apps/modules/environments") - subdirs.remove("/apps/modules/engineering") - subdirs.remove("/apps/modules/libraries") - subdirs.remove("/apps/modules/omics") - subdirs.remove("/apps/modules/prace") + if os.getenv('CLUSTER') == "ANSELM": + SUBDIRS.remove("/apps/modules/init") + SUBDIRS.remove("/apps/modules/environments") + SUBDIRS.remove("/apps/modules/engineering") + SUBDIRS.remove("/apps/modules/libraries") + SUBDIRS.remove("/apps/modules/omics") + SUBDIRS.remove("/apps/modules/prace") - print "# Available Modules" - for dir in sorted(subdirs): - available_software = software_list(dir) - print "\n## %s\n" % os.path.basename(dir).title() + for subdir in sorted(SUBDIRS, key=lambda s: s.lower()): + available_software = get_software_list(subdir) + print "\n## %s\n" % os.path.basename(subdir).title() print "| Module | Description |" print "| ------ | ----------- |" - HTML_SOURCE_DATA[dir] = {} + HTML_SOURCE_DATA[subdir] = {} for soft in sorted(available_software, key=str.lower): - software_path = os.path.join(dir, soft) - if os.getenv('CLUSTER')!="ANSELM": - software_path = software_path.replace(os.path.basename(dir)+'/', 'all/') + software_path = os.path.join(subdir, soft) + if os.getenv('CLUSTER') != "ANSELM": + software_path = software_path.replace(os.path.basename(subdir)+'/', '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") + software_versions = [ver for ver in software_versions if not ver[0] == '.'] 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': [], + HTML_SOURCE_DATA[subdir][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())) - elif software_url=="(none)": - print "| %s | %s |" % (soft," ".join(software_description.split())) + HTML_SOURCE_DATA[subdir][soft]['versions'].append(version) + if software_url in ["", "(none)"]: + print "| %s | %s |" % (soft, " ".join(software_description.split())) else: - print "| [%s](%s) | %s |" % (soft,software_url," ".join(software_description.split())) + print "| [%s](%s) | %s |" % (soft, software_url, " ".join(software_description.split()))