首先关键部位:
- 工作空间 data 文件夹
- Git 程序
- 上面完工就万事俱备了
#已有仓库
cd D:\SiYuanData
git remote add origin https://gitee.com/cuijianzhe/ssgage.git
git push -u origin master
其实无非就是把 Git 自己完成而已,这其中有一个问题,刚改完建议不要马上执行同步,因为
D:\siyuan\data\.siyuan\conf.json
这个文件好像还没修正好时间数据,需耐心等待他完成,不过我的程序已在等待……
import os
import time
from subprocess import call
GIT_BASE_DIR = 'D:\siyuan'
gitdate = time.strftime("%Y%m%d%H%M%S", time.localtime())
GIT_DIR_DATA = GIT_BASE_DIR + '\data\.siyuan\conf.json'
choice_list = ['仅更新','上传','抹除本地更改然后更新']
def git_init():
os.chdir(GIT_BASE_DIR)
git_init_cmd = "git init ."
git_add_cmd = "git add -A"
git_commit_cmd = "git commit -m {}".format(gitdate)
git_push_cmd = "git push origin master"
call(
git_init_cmd + "&&" +
git_add_cmd + "&&" +
git_commit_cmd + "&&" +
git_push_cmd,
shell=True
)
def git_update():
os.chdir(GIT_BASE_DIR)
git_pull_cmd = "git pull origin master"
call(
git_pull_cmd,
shell=True
)
def git_reset_update():
os.chdir(GIT_BASE_DIR)
git_reset = "git reset --hard"
git_pull_cmd = "git pull origin master"
call(
git_reset + "&&" +
git_pull_cmd,
shell=True
)
def file_or_open():
try:
with open(GIT_DIR_DATA, 'r') as f:
context = f.read()
return context
except PermissionError as error:
return False
if __name__ == "__main__":
while True:
context = file_or_open()
if context:
for num, char in enumerate(choice_list):
print(num, char)
while True:
git_num = input('配置修正已完成,请按照以上提示输入相应的序号:')
if git_num == '0':
git_update()
time.sleep(5)
break
if git_num == '1':
git_init()
time.sleep(5)
break
if git_num == '2':
git_reset_update()
time.sleep(5)
break
else:
print('输入错误,请重新输入')
break
else:
print('正在尝试打开并修正配置文件,请稍等……')
time.sleep(5)
如此,每次更新完后,手动执行一下程序即可,千万不要忘记哦……
还有,windows 可以打包,我已打包完成,直接点击一下 exe
即可。