Skip to content

Commit

Permalink
build: compile-pyc
Browse files Browse the repository at this point in the history
  • Loading branch information
shaohuzhang1 committed Dec 23, 2024
1 parent 1113e1f commit 8d02e9c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion installer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ RUN chmod 755 /opt/maxkb/app/installer/run-maxkb.sh && \
useradd --no-create-home --home /opt/maxkb/app/sandbox sandbox -g root && \
chown -R sandbox:root /opt/maxkb/app/sandbox && \
chmod g-x /usr/local/bin/* /usr/bin/* /bin/* /usr/sbin/* /sbin/* /usr/lib/postgresql/15/bin/* && \
chmod g+x /usr/local/bin/python* /bin/sh
chmod g+x /usr/local/bin/python* /bin/sh && \
python3 /opt/maxkb/app/installer/compile.py

EXPOSE 8080

Expand Down
35 changes: 35 additions & 0 deletions installer/compile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# coding=utf-8
"""
@project: MaxKB
@Author:虎
@file: compile.py
@date:2024/12/23 14:11
@desc:
"""
import os
from py_compile import compile


def compile_pyc(path_str: str):
"""
将py编译为pyc文件
@param path_str: 需要编译的目录
@return: None
"""
for parent, dir_name, filename in os.walk(path_str):
for cfile in filename:
fullname = os.path.join(parent, cfile)
if cfile[-3:] == '.py':
try:
if compile(fullname, fullname.replace('py', 'pyc')):
if cfile != 'settings.py' and cfile != 'wsgi.py':
os.remove(fullname) # 删除原文件,保留settings.py和wsgi.py
print("Success compile and remove file:%s" % fullname)
else:
print("Can't compile file:%s,The original file has been retained" % fullname)
except Exception as e:
print("Can't compile file:%s, reason:%s" % (fullname, e))


if __name__ == '__main__':
compile_pyc("../apps")

0 comments on commit 8d02e9c

Please sign in to comment.