pythonプロジェクトファイルをパブリッシュしたスクリプトにパッケージ化(元のプロジェクト構造を保持)
1216 ワード
__author__ = 'wei'
# -*- coding: utf-8 -*-
__author__ = 'wei'
import getopt
import sys
import os
import py_compile
def 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)