compile.py
1.2 KB
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
# coding=utf-8
#author: 4N
#createtime: 2022/2/28
#email: nheweijun@sina.com
import py_compile
import os
import shutil
def compile(des):
project_dir = os.path.dirname(os.path.realpath(__file__))
if os.path.normpath(project_dir) == os.path.normpath(des):
raise Exception("目标目录不能与代码目录一样!")
if os.path.exists(des):
os.system("rd/s/q {}".format(des))
shutil.rmtree(des, True)
shutil.copytree(project_dir, des)
git_path = os.path.join(des,".git")
if os.path.exists(os.path.join(des,".git")):
os.system("rd/s/q {}".format(git_path))
for root, dirs, files in os.walk(os.path.join(des,"app")):
for fn in files:
if fn.endswith("py"):
py_file = os.path.join(root, fn)
py_compile.compile(py_file)
os.remove(py_file)
pyc_file = os.path.join(root, "__pycache__",fn.split(".")[0]+".cpython-37.pyc")
des_pyc_file = os.path.join(root,fn.split(".")[0]+".pyc")
shutil.copy(pyc_file,des_pyc_file)
if __name__ == '__main__':
des="H:\DMapManager"
compile(des)