fixed #1733, the python script perfectly works, tested on both osx and windows

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
This commit is contained in:
walzer 2013-02-20 13:26:41 +08:00
parent d119d3686e
commit 8915b4787d
5 changed files with 26 additions and 12 deletions

View File

@ -108,6 +108,6 @@ for platform in platforms_list:
exec "import creator_%s.handle_project_files" % (platform) exec "import creator_%s.handle_project_files" % (platform)
exec "creator_%s.handle_project_files.handle_project_files(context)" % (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!" print "Have Fun!"

View File

@ -6,6 +6,7 @@
# Android # Android
import os import os
import shutil
def handle_project_files(context): def handle_project_files(context):
# determine proj_path # 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" dst_java_file_path = proj_path + "src/" + dst_pkg[0] + "/" + dst_pkg[1] + "/" + dst_pkg[2] + "/" + context["dst_project_name"] + ".java"
# remove useless files. # remove useless files.
os.popen("rm -rf " + proj_path + "assets") removes = [
os.popen("rm -rf " + proj_path + "bin") "assets",
os.popen("rm -rf " + proj_path + "gen") "bin",
os.popen("rm -rf " + proj_path + "obj") "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 # replaceString function is implemented in ../create-project.py
import replaces import replaces

View File

@ -6,6 +6,7 @@
# iOS # iOS
import os import os
import shutil
def handle_project_files(context): def handle_project_files(context):
# determine proj_path # determine proj_path
@ -24,9 +25,13 @@ def handle_project_files(context):
proj_path + context["dst_project_name"] + ".xcodeproj" ) proj_path + context["dst_project_name"] + ".xcodeproj" )
# remove useless files. # remove useless files.
os.popen("rm -rf " + proj_path + context["dst_project_name"] + ".xcodeproj/project.xcworkspace") removes = [
os.popen("rm -rf " + proj_path + context["dst_project_name"] + ".xcodeproj/xcuserdata" ) context["dst_project_name"] + ".xcodeproj/project.xcworkspace",
os.popen("rm -rf " + proj_path + "build" ) 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 # replaceString function is implemented in ../create-project.py
import replaces import replaces

View File

@ -18,6 +18,8 @@ def handle_project_files(context):
proj_path + context["dst_project_name"] + ".vcxproj.filters") proj_path + context["dst_project_name"] + ".vcxproj.filters")
os.rename(proj_path + context["src_project_name"] + ".vcxproj.user", os.rename(proj_path + context["src_project_name"] + ".vcxproj.user",
proj_path + context["dst_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 # replaceString function is implemented in ../create-project.py
import replaces 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", 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.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"] + ".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"]) replaces.replaceString(proj_path + "main.cpp", context["src_project_name"], context["dst_project_name"])
# done! # done!
print "proj.win32 : Done!" print "proj.win32 : Done!"

View File

@ -5,14 +5,14 @@
def replaceString(filepath, src_string, dst_string): def replaceString(filepath, src_string, dst_string):
content = "" content = ""
f1 = open(filepath, "r") f1 = open(filepath, "rb")
for line in f1: for line in f1:
if src_string in line: if src_string in line:
content += line.replace(src_string, dst_string) content += line.replace(src_string, dst_string)
else: else:
content += line content += line
f1.close() f1.close()
f2 = open(filepath, "w") f2 = open(filepath, "wb")
f2.write(content) f2.write(content)
f2.close() f2.close()
# end of replaceString(filepath, src, dst) function # end of replaceString(filepath, src, dst) function