Skip to content

Commit af06663

Browse files
author
黄佰荣
committed
window环境的构建脚本
1 parent 65589bb commit af06663

File tree

2 files changed

+46
-18
lines changed

2 files changed

+46
-18
lines changed

qpython-docs/add-analytics-windown.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import sys, os
2-
3-
with open(sys.argv[1], 'r', encoding='gbk') as f, \
4-
open('./qpydoc.tmp', 'w', encoding='gbk') as g, \
5-
open(os.path.dirname(os.path.abspath(__file__)) + '/extra.txt', 'r', encoding='gbk') as e:
1+
import sys,os
2+
with open(sys.argv[1], 'r') as f, open('./qpydoc.tmp', 'wb') as g, open(os.path.dirname(os.path.abspath(__file__))+'/extra.txt','r') as e:
63
pth = sys.argv[1][1:]
7-
extra = "".join(e.readlines()).replace("{{PTH}}", pth)
4+
extra = "".join(e.readlines()).replace("{{PTH}}",pth)
85
g.write('\n'.join(
96
filter(lambda s: len(s),
107
map(lambda s:
11-
('', extra + "<hr/>")[s == '<div role="contentinfo">'] + s,
8+
('',extra+"<hr/>")[s=='<div role="contentinfo">']+s,
129
map(str.strip, f.readlines())))))
13-
os.rename('./qpydoc.tmp', sys.argv[1])
10+
os.rename('./qpydoc.tmp', sys.argv[1])

qpython-docs/add-analytics.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
1-
import sys,os
2-
with open(sys.argv[1], 'r') as f, open('./qpydoc.tmp', 'wb') as g, open(os.path.dirname(os.path.abspath(__file__))+'/extra.txt','r') as e:
3-
pth = sys.argv[1][1:]
4-
extra = "".join(e.readlines()).replace("{{PTH}}",pth)
5-
g.write('\n'.join(
6-
filter(lambda s: len(s),
7-
map(lambda s:
8-
('',extra+"<hr/>")[s=='<div role="contentinfo">']+s,
9-
map(str.strip, f.readlines())))))
10-
os.rename('./qpydoc.tmp', sys.argv[1])
1+
import sys
2+
import os
3+
4+
def process_file(input_file, output_file, extra_file):
5+
# 确保 extra.txt 文件存在
6+
if not os.path.exists(extra_file):
7+
print(f"Error: The file '{extra_file}' does not exist.")
8+
return
9+
10+
# 获取 extra.txt 文件内容
11+
with open(extra_file, 'r', encoding='utf-8') as e:
12+
extra = e.read().replace("{{PTH}}", input_file[1:]) # 用路径替换 {{PTH}}
13+
14+
# 逐行读取输入文件并处理内容
15+
with open(input_file, 'r', encoding='utf-8') as f, open(output_file, 'w', encoding='utf-8') as g:
16+
for line in f:
17+
line = line.strip() # 去除行首和行尾空白字符
18+
if line: # 忽略空行
19+
# 如果是特定标签,添加 extra 和 <hr/> 内容
20+
if line == '<div role="contentinfo">':
21+
g.write(extra + "<hr/>\n")
22+
else:
23+
g.write(line + '\n') # 写入处理后的行
24+
25+
# 替换原始文件
26+
os.rename(output_file, input_file)
27+
28+
def main():
29+
if len(sys.argv) < 2:
30+
print("Usage: python script.py <input_file>")
31+
return
32+
33+
input_file = sys.argv[1]
34+
output_file = './qpydoc.tmp'
35+
extra_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'extra.txt')
36+
37+
# 处理文件
38+
process_file(input_file, output_file, extra_file)
39+
40+
if __name__ == '__main__':
41+
main()

0 commit comments

Comments
 (0)