-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfreshness_check.py
More file actions
63 lines (54 loc) · 1.95 KB
/
Copy pathfreshness_check.py
File metadata and controls
63 lines (54 loc) · 1.95 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
"""
Flag stale entries (> 6 months).
"""
import os
import glob
import yaml
from datetime import datetime, timedelta
import sys
def load_services():
script_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.dirname(os.path.dirname(script_dir))
services_dir = os.path.join(project_root, 'services')
services = []
for yaml_file in glob.glob(os.path.join(services_dir, '**', '*.yml'), recursive=True):
try:
with open(yaml_file, 'r') as f:
data = yaml.safe_load(f)
services.append((yaml_file, data['service']))
except Exception as e:
print(f"Error loading {yaml_file}: {e}")
for yaml_file in glob.glob(os.path.join(services_dir, '**', '*.yaml'), recursive=True):
try:
with open(yaml_file, 'r') as f:
data = yaml.safe_load(f)
services.append((yaml_file, data['service']))
except Exception as e:
print(f"Error loading {yaml_file}: {e}")
return services
def is_stale(last_verified_str):
if not last_verified_str:
return True # If empty or None, consider stale
try:
last_verified = datetime.strptime(last_verified_str, '%Y-%m-%d')
six_months_ago = datetime.now() - timedelta(days=180)
return last_verified < six_months_ago
except (ValueError, TypeError):
return True # If date format wrong or not a string, consider stale
def main():
services = load_services()
stale = []
for yaml_file, service in services:
last_verified = service.get('metadata', {}).get('last_verified', '')
if is_stale(last_verified):
stale.append((yaml_file, last_verified))
if stale:
print("Stale entries (> 6 months):")
for file, date in stale:
print(f" {file}: last verified {date}")
sys.exit(1)
else:
print("All entries are fresh.")
if __name__ == "__main__":
main()