StoryCheckTools/manage/NovelManage.py

35 lines
952 B
Python
Raw Normal View History

2024-07-29 03:52:28 +00:00
import sys, os
import subprocess as xsub
import time
2024-07-29 03:58:41 +00:00
from typing import List
2024-07-29 03:52:28 +00:00
def git_save(target_dir: str):
retls = xsub.run("git status", shell=True, capture_output=True)
print(retls.stdout)
outlist = str(retls.stdout).split(r'\n')
has_changed:bool = False
2024-07-29 03:58:41 +00:00
files_path:List[str] = []
2024-07-29 03:52:28 +00:00
for o in outlist:
2024-07-29 03:58:41 +00:00
modified_flag = r"\tmodified:"
2024-07-29 04:01:14 +00:00
new_flag = r"\tnew file:"
2024-07-29 03:58:41 +00:00
if o.startswith(modified_flag):
2024-07-29 03:52:28 +00:00
has_changed = True
2024-07-29 03:58:41 +00:00
files_path.append(o[len(modified_flag):])
2024-07-29 04:01:14 +00:00
elif o.startswith(new_flag):
2024-07-29 03:52:28 +00:00
has_changed = True
2024-07-29 04:01:14 +00:00
files_path.append(o[len(new_flag):])
2024-07-29 03:52:28 +00:00
if has_changed:
2024-07-29 04:01:14 +00:00
xsub.run(f"git add {" ".join(files_path)}", shell=True)
2024-07-29 03:52:28 +00:00
xsub.run(f"git commit -m 'save-at:{time.time()}'")
if __name__ == "__main__":
print(sys.argv)
cmd_line = ":".join(sys.argv[1:])
#wnss:-cmp
if cmd_line == "wnss:-cmp":
git_save(os.getcwd())