This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Manaual.py
167 lines (143 loc) · 5.34 KB
/
Manaual.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
# coding=utf-8
import os
import json
TexHead = r"""
\documentclass[twoside]{article}
\usepackage[colorlinks,linkcolor=black]{hyperref}
\usepackage{xeCJK,xunicode}
\usepackage{fancyhdr}
\usepackage{amsmath,amsthm}
\usepackage{listings,xcolor}
\usepackage{geometry}
\usepackage{fontspec}
\setCJKmainfont[BoldFont=STYuanti-SC-Regular,ItalicFont=STYuanti-SC-Regular]{STYuanti-SC-Regular}
\setCJKmonofont[BoldFont=STYuanti-SC-Regular]{STYuanti-SC-Regular}
\setCJKsansfont{STYuanti-SC-Regular}
\setsansfont{Monaco}
\setmonofont[Mapping={}]{Monaco}
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\geometry{left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm}
\lstset{
language = c++,
breaklines = true,
captionpos = b,
tabsize = 4,
numbers = left,
columns = fullflexible,
keepspaces = true,
commentstyle = \color[RGB]{0,128,0},
keywordstyle = \color[RGB]{0,0,255},
basicstyle = \small\ttfamily,
rulesepcolor = \color{red!20!green!20!blue!20},
showstringspaces = false,
}
"""
def InitSetting():
try:
with open('setting.json', 'r', encoding='utf-8') as f:
SettingData = json.load(f)
print(u'读取到保存的设置: ')
for key in SettingData:
print('[%s] %s' % (key, SettingData[key]))
op = input('是否使用已保存的设置?[Y/n]')
if op not in ['n', 'N', 'no', 'No', 'NO']:
global TITLE, SCHOOL, TEAM, FILE
for key in ['TITLE', 'SCHOOL', 'TEAM', 'FILE']:
globals()[key] = SettingData[key].encode('utf-8')
print(globals()['FILE'])
else:
NewSetting()
except:
print(u'读取设置失败')
NewSetting()
def NewSetting():
global TITLE, SCHOOL, TEAM, FILE
TITLE = input('请输入标题: ')
SCHOOL = input('请输入学校: ')
TEAM = input('请输入队名: ')
FILE = input('请输入文件名: ')
Data = dict()
for key in ['TITLE', 'SCHOOL', 'TEAM', 'FILE']:
Data[key] = globals()[key]
json.dump(Data, open('setting.json', 'w'), ensure_ascii=False, sort_keys=True, indent=4)
def Clear():
for suffix in ['aux', 'log', 'toc', 'out']:
filename = '%s.%s' % (FILE, suffix)
if os.path.exists(filename):
os.remove(filename)
def Generate():
Clear()
os.system('xelatex %s.tex' % FILE)
os.system('xelatex %s.tex' % FILE)
Clear()
os.system('open %s.pdf' % FILE)
def ReadCpp(file):
f = open(file, 'r')
Tex = 0
TargetFile.write('\\begin{lstlisting}\n')
for line in f:
if line[:-1] == '// ---':
Tex = not Tex
ToWrite = '\\%s{lstlisting}\n' % ('begin', 'end')[Tex]
TargetFile.write(ToWrite)
continue
TargetFile.write(line[(0, 3)[Tex]:])
TargetFile.write('\\end{lstlisting}\n')
f.close()
def ReadTex(file):
f = open(file, 'r')
for line in f:
TargetFile.write(line)
f.close()
def Search(level, pwd, folder=''):
ls = os.popen('ls "%s"| grep [0-9]_' % pwd).read().split('\n')[:-1]
if folder:
TargetFile.write(SECTION[level] % folder[3:])
for item in ls:
item.replace(' ', '\\ ')
if '.cpp' in item:
if not item[:2] == '00':
TargetFile.write(SECTION[level + 1] % item[3:-4])
ReadCpp(pwd + item)
elif '.tex' in item:
if not item[:2] == '00':
TargetFile.write(SECTION[level + 1] % item[3:-4])
ReadTex(pwd + item)
else:
cd = os.popen('cd "%s%s/"' % (pwd, item)).read()
if 'Not a directory' in cd or 'No such file or directory' in cd:
print('[Unknown File] %s/%s' % (pwd, item))
else:
Search(level + 1, pwd + item + '/', item)
if __name__ == '__main__':
# 全局设置
TITLE, SCHOOL, TEAM, FILE = '', '', '', ''
SECTION = ['', '\\clearpage\\section{%s}\n',
'\\subsection{%s}\n', '\\subsubsection{%s}\n']
InitSetting()
print(FILE)
TargetFile = open('%s.tex' % FILE, 'w')
# Output Head File
TargetFile.write(TexHead)
TargetFile.write('\\title{%s}\n' % TITLE)
TargetFile.write('\\author{%s}\n' % TEAM)
TargetFile.write('\\pagestyle{fancy}\n\\fancyhf{}\n\\fancyhead[C]{%s, %s}\n' % (TITLE, TEAM))
TargetFile.write('\\begin{document}\\small\n')
TargetFile.write(
'\\begin{titlepage}\n\\begin{center}\n\\vspace*{0.5cm}\\includegraphics[width=0.75\\textwidth]{logo.jpg} \\\\ [2cm]\n')
TargetFile.write('\\HRule \\\\ [1cm]\n')
TargetFile.write('\\textbf{\\Huge{%s}} \\\\ [0.5cm]\n' % TITLE)
TargetFile.write('\\HRule \\\\ [4cm]\n')
TargetFile.write('\\textbf{\\Huge{%s}} \\\\ [1cm]\n\\LARGE{%s}\n' % (SCHOOL, TEAM))
TargetFile.write('\\vfill\n\\Large{\\today}\n\\end{center}\n')
TargetFile.write('\\clearpage\n\end{titlepage}\n')
TargetFile.write('\\tableofcontents\\clearpage\n')
TargetFile.write('\\pagestyle{fancy}\n\\lfoot{}\n\\cfoot{\\thepage}\\rfoot{}\n')
TargetFile.write('\\setcounter{section}{-1}\n\\setcounter{page}{1}\n')
# Search Files
Search(0, './')
# End Output
TargetFile.write('\n\\end{document}\n')
TargetFile.close()
# Gen
Generate()