StoryCheckTools/manage/NovelManage.py

83 lines
2.6 KiB
Python
Raw Permalink Normal View History

2024-07-29 13:34:31 +00:00
import os
2024-07-29 03:52:28 +00:00
import subprocess as xsub
2024-07-29 13:34:31 +00:00
import sys
2024-07-29 03:52:28 +00:00
import time
2024-07-29 03:58:41 +00:00
from typing import List
2024-07-29 14:19:48 +00:00
from PyQt5.QtWidgets import QApplication
2024-07-29 04:56:42 +00:00
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
2024-07-29 13:34:31 +00:00
from parse.StoryMap import XAST_ParseTool, storyline_list2map
from parse.StorylineCmp import CmpTool
2024-07-29 04:50:59 +00:00
from manage.MileStone import base_store_path, current_store_path
2024-07-29 14:19:48 +00:00
from frame.CompareViews import CompareWindow
2024-08-02 15:02:46 +00:00
from frame.ContentView import StorylinesView, ArticleRefsView
2024-07-29 03:52:28 +00:00
def git_save(target_dir: str):
retls = xsub.run("git status", shell=True, capture_output=True)
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 04:41:56 +00:00
delete_flag = r"\tdeleted:"
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
2024-07-29 04:41:56 +00:00
elif o.startswith(delete_flag):
has_changed = True
files_path.append(o[len(delete_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()}'")
2024-07-29 04:41:56 +00:00
def nsc_compile(target_dir: str):
retls = xsub.run("nsc --path ./ --dest E:/", shell=True)
2024-07-29 03:52:28 +00:00
if __name__ == "__main__":
2024-07-29 14:19:48 +00:00
app = QApplication(sys.argv)
2024-07-29 03:52:28 +00:00
cmd_line = ":".join(sys.argv[1:])
2024-07-29 04:41:56 +00:00
2024-07-29 03:52:28 +00:00
#wnss:-cmp
if cmd_line == "wnss:-cmp":
2024-07-29 04:41:56 +00:00
git_save(os.getcwd())
2024-07-29 04:50:59 +00:00
nsc_compile(os.getcwd())
ast_old = XAST_ParseTool(base_store_path)
ast_new = XAST_ParseTool(current_store_path)
map_old = storyline_list2map(ast_old.story_list)
2024-07-29 14:19:48 +00:00
ast_old.storylines_plait(map_old)
2024-07-29 04:50:59 +00:00
map_new = storyline_list2map(ast_new.story_list)
2024-07-29 14:19:48 +00:00
ast_new.storylines_plait(map_new)
2024-07-29 04:50:59 +00:00
cmp_tool = CmpTool()
all_changed = cmp_tool.graph_compare(map_new, map_old)
2024-07-29 14:19:48 +00:00
present_view = CompareWindow(map_new, all_changed, None)
present_view.show()
2024-08-02 15:02:46 +00:00
pass
elif cmd_line == "wnss:-prsn":
git_save(os.getcwd())
nsc_compile(os.getcwd())
stool = XAST_ParseTool(current_store_path)
graph_curr = stool.get_story_graph()
story_lines_view = StorylinesView(None)
story_lines_view.show()
story_lines_view.present_stories_graph(graph_curr)
frags_curr = stool.get_article_nodes()
frags_refs_view = ArticleRefsView(None)
frags_refs_view.show()
frags_refs_view.present_volumes_graph(frags_curr)
pass
app.exec()