1 Star 0 Fork 0

nsyouran/EAGLE

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
file_sync.py 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
nsyouran 提交于 2016-12-02 17:17 . Update_.sublff5.tmp
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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/nsyouran/EAGLE.git
git@gitee.com:nsyouran/EAGLE.git
nsyouran
EAGLE
EAGLE
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385