-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_collection_info.py
More file actions
executable file
·38 lines (29 loc) · 995 Bytes
/
get_collection_info.py
File metadata and controls
executable file
·38 lines (29 loc) · 995 Bytes
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
#!/usr/bin/env python
import os
import sys
# 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
if len(sys.argv) != 2:
exit("This script requires a single collection name as an argument.")
what = sys.argv[1]
try:
ns, coll = what.split('.',1)
except ValueError:
exit("Invalid collection name supplied: %s" % what)
for path in where:
collpath = os.path.join(path, 'ansible_collections', ns, coll)
if os.path.exists(collpath):
mpath= os.path.join(collpath, 'MANIFEST.json')
if not os.path.exists(mpath):
exit("Found collection at '%s' but missing MANIFEST.json, cannot get info." % collpath)
with open(mpath, 'r') as f:
print(f.read())
break
else:
exit("Collection '%s' not found in '%s'" % (what, where))