Skip to content
Snippets Groups Projects
modules.py 3.1 KiB
Newer Older
Easy Build's avatar
Easy Build committed
#!/usr/bin/env python

import os
import re

David Hrbáč's avatar
David Hrbáč committed
def get_software_list(path):
Easy Build's avatar
Easy Build committed
    """List software from given module class"""
David Hrbáč's avatar
David Hrbáč committed
    os.chdir(path)
Easy Build's avatar
Easy Build committed
    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

David Hrbáč's avatar
David Hrbáč committed
def get_software_versions(path):
Easy Build's avatar
Easy Build committed
    """List available versions of software"""
David Hrbáč's avatar
David Hrbáč committed
    os.chdir(path)
Easy Build's avatar
Easy Build committed
    return next(os.walk('.'))[2]

def get_module_description(module_path):
    """Return software homepage URL and description"""
    url = ""
    description = "Old module, description not available."
David Hrbáč's avatar
David Hrbáč committed
    with open(module_path) as _file:
        content = _file.read()
    if module_path.endswith('lua'):
David Hrbáč's avatar
David Hrbáč committed
        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+)}",
David Hrbáč's avatar
David Hrbáč committed
                         content, re.DOTALL)
Easy Build's avatar
Easy Build committed
    try:
        description = data.group(2)
David Hrbáč's avatar
David Hrbáč committed
        url = data.group(3)
Easy Build's avatar
Easy Build committed
    except AttributeError:
        pass
    return url, description

if __name__ == "__main__":
    HTML_SOURCE_DATA = {}
David Hrbáč's avatar
David Hrbáč committed
    SUBDIRS = os.environ['MODULEPATH'].split(':')
Easy Build's avatar
Easy Build committed

David Hrbáč's avatar
David Hrbáč committed
    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")
David Hrbáč's avatar
David Hrbáč committed
    for subdir in sorted(SUBDIRS, key=lambda s: s.lower()):
        available_software = get_software_list(subdir)
David Hrbáč's avatar
David Hrbáč committed
        print "\n## %s\n" % os.path.basename(subdir).title()
Easy Build's avatar
Easy Build committed
        print "| Module | Description |"
        print "| ------ | ----------- |"
David Hrbáč's avatar
David Hrbáč committed
        HTML_SOURCE_DATA[subdir] = {}
Easy Build's avatar
Easy Build committed
        for soft in sorted(available_software, key=str.lower):
David Hrbáč's avatar
David Hrbáč committed
            software_path = os.path.join(subdir, soft)
            if os.getenv('CLUSTER') != "ANSELM":
                software_path = software_path.replace(os.path.basename(subdir)+'/', 'all/')
Easy Build's avatar
Easy Build committed
            software_versions = get_software_versions(software_path)
David Hrbáč's avatar
David Hrbáč committed
            software_versions = [ver for ver in software_versions if not ver[0] == '.']
Easy Build's avatar
Easy Build committed

            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)
David Hrbáč's avatar
David Hrbáč committed
            HTML_SOURCE_DATA[subdir][soft] = {'versions': [],
Easy Build's avatar
Easy Build committed
                                           'url': software_url,
                                           'description': software_description}
            for version in software_versions:
David Hrbáč's avatar
David Hrbáč committed
                HTML_SOURCE_DATA[subdir][soft]['versions'].append(version)
            if software_url in ["", "(none)"]:
                print "| %s | %s |" % (soft, " ".join(software_description.split()))
Easy Build's avatar
Easy Build committed
            else:
David Hrbáč's avatar
David Hrbáč committed
                print "| [%s](%s) | %s |" % (soft, software_url, " ".join(software_description.split()))