-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_collections.py
executable file
·36 lines (29 loc) · 1.03 KB
/
list_collections.py
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
#!/usr/bin/env python
import os
import sys
import warnings
# if you dont have ansible, how are you using collections??
from ansible import constants as C
try:
C.COLLECTIONS_SCAN_SYS_PATH
exit("newer Ansible, use: ansible-galaxy collections list")
except AttributeError:
pass
where = C.COLLECTIONS_PATHS
found = {}
for path in where:
collpath = os.path.join(path, 'ansible_collections')
if os.path.exists(collpath):
for ns in os.listdir(collpath):
nsp = os.path.join(collpath, ns)
if os.path.isdir(nsp):
for collection in os.listdir(nsp):
collp = os.path.join(nsp, collection)
if os.path.isdir(collp):
info = {'path': collp}
cname = '.'.join([ns, collection])
if cname in found:
warnings.warn("Skipping duplicate %s in %s" % (cname, collp))
found[cname] = info
for k in found.keys():
print(k, found[k]['path'])