-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
85 lines (70 loc) · 2.16 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# 运行:python3 run.py
import os
class Run:
def __init__(self):
self.path = os.path.abspath(os.path.dirname(__file__))
self.pdfTools = ("okular", "evince")
self.pdfTool = self.choose_pdf_tool()
self.pdfFile = "main.pdf"
def choose_pdf_tool(self):
tool = ""
for t in self.pdfTools:
notHasTool = os.system("which {}".format(t))
if notHasTool:
continue
tool = t
return tool
def change_dir(self, path):
os.chdir(path)
def compile(self):
path = self.path
self.change_dir(path)
compile_str, bib_str = 'xelatex main.tex', 'bibtex main.aux'
os.system(compile_str)
os.system(bib_str)
os.system(compile_str)
os.system(compile_str)
def clear(self):
os.system("latexmk -C")
def remove_file(self, path, filename):
file = os.path.join(path, filename)
if (os.path.exists(file)):
os.remove(file)
def list_dir(self):
path = self.path
print("{0}项目下的文件或目录{0}".format("="*5))
for f in os.listdir(path):
print(f)
print("="*20)
def view_pdf(self):
pdfFilePath = os.path.join(self.path, self.pdfFile)
fileExist = os.path.exists(pdfFilePath)
if fileExist:
os.system("{0} {1}".format(self.pdfTool, self.pdfFile))
else:
print("="*22)
print("警告{0} 不存在".format(self.pdfFile))
print("="*22)
def debug(self):
pass
if __name__ == "__main__":
run = Run()
prompt = """
输入 1、2、3、4来执行下面的操作,输入 q 或 Q 退出
1.编译项目
2.清除多余文件
3.查看项目下的文件
4.查看 pdf
"""
while True:
i = input(prompt)
if i == 'q' or i == 'Q':
break
if i == '1':
run.compile()
if i == '2':
run.clear()
if i == '3':
run.list_dir()
if i == '4':
run.view_pdf()