compile.py
1.1 KB
# coding=utf-8
#author: 4N
#createtime: 2022/2/28
#email: nheweijun@sina.com
import py_compile
import os
import shutil
def compile(des):
if os.path.exists(des):
os.system("rd/s/q {}".format(des))
shutil.rmtree(des, True)
project_dir = os.path.dirname(os.path.realpath(__file__))
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="F:\Python\DMapManagerPublish"
compile(des)