-
Notifications
You must be signed in to change notification settings - Fork 2
/
makeall.py
193 lines (152 loc) · 6.52 KB
/
makeall.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env python3
#_∗_coding: utf-8 _∗_
import os
import shutil
import pathlib
import re
import subprocess
def compileall(task='all'): #'all','compare'
print(os.linesep)#这些都是字符串
print(os.sep)
print(os.pathsep)
print(os.curdir)
print(os.pardir)
print(os.getcwd())
print(os.listdir(path='.'))
if task=='all':
pwd=os.getcwd()
filesneedcopy=["bibmap.sty",
"bibmap.py",
"bibmapaddauthoran.py",
"bibmapaddbihuakey.py",
"bibmapaddkw.py",
"bibmapaddpinyinkey.py",
"bibmapdefault.py",
"bibmapsomeset.py",
"bibmaptitlecase.py",
"bibmaptitlecases.py",
"bibmaptobibtex.py",
"bibstyleauthoryear.py",
"bibstyleexample.py",
"bibstylenumeric.py",
"bibstyletabthreecols.py",
"bibstyletabtwocols.py",
"hanzicollationpinyin.py",
"hanzicollationstroke.py",
"hanzipinyindatabase.py"]
filelatexext=[".aux", ".bbl", ".blg", ".log", ".out", ".toc", ".bcf",
".xml", ".synctex", ".nlo", ".nls", ".bak", ".ind", ".idx",
".ilg", ".lof", ".lot", ".ent-x", ".tmp", ".ltx", ".los",
".lol", ".loc", ".listing", ".gz", ".userbak", ".nav", ".snm", ".vrb",
".fls", ".xdv", ".fdb_latexmk"]
#复制相关文件
dirlst=os.listdir()
subdirlst=[]
for elem in dirlst:
#print('elem=',elem)
if os.path.isdir(elem) and elem != ".git" and elem not in ["bibfiles"]:
subdir=pwd+os.sep+elem
subdirlst.append(subdir)
for file in filesneedcopy:
shutil.copyfile(pwd+os.sep+file,subdir+os.sep+file)
print(subdir+os.sep+file+' ... copied')
#进入相关文件夹进行编译
for dirname in ["backendtest","backendtest-tabbib","backendtest-lanparal"]: #
subdir=pwd+os.sep+dirname
os.chdir(subdir)
pwd=os.getcwd()
print('pwd=',pwd)
print(os.listdir())
#--------编译latex---------
fileuniset=["eg*.tex","test*.tex"]
for fileuni in fileuniset:
pf1=pathlib.Path('.').glob(fileuni)
pf=[str(x) for x in pf1]
print('pf=',pf)
if pf:
for file in pf:
print('---------compile new file:---------')
print('file=',file)
print('file=',os.path.splitext(file))
jobname=os.path.splitext(file)[0]
#删除辅助文件
for fileext in filelatexext:
fileaux=pwd+os.sep+jobname+fileext
if os.path.exists(fileaux):
os.remove(fileaux)
#latex编译
latexcmd="xelatex"
subprocess.run([latexcmd,"-no-pdf",file],check=True)
subprocess.run("python bibmap.py "+jobname,shell=True)
subprocess.run([latexcmd,file],check=True)
#--------编译latex结束---------
os.chdir(os.pardir)
pwd=os.getcwd()
print('pwd=',pwd)
#进入相关文件夹进行测试
for dirname in ["mapbibtest","mapbibtest-authoran","mapbibtest-casetransfer","mapbibtest-tobibtex"]: #
subdir=pwd+os.sep+dirname
os.chdir(subdir)
pwd=os.getcwd()
print('pwd=',pwd)
print(os.listdir())
fileuniset=["*.bib"]
for fileuni in fileuniset:
pf1=pathlib.Path('.').glob(fileuni)
pf=[str(x) for x in pf1]
print('pf=',pf)
if pf:
for file in pf:
if 'new' not in file:
print('---------compile new file:---------')
print('file=',file)
print('file=',os.path.split(file))
jobname=os.path.split(file)[1]
if dirname == "mapbibtest":
#python bibmap.py test.bib -m bibmapaddpinyinkey.py --nofmt
subprocess.run(["python", "bibmap.py",jobname,'-m', 'bibmapaddpinyinkey.py', '--nofmt'],check=True)
elif dirname == "mapbibtest-authoran":
subprocess.run(["python", "bibmap.py",jobname,'-m', 'bibmapaddauthoran.py', '--nofmt'],check=True)
elif dirname == "mapbibtest-casetransfer":
subprocess.run(["python", "bibmap.py",jobname,'-m', 'bibmaptitlecases.py','--nofmt'],check=True)
elif dirname == "mapbibtest-tobibtex":
subprocess.run(["python", "bibmap.py",jobname,'-m', 'bibmaptobibtex.py','--nofmt'],check=True)
#返回上级目录
os.chdir(os.pardir)
pwd=os.getcwd()
print('pwd=',pwd)
#进入相关文件夹进行测试
for dirname in ["binary"]: #
subdir=pwd+os.sep+dirname
os.chdir(subdir)
pwd=os.getcwd()
print('pwd=',pwd)
print(os.listdir())
subprocess.run(["makeexefile.bat"])
#返回上级目录
os.chdir(os.pardir)
pwd=os.getcwd()
print('pwd=',pwd)
#主目录文档编译
jobname="bibmap"
subprocess.run(["xelatex","-no-pdf",jobname],check=True)
subprocess.run(["xelatex","--synctex=-1",jobname],check=True)
#删除相关文件
dirlst=os.listdir()
subdirlst=[]
for elem in dirlst:
#print('elem=',elem)
if os.path.isdir(elem) and elem != ".git" and elem not in ["bibfiles","binary",'__pycache__']:
subdir=pwd+os.sep+elem
os.chdir(subdir)
pwd=os.getcwd()
print('pwd=',pwd)
subprocess.run(["makeclear.bat"])
os.chdir(os.pardir)
pwd=os.getcwd()
print('pwd=',pwd)
print("test all ended!")
if __name__ == '__main__':
compileall()
#compileall('all')
#compileall('compare')