python之生成Qt pro文件
2015-11-19 00:26
591 查看
##genQtPro.py
@@生成Qt的pro文件
topro CmdWifi
生成CmdWif.pro
import os,sys,re import shutil,string # [OK] # global var for app # calc the baseLen, we should add the divator char '/' or '\' gBaseLen = len(os.getcwd()) + 1 gSrcList = "SOURCES += \\" + "\n" gHeadList = "HEADERS += \\" + "\n" gUiList = "FORMS += \\" + "\n" gTarget = "Test" argLen = len(sys.argv) if argLen >= 2: gTarget = sys.argv[1] if gTarget.find('.') != -1: gTarget = gTarget.split('.',1)[0] ################################################################################################### # define the blakc list,which we ignore (dirname) [OK] ################################################################################################### bUseWhite = False gRangeList = ["debug"] ################################################################################################### # Judge one file can be accessed through the black or white list. [OK] ################################################################################################### def canAcessFile(file): global bUseWhite,gRangeList bInRange = (file in gRangeList) return (bUseWhite and bInRange ) or (not bUseWhite and not bInRange) ################################################################################################### # walk the dirname, # if type is file,then call pFunc to process it. # if type is dir,then recurse to walk the dir. [OK] ################################################################################################### def getList(dirname,pFunc): try: ls=os.listdir(dirname) except: print dirname,'is access deny' else: for file in ls: temp = os.path.join(dirname,file) if(os.path.isdir(temp)): if canAcessFile(file): getList(temp,pFunc) else: pFunc(dirname,file) ################################################################################################### # define the blakc list,which we ignore (dirname) ################################################################################################### def convertDivChar(path): return path.replace('\\','/') ################################################################################################### # this function is used to process the certain file && dirname. [OK] ################################################################################################### def printFile(dirname,file): global gSrcList,gHeadList,gUiList newPath = "" if len(dirname) == gBaseLen: newPath = file else: newPath = dirname[gBaseLen:] + "/" + file #filter if newPath[0] == '/': newPath = newPath[1:] newPath = convertDivChar(newPath) if re.search("\.h$",newPath): gHeadList = gHeadList + "\t" + newPath + " \\" + "\n" if re.search("\.hpp$",newPath): gHeadList = gHeadList + "\t" + newPath + " \\" + "\n" if re.search("\.cpp$",newPath): gSrcList = gSrcList + "\t" + newPath + " \\" + "\n" if re.search("\.c$",newPath): gSrcList = gSrcList + "\t" + newPath + " \\" + "\n" if re.search("\.ui$",newPath): gUiList = gUiList + "\t" + newPath + " \\" + "\n" ################################################################################################### # write string to file. [OK] ################################################################################################### def writeToFile(str,fname): fp = open(fname,"w") fp.write(str) fp.close() ################################################################################################### # read content from fname. ################################################################################################### def readFile(fname): with open(fname, 'r') as f: return f.read() ################################################################################################### # generate the pro body. ################################################################################################### def getBasicHead(): ret = "#hand-generate-code" ret = "%s\n%s" % (ret,"QT += core gui") ret = "%s\nTARGET = %s" % (ret,gTarget) ret = "%s\n%s" % (ret,"TEMPLATE = app") ret = "%s\n%s" % (ret,"") ret = "%s\n%s" % (ret,"#LIBS += -L/usr/lib/mysql -lmysqlclient") ret = "%s\n%s" % (ret,"#INCLUDEPATH += /usr/include/mysql\n\n") return ret ################################################################################################### # generate the pro body. ################################################################################################### gKeyword = "#auto-generate-code#" getList(os.getcwd(),printFile) gContent = "" gFname = "%s.pro" % (gTarget) if os.path.exists(gFname): print "Update" cnt = readFile(gFname) pos = cnt.find(gKeyword) gContent = cnt[0:pos] else: print "Create" gContent = getBasicHead() fOutCnt = "%s%s\n\n%s\n%s\n%s" % (gContent ,gKeyword ,gHeadList ,gSrcList ,gUiList) writeToFile(fOutCnt ,gFname)
@@生成Qt的pro文件
topro CmdWifi
生成CmdWif.pro
相关文章推荐
- python之扫描本地信息到Solr服务
- python之自动生成table网页(行列可指定)
- python之读取Excel数据
- 使用PyCharm配合部署Python的Django框架的配置纪实
- Qpython
- 利用Psyco让Python程序执行更快
- Python IDLE快捷键一览
- Python List+Tuple+Dict+Set小结
- python之自定义爬虫脚本
- python之自动生成图像列表
- python之自动化生成解析ini文件的Qt类
- python之定时执行截屏
- Python 学习LINK
- leetcode Roman to Integer python
- python之生成文件列表(链接方式)
- python之批量重命名目录文件
- 练习PYTHON之EPOLL
- python之转换源码后缀名为txt后缀名
- python urllib模块
- leetcode Integer to Roman python