Skip to content
Snippets Groups Projects
Commit 7f04adcb authored by Porter Libby's avatar Porter Libby
Browse files

Update 2 files

- /pylist_all.sh
- /pylist.py
parent 40c67c94
No related merge requests found
import pkg_resources, socket, sys, platform, json
"""
Create an object containing all packages from the host python environment
Prints object to stout, for use in Bash script.
"""
def get_packages():
pyversion = {
'package_list': [],
'python_version': platform.python_version(),
'python_location': sys.executable,
'host_machine': socket.gethostname()
}
for m in pkg_resources.working_set:
pyversion['package_list'].append({
'name': m.project_name,
'version': m.version
})
return json.dumps(pyversion)
print(get_packages())
\ No newline at end of file
#!/bin/bash
# Hide Python Warnings
export PYTHONWARNINGS=ignore
# Source bashrc file if it exists
if [ -f /etc/bashrc ]; then
source /etc/bashrc
fi
if [ -f /etc/bash.bashrc ]; then
source /etc/bash.bashrc
fi
if [ -f /etc/profile.d/modules.sh ]; then
source /etc/profile.d/modules.sh
fi
# Collect data
DATA="[";
while read -r line ; do
module load $line &> /dev/null;
NEWOBJ=$(python /etc/snmp/scripts/pylist.py);
DATA+=$NEWOBJ;
DATA+=",";
module unload $line &> /dev/null;
done < <(module paths python/)
DATA=${DATA::-1}
DATA+="]";
# Output data
echo $DATA
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment