×

Welcome to TagMyCode

Please login or create account to add a snippet.
3
0
 
0
Language: Python
Posted by: j.alejandromedina
Added: Jul 1, 2011 3:32 PM
Views: 732
Tags: no tags
  1. #!/usr/bin/env python
  2.  
  3. ###############################################################################
  4. ## modulegen.py
  5. ## This program creates a basic modulefile for software compliant with the
  6. ## FHS second hierarchy standard.
  7. #
  8. ## python modulegen.py git /share/apps/git | sudo tee $MODULESHOME/modulefiles/git
  9.  
  10. import sys
  11.  
  12. from string import Template
  13.  
  14. #### begin moduletemplate ####
  15. moduletemplate=Template("""
  16. #%Module1.0#####################################################################
  17. ##
  18. ## $modulename modulefile
  19. ##
  20. ## modulefiles/$modulename
  21. ##
  22. proc ModulesHelp { } {
  23.                puts stderr "This module sets up the $modulename environment on nanobio."
  24.                }
  25.  
  26.                module-whatis   "loads the $modulename environment"
  27.  
  28.                # for Tcl script use only
  29.  
  30.                prepend-path    PATH                "$modulepath/bin"
  31.                prepend-path    LD_LIBRARY_PATH     "$modulepath/lib64:$modulepath/lib"
  32.                prepend-path    MANPATH             "$modulepath/share/man"
  33.  
  34. """)
  35. #### end moduletemplate ####
  36.  
  37. def usage():
  38.     print "python modulegen.py software_name software_path"
  39.  
  40. def get_modulefile_string(swname, swpath):
  41.     return moduletemplate.substitute(modulename=swname, modulepath=swpath).strip()
  42.  
  43. if __name__ == "__main__":
  44.     if len(sys.argv) == 3:
  45.         swname=sys.argv[1]
  46.         swpath=sys.argv[2]
  47.         print get_modulefile_string(swname, swpath)
  48.     else:
  49.         usage()
  50.