-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatcher.py
123 lines (101 loc) · 3.72 KB
/
watcher.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*-coding:Utf-8 -*
from subprocess import *
import os, time, sys
#get the Python files in a dir
def getPyFiles(paths = ['src', 'src/lib'], files = ['input.txt', 'watcher.py', 'script.py']):
for directory in paths:
for elmt in os.listdir(directory):
if elmt.endswith(".py"):
yield [directory+'/'+elmt, getModificationTime(directory+'/'+elmt)]
for filename in files:
yield [filename, getModificationTime(filename)]
#get the modification time of the file
def getModificationTime(filename):
return os.stat(filename).st_mtime
#print the sleepy snoring fox
def printSleepy():
print(""" |\ _,,,---,,_
/,`.-'`' -. ;-;;,_
|,4- ) )-,_..;\ ( `'-'
'---''(_/--' `-'\_) zzz zzz
""")
#the main method
def fileWatcher():
outputFormat = ''
for arg in sys.argv:
if arg == '--frequency':
outputFormat = 'frequency'
if arg == '--percent':
outputFormat = 'percent'
files = list(getPyFiles())
sleepy = 0
while 1:
for elmt in files:
if elmt[1] != getModificationTime(elmt[0]):
if str(elmt[0]) == 'watcher.py':
print('********** Please restart the watcher \n \n')
elmt[1] = getModificationTime(elmt[0])
else:
print('***** Processing *****')
if outputFormat == '':
call(['python', 'script.py'])
elif outputFormat == 'frequency':
call(['python', 'src/script.py', '--frequency'])
else:
call(['python', 'src/script.py', '--percent'])
print('***** End ***** \n')
elmt[1] = getModificationTime(elmt[0])
sleepy = 0
break
else:
files = list(getPyFiles())
sleepy += 1
if sleepy > 100:
sleepy = 0
printSleepy()
time.sleep(1)
if __name__=='__main__':
welcome = """ _____ _
/ __ \ | |
| / \/_ __ _ _ _ __ | |_
| | | '__| | | | '_ \| __|
| \__/\ | | |_| | |_) | |_
\____/_| \__, | .__/ \__|
__/ | |
|___/|_|
__ ___ _
\ \ / / | | |
\ \ /\ / /| |__ __ _| |_ __ _
\ \/ \/ / | '_ \ / _` | __| / _` |
\ /\ / | | | | (_| | |_ | (_| |
\/ \/ |_| |_|\__,_|\__| \__,_|
_ _ _ __ _
| | | | (_)/ _| | |
| |__ ___ __ _ _ _| |_ _| |_ _ _| |
| '_ \ / _ \/ _` | | | | __| | _| | | | |
| |_) | __/ (_| | |_| | |_| | | | |_| | |
|_.__/ \___|\__,_|\__,_|\__|_|_| \__,_|_|
_ _
| | | |
__| | __ _ _ _ | |_ ___
/ _` |/ _` | | | | | __/ _ \
| (_| | (_| | |_| | | || (_) |
\__,_|\__,_|\__, | \__\___/
__/ |
|___/
_ _
| | | |
__| | ___ ___ _ __ _ _ _ __ | |_
/ _` |/ _ \/ __| '__| | | | '_ \| __|
| (_| | __/ (__| | | |_| | |_) | |_
\__,_|\___|\___|_| \__, | .__/ \__|
__/ | |
|___/|_|
_ __ ___ ___ ___ ___ __ _ __ _ ___ ___
| '_ ` _ \ / _ \/ __/ __|/ _` |/ _` |/ _ \/ __|
| | | | | | __/\__ \__ \ (_| | (_| | __/\__ \\
|_| |_| |_|\___||___/___/\__,_|\__, |\___||___/
__/ |
|___/ """
print(welcome)
fileWatcher()