From 8915b4787d6fa407909213c3580b8e293ff9f830 Mon Sep 17 00:00:00 2001 From: walzer Date: Wed, 20 Feb 2013 13:26:41 +0800 Subject: [PATCH] fixed #1733, the python script perfectly works, tested on both osx and windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This pull request fixed: - Handling the difference of line ending between osx and windows - remove os.popen("rm -rf" + …) usage which can not cross desktop platforms, uses shutil.rmtree instead --- tools/project-creator/create_project.py | 2 +- .../creator_android/handle_project_files.py | 16 +++++++++++----- .../creator_ios/handle_project_files.py | 13 +++++++++---- .../creator_win32/handle_project_files.py | 3 +++ tools/project-creator/replaces.py | 4 ++-- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/tools/project-creator/create_project.py b/tools/project-creator/create_project.py index 9ec3c9d1cd..8833dd6240 100755 --- a/tools/project-creator/create_project.py +++ b/tools/project-creator/create_project.py @@ -108,6 +108,6 @@ for platform in platforms_list: exec "import creator_%s.handle_project_files" % (platform) exec "creator_%s.handle_project_files.handle_project_files(context)" % (platform) -print "New project has been created in this path: " + context["dst_project_path"] +print "New project has been created in this path: " + context["dst_project_path"].replace("/tools/project-creator/../..", "") print "Have Fun!" diff --git a/tools/project-creator/creator_android/handle_project_files.py b/tools/project-creator/creator_android/handle_project_files.py index 7ae1765794..162545325d 100755 --- a/tools/project-creator/creator_android/handle_project_files.py +++ b/tools/project-creator/creator_android/handle_project_files.py @@ -6,6 +6,7 @@ # Android import os +import shutil def handle_project_files(context): # determine proj_path @@ -34,12 +35,17 @@ def handle_project_files(context): dst_java_file_path = proj_path + "src/" + dst_pkg[0] + "/" + dst_pkg[1] + "/" + dst_pkg[2] + "/" + context["dst_project_name"] + ".java" - # remove useless files. - os.popen("rm -rf " + proj_path + "assets") - os.popen("rm -rf " + proj_path + "bin") - os.popen("rm -rf " + proj_path + "gen") - os.popen("rm -rf " + proj_path + "obj") + removes = [ + "assets", + "bin", + "libs", + "gen", + "obj", + ] + for i in range(0, len(removes)): + if (os.path.exists(proj_path + removes[i]) == True): + shutil.rmtree(proj_path + removes[i]) # replaceString function is implemented in ../create-project.py import replaces diff --git a/tools/project-creator/creator_ios/handle_project_files.py b/tools/project-creator/creator_ios/handle_project_files.py index f07c1614a2..ddc0271308 100755 --- a/tools/project-creator/creator_ios/handle_project_files.py +++ b/tools/project-creator/creator_ios/handle_project_files.py @@ -6,6 +6,7 @@ # iOS import os +import shutil def handle_project_files(context): # determine proj_path @@ -24,10 +25,14 @@ def handle_project_files(context): proj_path + context["dst_project_name"] + ".xcodeproj" ) # remove useless files. - os.popen("rm -rf " + proj_path + context["dst_project_name"] + ".xcodeproj/project.xcworkspace") - os.popen("rm -rf " + proj_path + context["dst_project_name"] + ".xcodeproj/xcuserdata" ) - os.popen("rm -rf " + proj_path + "build" ) - + removes = [ + context["dst_project_name"] + ".xcodeproj/project.xcworkspace", + context["dst_project_name"] + ".xcodeproj/xcuserdata", + ] + for i in range(0, len(removes)): + if (os.path.exists(proj_path + removes[i]) == True): + shutil.rmtree(proj_path + removes[i]) + # replaceString function is implemented in ../create-project.py import replaces # package_name should be replaced at first. Don't change this sequence diff --git a/tools/project-creator/creator_win32/handle_project_files.py b/tools/project-creator/creator_win32/handle_project_files.py index c834f04c92..9aade7b5ad 100755 --- a/tools/project-creator/creator_win32/handle_project_files.py +++ b/tools/project-creator/creator_win32/handle_project_files.py @@ -18,6 +18,8 @@ def handle_project_files(context): proj_path + context["dst_project_name"] + ".vcxproj.filters") os.rename(proj_path + context["src_project_name"] + ".vcxproj.user", proj_path + context["dst_project_name"] + ".vcxproj.user") + os.rename(proj_path + context["src_project_name"] + ".sln", + proj_path + context["dst_project_name"] + ".sln") # replaceString function is implemented in ../create-project.py import replaces @@ -25,6 +27,7 @@ def handle_project_files(context): replaces.replaceString(proj_path + context["dst_project_name"] + ".vcxproj", context["src_project_name"], context["dst_project_name"]) replaces.replaceString(proj_path + context["dst_project_name"] + ".vcxproj.filters", context["src_project_name"], context["dst_project_name"]) replaces.replaceString(proj_path + context["dst_project_name"] + ".vcxproj.user", context["src_project_name"], context["dst_project_name"]) + replaces.replaceString(proj_path + context["dst_project_name"] + ".sln", context["src_project_name"], context["dst_project_name"]) replaces.replaceString(proj_path + "main.cpp", context["src_project_name"], context["dst_project_name"]) # done! print "proj.win32 : Done!" diff --git a/tools/project-creator/replaces.py b/tools/project-creator/replaces.py index 1975dc5041..b86ef16fa2 100755 --- a/tools/project-creator/replaces.py +++ b/tools/project-creator/replaces.py @@ -5,14 +5,14 @@ def replaceString(filepath, src_string, dst_string): content = "" - f1 = open(filepath, "r") + f1 = open(filepath, "rb") for line in f1: if src_string in line: content += line.replace(src_string, dst_string) else: content += line f1.close() - f2 = open(filepath, "w") + f2 = open(filepath, "wb") f2.write(content) f2.close() # end of replaceString(filepath, src, dst) function