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 "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!"

View File

@ -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

View File

@ -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

View File

@ -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!"

View File

@ -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