Last active
January 20, 2016 09:23
-
-
Save yanqiw/cdc80b111fea629aa053 to your computer and use it in GitHub Desktop.
this code is used to watch folder, after file changes, add and commit the git
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
''' | |
this script is used watch the folder. after file changes, auto add and commit the git | |
run python git-auto-add.py [commit comments] | |
''' | |
import time | |
import sys | |
import os | |
from watchdog.observers import Observer | |
from watchdog.events import PatternMatchingEventHandler | |
class MyHandler(PatternMatchingEventHandler): | |
def setComments(self, msg): | |
self.msg = msg | |
pass | |
def on_modified(self, event): | |
print self.msg | |
os.system('git add -A'); | |
os.system('git commit -m "' + self.msg + '"') | |
if __name__ == "__main__": | |
patt = ['*.py', '*.js', '*.html'] | |
event_handler = MyHandler(patt) | |
event_handler.setComments(sys.argv[1] if len(sys.argv) > 1 else 'auto add and commit') | |
observer = Observer() | |
observer.schedule(event_handler, path='.', recursive=True) | |
observer.start() | |
try: | |
while True: | |
time.sleep(1) | |
except KeyboardInterrupt: | |
observer.stop() | |
observer.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment