Skip to content

Commit 8d02e9c

Browse files
committed
build: compile-pyc
1 parent 1113e1f commit 8d02e9c

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

installer/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ RUN chmod 755 /opt/maxkb/app/installer/run-maxkb.sh && \
6767
useradd --no-create-home --home /opt/maxkb/app/sandbox sandbox -g root && \
6868
chown -R sandbox:root /opt/maxkb/app/sandbox && \
6969
chmod g-x /usr/local/bin/* /usr/bin/* /bin/* /usr/sbin/* /sbin/* /usr/lib/postgresql/15/bin/* && \
70-
chmod g+x /usr/local/bin/python* /bin/sh
70+
chmod g+x /usr/local/bin/python* /bin/sh && \
71+
python3 /opt/maxkb/app/installer/compile.py
7172

7273
EXPOSE 8080
7374

installer/compile.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# coding=utf-8
2+
"""
3+
@project: MaxKB
4+
@Author:虎
5+
@file: compile.py
6+
@date:2024/12/23 14:11
7+
@desc:
8+
"""
9+
import os
10+
from py_compile import compile
11+
12+
13+
def compile_pyc(path_str: str):
14+
"""
15+
将py编译为pyc文件
16+
@param path_str: 需要编译的目录
17+
@return: None
18+
"""
19+
for parent, dir_name, filename in os.walk(path_str):
20+
for cfile in filename:
21+
fullname = os.path.join(parent, cfile)
22+
if cfile[-3:] == '.py':
23+
try:
24+
if compile(fullname, fullname.replace('py', 'pyc')):
25+
if cfile != 'settings.py' and cfile != 'wsgi.py':
26+
os.remove(fullname) # 删除原文件,保留settings.py和wsgi.py
27+
print("Success compile and remove file:%s" % fullname)
28+
else:
29+
print("Can't compile file:%s,The original file has been retained" % fullname)
30+
except Exception as e:
31+
print("Can't compile file:%s, reason:%s" % (fullname, e))
32+
33+
34+
if __name__ == '__main__':
35+
compile_pyc("../apps")

0 commit comments

Comments
 (0)