-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1113e1f
commit 8d02e9c
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |