Initial version of the sit script listing all versions of installed modules.
This commit is contained in:
parent
0be4a91a0f
commit
44fff0ff8f
1 changed files with 55 additions and 0 deletions
55
sit-list-installed.py
Executable file
55
sit-list-installed.py
Executable file
|
@ -0,0 +1,55 @@
|
|||
#!/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()
|
||||
|
||||
|
Loading…
Reference in a new issue