代码拉取完成,页面将自动刷新
import sys
import ntpath
import os
import re
import platform
from subprocess import call
from subprocess import check_output
from watchdog.observers import Observer
from watchdog.events import *
import time
DIR_FOR_GIT = os.path.dirname(os.path.abspath(__file__))
#print("DIR_FOR_GIT : {0} ".format(DIR_FOR_GIT))
#Changes not staged for commit:
def on_change(event,str):
if event.is_directory:
print "directory ",str
else:
print "file ",str
log = check_output("git status")
if not "Changes not staged for commit:" in log:
print "no needed"
return
print "needed"
cd_cmd = "cd "+DIR_FOR_GIT
git_add_cmd = "git add -A"
git_commit_cmd = "git commit -m " + re.escape("Update "+path_leaf(event.src_path))
if platform.system() == "Windows":
git_commit_cmd = "git commit -m " + re.escape("Update_"+path_leaf(event.src_path))
git_pull_cmd = "git pull origin master"
git_push_cmd = "git push origin master"
call(
cd_cmd + "&&" +
git_add_cmd + "&&" +
git_commit_cmd + "&&" +
git_pull_cmd + "&&" +
git_push_cmd,
shell=True
)
def path_leaf(path):
head, tail = ntpath.split(path)
return tail or ntpath.basename(head)
class FileEventHandler(FileSystemEventHandler):
def __init__(self):
FileSystemEventHandler.__init__(self)
def on_moved(self, event):
on_change(event,"moved");
def on_created(self, event):
on_change(event,"created");
def on_deleted(self, event):
on_change(event,"deleted");
def on_modified(self, event):
on_change(event,"modified");
if __name__ == "__main__":
observer = Observer()
event_handler = FileEventHandler()
observer.schedule(event_handler,DIR_FOR_GIT,False)
observer.start()
try:
while True:
time.sleep(3000)
except KeyboardInterrupt:
observer.stop()
observer.join()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。