源码放在https://gitee.com/yhli/misc/tree/master/pmod上了。
组里有一台服务器硬盘坏了。上周抽空修好它,重装系统后,觉得用export XXXX=xxx:$XXXX设置环境变量太麻烦。一旦手滑把PATH或者LD_LIBRARY_PATH拼错,就进不了系统了。于是就先写了这么个修改环境变量的函数
- function setenv ()
- {
- case $1 in
- mod)
- export PATH=$2/bin:$PATH
- export LIBRARY_PATH=$2/lib:$LIBRARY_PATH
- export LD_LIBRARY_PATH=$2/lib:$LD_LIBRARY_PATH
- export C_INCLUDE_PATH=$2/include:$C_INCLUDE_PATH
- export CPLUS_INCLUDE_PATH=$2/include:$CPLUS_INCLUDE_PATH
- ;;
- path)
- export PATH=$2:$PATH
- ;;
- lib)
- export LIBRARY_PATH=$2:$LIBRARY_PATH
- export LD_LIBRARY_PATH=$2:$LD_LIBRARY_PATH
- ;;
- inc)
- export C_INCLUDE_PATH=$2:$C_INCLUDE_PATH
- export CPLUS_INCLUDE_PATH=$2:$CPLUS_INCLUDE_PATH
- ;;
- py)
- export PYTHONPATH=$2:$PYTHONPATH
- ;;
- *)
- echo "Unrecognized environment variable $1"
- ;;
- esac
- }
复制代码 后来在师弟的不断修改下,这个函数功能越来越多,具有了模块管理系统的雏形。但用shell写复杂一点的东西很麻烦,想传个列表给函数要倒好几趟手。专业的模块管理系统比如lmod又需要学习,就自己用python写了一个简单的。
整个程序很简单,只有三个文件。核心思想是把模块配置信息存在字典中;bash接收命令行参数并转发给python脚本,再执行由python脚本返回的bash命令。目前支持输出模块信息、加载和卸载模块、自动加载依赖模块、执行附加命令等功能。安装不强求root权限,适合几个人用的单一节点,也可以单人使用。
配置信息是这样的:
- # Module configurations
- avail_mods = dict()
- prefix = "/home/yhli/soft"
- # for shared libraries
- add_mod("mkl-13.0.079", "mod", prefix+"/mkl-13.0.079")
- add_mod("mkl-13.0.079", "lib", prefix+"/mkl-13.0.079/lib/intel64")
- add_mod("fftw-3.3.4", "mod", prefix+"/fftw-3.3.4")
- add_mod("hdf5-1.8.17", "mod", prefix+"/hdf5-1.8.17")
- add_mod("libxc-4.2.3","mod", prefix+"/libxc-4.2.3")
- # for openmpi
- add_mod("openmpi-1.10.0", "mod", prefix+"/openmpi-1.10.0")
- # for DFT and GW software
- add_mod("qe-6.2", "path", prefix+"/qe-6.2/bin",
- dep=["mkl-13.0.079", "openmpi-1.10.0", "hdf5-1.8.17"])
- add_mod("qe-5.4.0", "path", prefix+"/espresso-5.4.0/bin",
- dep=["mkl-13.0.079", "openmpi-1.10.0"])
- add_mod("bgw-1.2.0", "path", prefix+"/bgw-1.2.0/bin",
- dep=["mkl-13.0.079", "openmpi-1.10.0", "hdf5-1.8.17", "fftw-3.3.4"])
- add_mod("elk-4.0.15", "path", prefix+"/elk-4.0.15/bin",
- dep=["mkl-13.0.079", "openmpi-1.10.0"])
- add_mod("wannier90-2.1.0", "path", prefix+"/wannier90-2.1.0",
- dep=["mkl-13.0.079", "openmpi-1.10.0"])
- add_mod("vasp.5.4.1", "path", prefix+"/vasp.5.4.1/bin",
- dep=["mkl-13.0.079", "openmpi-1.10.0"])
- add_mod("exciting.carbon", "path", prefix+"/exciting.carbon/bin",
- dep=["mkl-13.0.079", "openmpi-1.10.0"])
复制代码 运行效果如图:
|