运用Python运行cocos2dx-lua/js项目
来源:互联网 发布:程序员的自我修养图片 编辑:程序博客网 时间:2024/05/24 07:28
之前写了个篇博文运用Sublime Text开发cocos2dx-lua项目的lua部分,其中的运行命令是这么做的
{ "working_dir": "${project_path:${folder}}", "shell_cmd": "${folder}/simulator/win32/game1.exe -workdir ${folder}" }
这个buildSystem有缺陷:${folder}可能会指向其他工程目录,模拟器game1.exe文件不知道该怎么动态表达, 新的项目必须要修改它; 所以就想做个一劳永逸的build system.
python脚本就很适合啦。
{"working_dir": "${project_path:${folder}","shell_cmd": "D:\\soft\\python2.7_32\\python.exe D:\\soft\\cocos\\workspace\\luapro_run.py ${file}"}
运行luapro_run.py脚本, 参数传入项目中的lua文件 ${file}
# -*- coding: UTF-8 -*-# coding=UTF-8import sysimport stringimport osprint("这个命令是用来跑cocos2dx-lua项目的")reverXieGang = "\\"xieGang = "/"def formatDir(str):str = str.replace(reverXieGang, xieGang)if str[len(str) - 1] == '/':return str[0:len(str)-1]return strdef getParentDir(str):index = str.rfind(xieGang,0, len(str))if index > -1:ret = str[0:index]return retreturn strdef getLastDir(str):index = str.rfind(xieGang,0, len(str))if index > -1:return str[index + 1: len(str)]return strdef getProjectInfo(luaFilePath):luaFilePath = formatDir(luaFilePath)#print "入口文件为", luaFilePathparentDir = getParentDir(luaFilePath)#print "父目录为", parentDirlastDir = getLastDir(luaFilePath)#print "当前目录名为", lastDirwhile lastDir != "src":luaFilePath = parentDirparentDir = getParentDir(luaFilePath)lastDir = getLastDir(luaFilePath)luaFilePath = parentDirparentDir = getParentDir(luaFilePath)lastDir = getLastDir(luaFilePath)projectName = lastDir#print "当前工程名为:", projectNamereturn (parentDir, projectName)def startFuc():argsLen = len(sys.argv)if argsLen < 2:print "参数错误, 要加入要当前项目的lua文件路径"else:luaFilePath = sys.argv[1]print "入口文件为", luaFilePath(projectParentDir, projectName) = getProjectInfo(luaFilePath)#print "当前工程名为:", projectName#print "工程父目录为", projectParentDir#模拟器路径projectDir = projectParentDir + xieGang + projectNamesimFilePath = projectDir + xieGang + "simulator/win32/" + projectName+".exe -workdir " + projectDirprint "模拟器路径为", simFilePathos.system(simFilePath)#-workdir ${folder}#main方法if __name__ == "__main__":startFuc()
{"working_dir": "${project_path:${folder}}","shell_cmd": "D:\\soft\\python2.7_32\\python.exe D:\\soft\\cocos\\workspace\\cocosJS_pro_run.py ${file}"}
cocosJS_pro_run.py
# -*- coding: UTF-8 -*-# coding=UTF-8import sysimport stringimport osimport reimport shutilprint("这个命令是用来跑cocos2dx-js项目的")reverXieGang = "\\"xieGang = "/"def formatDir(str):str = str.replace(reverXieGang, xieGang)if str[len(str) - 1] == '/':return str[0:len(str)-1]return strdef getParentDir(str):index = str.rfind(xieGang,0, len(str))if index > -1:ret = str[0:index]return retreturn strdef getLastDir(str):index = str.rfind(xieGang,0, len(str))if index > -1:return str[index + 1: len(str)]return strdef getProjectInfo(luaFilePath):luaFilePath = formatDir(luaFilePath)#print "入口文件为", luaFilePathparentDir = getParentDir(luaFilePath)#print "父目录为", parentDirlastDir = getLastDir(luaFilePath)#print "当前目录名为", lastDirisFoundPro = 1while lastDir != "src":luaFilePath = parentDirparentDir = getParentDir(luaFilePath)lastDir = getLastDir(luaFilePath)if parentDir == luaFilePath:isFoundPro = 0breakif isFoundPro == 0:return 0, 0luaFilePath = parentDirparentDir = getParentDir(luaFilePath)lastDir = getLastDir(luaFilePath)projectName = lastDir#print "当前工程名为:", projectNamereturn (parentDir, projectName)def myCpFile(filePath, destDir):fileName = getLastDir(filePath)destDir = formatDir(destDir)destFile = destDir + xieGang + fileName#print "复制文件%s到%s" % (filePath, destFile)shutil.copyfile(filePath, destFile)return#复制文件def cpFilesByRegrex(path, fileRegrex, flag, destDir):for dirpath,dirnames,filenames in os.walk(path): for file in filenames: if dirpath == path: if re.match(fileRegrex, file, flag): myCpFile(dirpath + xieGang + file, destDir) else: returndef cpFilesByName(dirPath, fileName, distDir):myCpFile(dirPath + xieGang + fileName, distDir)def findDir(path, dirName):for dirpath,dirnames,filenames in os.walk(path): for d in dirnames: if d == dirName: return 1return 0#根据正则匹配取得目录或文件名称def getDirOrFileNameByRegrex(dirPath, regrex, flag):for dirpath,dirnames,filenames in os.walk(dirPath): if dirpath == dirPath: for dirName in dirnames: if re.match(regrex, dirName, flag): return dirName for fileName in filenames: if re.match(regrex, fileName, flag): return fileName else: return "" #拷贝目录def cpDir(dirPath, destDir):#print "复制目录%s到%s" % (dirPath, destDir)dirName = getLastDir(dirPath)if os.path.exists(destDir + xieGang + dirName) == False:os.chdir(destDir)#print "创建目录", dirNameos.mkdir(dirName)for dirpath,dirnames,filenames in os.walk(dirPath):if dirpath == dirPath: for file in filenames: cpFilesByName(dirPath, file, destDir + xieGang + dirName) for subDir in dirnames: #print "子目录名:", subDir cpDir(dirpath + xieGang + subDir, destDir + xieGang + dirName)def startFuc():argsLen = len(sys.argv)if argsLen < 2:print "参数错误, 要加入要当前项目的lua文件路径"else:luaFilePath = sys.argv[1]print "入口文件为", luaFilePath(projectParentDir, projectName) = getProjectInfo(luaFilePath)if projectParentDir == 0 :luaFilePath = formatDir(luaFilePath)if findDir(".", "src"):print "当前目录就是工程目录"curDir = getParentDir(luaFilePath)projectParentDir = getParentDir(curDir)projectName = getLastDir(curDir)else:print "未找到工程目录."return#print "当前工程名为:", projectName#print "工程父目录为", projectParentDir#模拟器路径projectDir = projectParentDir + xieGang + projectNametargetDir = projectDir + xieGang +"frameworks/runtime-src/proj.win32/Debug.win32"cpFilesByRegrex(projectDir, r'.*[.]js$', 0, targetDir)cpFilesByRegrex(projectDir, r'.*[.]json$',0, targetDir)cpDir(projectDir + xieGang + "src", targetDir)#取得exe文件名称exeFileName = getDirOrFileNameByRegrex(targetDir, r'.*[.]exe$', 0)if exeFileName == "":print "还没有生成exe文件,请重新编译工程,或者切换编译版本..."returnshellCmd = targetDir + xieGang + exeFileNameprint "命令行:", shellCmdos.system(shellCmd)#-workdir ${folder}#main方法if __name__ == "__main__":startFuc()
呵呵,不再老是打开庞大的VS2013编译项目啦,感觉写python脚本挺爽的!
阅读全文
0 0
- 运用Python运行cocos2dx-lua/js项目
- 运用Sublime Text开发cocos2dx-lua项目的lua部分
- cocos2dx-lua 示例运行
- cocos2dx-3.11 使用创建Lua项目以及运行自定义场景
- cocos2dx-3.0建立lua项目
- cocos2dx+lua编译Android项目
- sublime运行quick-cocos2dx-lua 步骤详情
- cocos2dx python项目创建
- cocos2dx python项目创建
- Python创建cocos2dx项目
- cocos2dx lua项目学习一 创建lua项目
- cocos2dx-lua项目的构建、编译细则
- cocos2dx Lua项目中添加Sqlite
- cocos2dx 3.2之Lua打飞机项目
- 新建cocos2dx-lua项目 和 HelloLua分析
- cocos2dx 创建lua项目 scheduler使用
- cocos2dx lua项目加入控制台输出打印
- cocos2dx之lua项目开发中MVC
- B
- GDB 基础调试总结
- Eclipse 如何配置 Tomcat
- C++调用WinSock api实现UDP传输
- 5、js基础:原型对象
- 运用Python运行cocos2dx-lua/js项目
- get与post根本区别以及乱码的处理
- hdu 1058 Humble Numbers 水题
- 自己整理的常用字符串校验和日期格式化工具类
- 排序汇总
- 数据挖掘之从数据中学习
- 第一个python程序
- LINUX学习日记(0)--虚拟机安装redhat7
- Chrome学习笔记(三):UI组件,皮肤引擎 —— 控件库