-
Notifications
You must be signed in to change notification settings - Fork 14
/
iOSApprovalsWatcher.py
executable file
·74 lines (56 loc) · 1.92 KB
/
iOSApprovalsWatcher.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/env python3
import argparse
import datetime
import os
import stat
import subprocess
import sys
import time
class WatchedFile:
path = ''
date = datetime.datetime(2000, 1, 1)
def __init__(self, path):
self.path = path
def __repr__(self):
return f'{str(self.date)} {self.path}'
def remove(self):
if os.path.exists(self.path):
os.remove(self.path)
def monitor(self):
if os.path.exists(self.path):
current_date = datetime.datetime.fromtimestamp(os.stat(self.path).st_mtime)
if self.date < current_date:
self.date = current_date
print(self)
os.chmod(self.path, os.stat(self.path).st_mode | stat.S_IEXEC)
subprocess.Popen(self.path)
def monitor_files(files):
while True:
time.sleep(0.5)
for watched_file in files:
watched_file.monitor()
def remove(files):
for watched_file in files:
watched_file.remove()
def directories_in(root):
paths = [root]
for dir_path in os.listdir(root):
path = os.path.join(root, dir_path)
if os.path.isdir(path):
paths.append(path)
directories_in(path)
return paths
def watchlist(relative_path, search_for):
absolute_path = os.path.abspath(relative_path)
directories = directories_in(absolute_path)
return [WatchedFile(os.path.join(directory, search_for)) for directory in directories]
def parse_arguments():
parser = argparse.ArgumentParser(description='Watch for iOS approvals.')
parser.add_argument('test_directory', type=str, help='Path to test directory')
return parser.parse_args()
if __name__ == '__main__':
args = parse_arguments()
watched_files = watchlist(args.test_directory, 'command.sh')
remove(watched_files)
print('Ready for iOS Approval Tests. Control-C to quit.')
monitor_files(watched_files)