56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
|
#!/usr/bin/env python
|
||
|
#
|
||
|
# Script to find out the versions of installed software modules
|
||
|
#
|
||
|
# Christoph Niethammer <niethammer@hlrs.de> Copyright 2011
|
||
|
#
|
||
|
|
||
|
import os
|
||
|
import sys
|
||
|
import subprocess
|
||
|
import shlex
|
||
|
|
||
|
import re
|
||
|
import string
|
||
|
|
||
|
def module_cmd( cmd ) :
|
||
|
m = subprocess.Popen('module ' + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||
|
return m.communicate()
|
||
|
|
||
|
def find_module_versions( module = "" ) :
|
||
|
m = subprocess.Popen('module av -l ' + module, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||
|
stdout_data, stderr_data = m.communicate()
|
||
|
mlist = stderr_data
|
||
|
mregex = "^"+module+"/(\S*)\s+.+\Z"
|
||
|
versions=[]
|
||
|
for m in mlist.split("\n") :
|
||
|
m_version = re.findall(mregex, m)
|
||
|
if m_version :
|
||
|
versions.append(m_version[0])
|
||
|
return versions
|
||
|
|
||
|
def find_modules() :
|
||
|
modules = set()
|
||
|
stdout_data, stderr_data = module_cmd( "av -l")
|
||
|
mlist = stderr_data
|
||
|
mregex = "^(\w\S*/\S+)/\S+\s+.+\Z"
|
||
|
for m in mlist.split("\n") :
|
||
|
module = re.findall(mregex, m)
|
||
|
if module :
|
||
|
modules.add(module[0])
|
||
|
return list(modules)
|
||
|
|
||
|
def main() :
|
||
|
if len(sys.argv) > 1 :
|
||
|
for module in sys.argv[1:] :
|
||
|
print {module : find_module_versions(module)}
|
||
|
else :
|
||
|
modules = find_modules()
|
||
|
for module in modules :
|
||
|
print {module : find_module_versions(module)}
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|
||
|
|
||
|
|