Skip to content
Snippets Groups Projects
modules_compare.py 1.61 KiB
Newer Older
  • Learn to ignore specific revisions
  • #!/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))