-
Notifications
You must be signed in to change notification settings - Fork 2
/
approvals.py
29 lines (25 loc) · 970 Bytes
/
approvals.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
#!/usr/bin/env python
# A quick script to automate approval file wrangling
import fnmatch
import os
import subprocess
pending_approvals = []
for root, dirnames, filenames in os.walk('sana_pchr'):
for filename in fnmatch.filter(filenames, '*.received.*'):
pending_approvals.append(os.path.join(root, filename))
for pending_approval_path in pending_approvals:
received_path = pending_approval_path
approved_path = pending_approval_path.replace(".received.", ".approved.")
print(os.path.basename(pending_approval_path))
if os.path.exists(approved_path):
subprocess.call(["diff", approved_path, received_path])
else:
try:
print(open(received_path, "r").read())
except UnicodeDecodeError:
print("Binary file")
res = input("Approve? (y/n):")
if res == 'y':
if os.path.exists(approved_path):
os.remove(approved_path)
os.rename(received_path, approved_path)