python将项目文件打包发布的脚本(保留原来的项目结构)

来源:互联网 发布:java项目开发案例经典 编辑:程序博客网 时间:2024/05/22 14:58
__author__ = 'wei'# -*- coding: utf-8 -*-__author__ = 'wei'import getoptimport sysimport osimport py_compiledef setparams():    global srcpath,pycpath    ps=getopt.getopt(sys.argv[1:], '', ['srcpath=', 'pycpath='])    psdict=dict(ps[0])    if '--srcpath' in psdict:        srcpath=psdict['--srcpath']    else:        srcpath=input('请输入源文件夹:')    if '--pycpath' in psdict:        pycpath=psdict['--pycpath']    else:        pycpath=input('请输入目标pyc文件夹:')if __name__=='__main__':    srcpath=''    pycpath=''    setparams()    print(srcpath)    for root,dirs,files in os.walk(srcpath):        for file in files:            if file[-3:]=='.py':                pyname=root+os.path.sep+file                pycname=pyname.replace(srcpath,pycpath)+'c'                pycdir=pycname.replace(file+'c', '')                if not os.path.exists(pycdir): #if not exist dir,create it                    os.mkdir(pycdir)                print(pyname,pycname)                py_compile.compile(pyname,cfile=pycname)

原创粉丝点击