From c2cd349da5dfdea8a5138566d0655b481de609eb Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 6 Mar 2014 14:56:22 +0800 Subject: [PATCH] Uses 'generate-tempate-files.py' to generate cocos2dx_files.json --- tools/travis-scripts/config.gitingore | 112 +++++++++++++ tools/travis-scripts/generate-cocosfiles.sh | 3 +- .../travis-scripts/generate-template-files.py | 149 ++++++++++++++++++ 3 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 tools/travis-scripts/config.gitingore create mode 100755 tools/travis-scripts/generate-template-files.py diff --git a/tools/travis-scripts/config.gitingore b/tools/travis-scripts/config.gitingore new file mode 100644 index 0000000000..e16be3535a --- /dev/null +++ b/tools/travis-scripts/config.gitingore @@ -0,0 +1,112 @@ +#This configure file use .gitingore rules. +#So you can config this file like config .gitingore +# + +# Ignore thumbnails created by windows +Thumbs.db +.git + +# ignore copy files +/lib +/linux-build +/samples +/templates +/tests +/plugin/samples +/tools + +.gitattributes +.gitignore +.gitmodules +.travis.yml +setup.py + +# Ignore files build by Visual Studio +win32-msvc-vs201*-x86 +*.obj +*.exe +*.pdb +*.aps +*.vcproj.*.user +*.vspscc +*_i.c +*.i +*.icf +*_p.c +*.ncb +*.suo +*.tlb +*.tlh +*.bak +*.cache +*.ilk +*.log +[Bb]in +[Dd]ebug/ +[Dd]ebug.win32/ +*.sbr +*.sdf +obj/ +[Rr]elease/ +[Rr]elease.win32/ +_ReSharper*/ +[Tt]est[Rr]esult* +ipch/ +*.opensdf + +# Ignore files build by ndk and eclipse +libs/ +bin/ +obj/ +gen/ +assets/ +local.properties + +# Ignore python compiled files +*.pyc + +# Ignore files build by airplay and marmalade +build_*_xcode/ +build_*_vc10/ + +# Ignore files build by xcode +*.mode*v* +*.pbxuser +*.xcbkptlist +*.xcscheme +*.xcworkspacedata +*.xcuserstate +*.xccheckout +xcschememanagement.plist +.DS_Store +._.* +xcuserdata/ +DerivedData/ + +# Ignore files built by AppCode +.idea/ + +# Ignore files built by bada +.Simulator-Debug/ +.Target-Debug/ +.Target-Release/ + +# Ignore files built by blackberry +Simulator/ +Device-Debug/ +Device-Release/ + +# Ignore vim swaps +*.swp +*.swo + +# Ignore files created by create_project.py +/projects + +# CTags +tags + +#include +!/tools/cocos2d-console/console/bin/ +!/plugin-x/plugin-x_ios.xcworkspace/ + diff --git a/tools/travis-scripts/generate-cocosfiles.sh b/tools/travis-scripts/generate-cocosfiles.sh index 55869cac59..1014bc303e 100755 --- a/tools/travis-scripts/generate-cocosfiles.sh +++ b/tools/travis-scripts/generate-cocosfiles.sh @@ -7,14 +7,13 @@ COMMITTAG="[AUTO][ci skip]: updating cocos2dx_files.json" PUSH_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls" OUTPUT_FILE_PATH="${PROJECT_ROOT}/templates/cocos2dx_files.json" - # Exit on error set -e generate_cocosfiles_json() { echo "Updates cocos_files.json" - ./for-each-file-in-dir.sh > "${OUTPUT_FILE_PATH}" + ./generate-template-files.py } if [ "$GEN_COCOS_FILES"x != "YES"x ]; then diff --git a/tools/travis-scripts/generate-template-files.py b/tools/travis-scripts/generate-template-files.py new file mode 100755 index 0000000000..ee974866be --- /dev/null +++ b/tools/travis-scripts/generate-template-files.py @@ -0,0 +1,149 @@ +#!/usr/bin/python +#coding=utf-8 +"""**************************************************************************** +Copyright (c) 2013 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************""" + +import os +import sys +import re + +class CocosFileList: + """ + Function: + List cocos engine's files and save to "../module/cocos_file_list.json". + config "config.gitingore" file can set exclude or include files. + """ + + def __init__(self): + self.excludeConfig=[] + self.inludeConfig=[] + self.rootDir = "" + self.fileList=[] + + def readIngoreFile(self, fileName): + """ + Read configure file which use ".gitingore"'s rules. + """ + pfile = "" + try: + pfile = open(fileName, 'r') + except IOError: + return + + for line in pfile: + line = line.strip() + if not line or line[0] == "#": + continue + + #convert .gitingore regular expression to python's regular expression + line=line.replace('.', '\\.') + line=line.replace('*', '.*') + line="%s$" %line + if line[0] == "!": + self.inludeConfig.append(line[1:]) + else: + self.excludeConfig.append(line) + pfile.close() + + def parseFileList(self, rootDir): + self.rootDir = os.path.abspath(rootDir) + self.__parseFileList(rootDir) + + def __parseFileList(self, folderdir): + """ + """ + for item in os.listdir(folderdir): + path = os.path.join(folderdir, item) + relativePath = path[len(self.rootDir)+1:len(path)] + relativePath = relativePath.replace('\\', '/') + if os.path.isdir(path): + if ( + self.__bInclude("/%s" %relativePath) or + self.__bInclude("/%s/" %relativePath) or + self.__bInclude(item) or + self.__bInclude("%s/" %item) + ): + self.fileList.append("%s/" %relativePath) + continue + if ( + self.__bExclude("/%s" %relativePath) or + self.__bExclude("/%s/" %relativePath) or + self.__bExclude(item) or + self.__bExclude("%s/" %item) + ): + continue + self.__parseFileList(path) + else: + if ( + not self.__bInclude("/%s" %relativePath) and + not self.__bInclude(item) + ): + if ( + self.__bExclude("/%s" %relativePath) or + self.__bExclude(item) + ): + continue + # print(relativePath) + self.fileList.append(relativePath) + + def __bExclude(self, item): + bexclude = False + for index in range(len(self.excludeConfig)): + if re.match(self.excludeConfig[index], item): + bexclude = True + break + return bexclude + + def __bInclude(self, item): + binclude = False + for index in range(len(self.inludeConfig)): + if re.match(self.inludeConfig[index], item): + binclude = True + break + return binclude + + def writeFileList(self,fileName): + """ + Save content to file with json format. + """ + f = open(fileName,"w") + self.fileList.sort() + content = "[\n\"%s\"\n]" % ("\",\n\"".join(self.fileList)) + f.write(content) + f.close() + return True + +# ------------ main -------------- +if __name__ == '__main__': + + cocos_root =os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) + cocos_file_path =os.path.abspath(os.path.join(cocos_root, "templates", "cocos2dx_files.json")) + cocos_file_ingore =os.path.abspath(os.path.join(os.path.dirname(__file__), "config.gitingore")) + # print ("begin list files") + cocosObj = CocosFileList() + cocosObj.readIngoreFile(cocos_file_ingore) + cocosObj.parseFileList(cocos_root) + cocosObj.writeFileList(cocos_file_path) + # print ("had list files to cocos_file_list.json") +