-
Notifications
You must be signed in to change notification settings - Fork 1
/
list-module-packages
executable file
·43 lines (31 loc) · 1.17 KB
/
list-module-packages
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
source "/etc/profile.d/modules.sh"
# Modules version 5.1.0 adds the redirection option we need to make this consistent
source "/shared/ucl/apps/modules/5.1.0/init/bash"
module load --auto python3/recommended 2>/dev/null >/dev/null
# If we don't load these modules, the beta modules and workaround modules aren't visible
module load workaround-modules
module load beta-modules
temp_file_dir="$(mktemp -d)"
# This does an extremely dodgy YAML conversion.
module whatis --redirect --no-pager \
| grep -e ':' -e '---' \
| sed -e 's/"/\\"/g' \
-e 's/^ *//' \
-e 's/^\([^-][^:]*\): \(.*\)/ - Name: "\1"\n Description: "\2"/' \
-e 's@^---* [^ ]*/\([^ /]*\) ---*$@\1:@' \
> "$temp_file_dir/tmp.whatis.yaml"
<"$temp_file_dir/tmp.whatis.yaml" \
python -c '
import yaml
import json
import sys
import datetime
package_list = yaml.safe_load(sys.stdin.read())
utc_dt = datetime.datetime.now(datetime.timezone.utc) # UTC time
dt = utc_dt.astimezone() # local time
info = {"generated": dt.strftime("%Y-%m-%dT%H:%M:%S%z"),
"package_groups": package_list}
print(json.dumps(info, indent=3))
'
'rm' "$temp_file_dir/tmp.whatis.yaml"