-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfind-images.py
executable file
·40 lines (32 loc) · 1.23 KB
/
find-images.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
37
38
39
40
#!/usr/bin/env python
import os
import sys
# Add vendor directory to module search path
parent_dir = os.path.abspath(os.path.dirname(__file__))
vendor_dir = os.path.join(parent_dir, 'vendor')
sys.path.append(vendor_dir)
import yaml
def find(key, dictionary):
for k, v in dictionary.items():
if k == key:
yield v
elif isinstance(v, dict):
for result in find(key, v):
yield result
if __name__ == '__main__':
# traverse root directory, and list directories as dirs and files as files
for root, dirs, files in os.walk("."):
fullpath = os.path.abspath(root)
for file in files:
if file == 'values.yaml':
f = os.path.join(fullpath, file)
with open(f, 'r') as stream:
try:
data = yaml.safe_load(stream)
for image in find("image", data):
if isinstance(image, dict):
repo = image.get("repository", "")
tag = image.get("tag", "")
print(repo + ":" + tag)
except yaml.YAMLError as exc:
print(exc)