CoCalc Public Filesautocommit.pyOpen with one click!
Authors: Tim Clemans SMC, Harald Schilly, William A. Stein, alwaysleaveanote alwaysleaveanote
Views : 77
Compute Environment: Ubuntu 18.04 (Deprecated)
1
import time
2
from watchdog.observers import Observer
3
from watchdog.events import PatternMatchingEventHandler
4
import os
5
import sys
6
7
class MyHandler(PatternMatchingEventHandler):
8
patterns = ["*.py", "*.html"]
9
10
def process(self, event):
11
"""
12
event.event_type
13
'modified' | 'created' | 'moved' | 'deleted'
14
event.is_directory
15
True | False
16
event.src_path
17
peoples_nsa_api
18
"""
19
# the file will be processed there
20
print event.src_path, event.event_type # print now only for degug
21
os.system('cd ~/insideyourgovernment_api; git add .; git commit -a -m "auto commit"; git push origin master')
22
23
def on_modified(self, event):
24
self.process(event)
25
26
def on_created(self, event):
27
self.process(event)
28
29
if __name__ == '__main__':
30
args = sys.argv[1:]
31
observer = Observer()
32
observer.schedule(MyHandler(), path=args[0] if args else 'insideyourgovernment_api', recursive=True)
33
observer.start()
34
35
try:
36
while True:
37
time.sleep(1)
38
except KeyboardInterrupt:
39
observer.stop()
40
41
observer.join()
42