python之生成Qt pro文件
来源:互联网 发布:中国鉴藏 数据 编辑:程序博客网 时间:2024/05/19 19:57
##genQtPro.py
import os,sys,reimport shutil,string#[OK]#global var for app#calc the baseLen, we should add the divator char '/' or '\'gBaseLen = len(os.getcwd()) + 1gSrcList = "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 = FalsegRangeList = ["debug"]#################################################################################################### Judge one file can be accessed through the black or white list. [OK]###################################################################################################def canAcessFile(file):global bUseWhite,gRangeListbInRange = (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,gUiListnewPath = ""if len(dirname) == gBaseLen:newPath = fileelse:newPath = dirname[gBaseLen:] + "/" + file#filterif 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
0 0
- python之生成Qt pro文件
- Qt-Pro文件的生成
- QT 运行QMake生成Pro项目文件
- QT 之 .pro 文件配置解析
- python之自动化生成解析ini文件的Qt类
- qmake生成的pro文件中QT变量的说明
- 嵌入式Qt程序开发无法生成.pro文件
- qmake生成的pro文件中QT变量的说明
- QT的qmake 通过pro文件生成vs工程
- Qt生成动/静态链接库的*.pro文件设置
- QT 开源项目由源码生成Pro项目文件
- qt pro文件
- Qt中的.pro文件
- Qt .pro文件 详解
- Qt .pro文件 详解
- Qt .pro文件解析
- Qt .pro文件 详解
- Qt pro文件使用
- Linux__ssh服务开启_me
- 数据案例-SAP为何转向HANA云计算?
- ID3
- 浅谈分布式计算的开发与实现(2)
- php文件锁
- python之生成Qt pro文件
- Android Studio | 一个优雅的安卓开发环境
- Quartz使用-入门使用(java定时任务实现)
- php文件锁
- Android 4.4从图库选择图片,获取图片路径并裁剪
- JSTL标签详解
- 2015年11月广师android群内容分享
- python之生成文件/目录的md5值
- FileMode文件模式