def help(): util.print_W("""用法: build.py -h 显示帮助 build.py -p path path 为指定要编译的sdk平台路径, 含有project.ini文件 如:....../trunk/wzzj_platform/gfan/ build.py path path 为包含各种sdk平台目录的仓库路径 如:....../trunk/wzzj_platform/ build.py 同build.py path 将当前目录作为path传入""")
def del_help(): util.print_W("""用法: ant_configure.py -h 显示帮助 ant_configure.py -p path path 为指定要编译的sdk平台路径, 含有project.ini文件 如:....../trunk/wzzj_platform/gfan/ ant_configure.py path path 为包含各种sdk平台目录的仓库路径 如:....../trunk/wzzj_platform/ ant_configure.py 同ant_configure.py path 将当前目录作为path传入""")
def _help(): util.print_W("""用法: ant_configure.py -h 显示帮助 ant_configure.py -p path path 为指定要编译的sdk平台项目路径, 如:china-alliance/91/3.2.6.1/interface_android/LK_Android_91Demo ant_configure.py path path 为包含config.xml的目录 根据config文件引导用户,选择对应的目录进行配置 ant_configure.py 同ant_configure.py path 将当前目录作为path传入 当前目录含有config.xml文件""")
def _help(): util.print_W("""用法:build.py [选项]... [PATH] [PATH] 为包含config.xml的目录 根据config文件引导用户,选择对应的目录进行编译。当不指定PATH时,这代表使用当前文件夹 选项参数: -h, --help 显示帮助 -p, --path=project_path project_path 为指定要编译的sdk平台项目路径, 如:china-alliance/91/3.2.6.1/interface_android/LK_Android_91Demo -d, --debug 指定编译debug版本,默认编译release版本""")
def help(): util.print_W( """用法: build.py -h 显示帮助 build.py -p path path 为指定要编译的sdk平台路径, 含有project.ini文件 如:....../trunk/wzzj_platform/gfan/ build.py path path 为包含各种sdk平台目录的仓库路径 如:....../trunk/wzzj_platform/ build.py 同build.py path 将当前目录作为path传入""" )
def _help(): util.print_W( """用法:build.py [选项]... [PATH] [PATH] 为包含config.xml的目录 根据config文件引导用户,选择对应的目录进行编译。当不指定PATH时,这代表使用当前文件夹 选项参数: -h, --help 显示帮助 -p, --path=project_path project_path 为指定要编译的sdk平台项目路径, 如:china-alliance/91/3.2.6.1/interface_android/LK_Android_91Demo -d, --debug 指定编译debug版本,默认编译release版本""" )
def config(workspace): extern_jar = [] islib = "" ref_library = [] print "\n处理workspace = %s " % workspace if not os.path.isdir(workspace): util.print_E("ERROR: 文件夹不存在") return #.classpath project.properties local.properties #sed -i 's@\\@/@g' project.properties for f in [".classpath", "project.properties", "local.properties"]: if os.path.isfile(os.path.join(workspace, f)): sed_cmd = "sed -i 's@\\\\@/@g' %s" % (os.path.join(workspace, f)) util.print_D(sed_cmd) os.system(sed_cmd) #获得项目名 --name doc_project = ET.parse(os.path.join(workspace, ".project")) project_name = doc_project.find("name").text util.print_D(project_name) #获得external jar doc_classpath = ET.parse(os.path.join(workspace, ".classpath")) for node in doc_classpath.findall("classpathentry"): if node.get("kind", default=None) == "lib": extern_jar.append(node.get("path", default=None)) util.print_D(extern_jar) #获得android.library fproject_properties = open(os.path.join(workspace, "project.properties"), "r+") for line in fproject_properties: util.print_D(line) if line.startswith("android.library="): islib = line.split('=')[1].strip() if ostype == "cygwin" or ostype == "win32": android_bat = "android.bat" else: android_bat = "android" #运行android.bat 脚本生成ant配置文件 if not islib.lower() == "true": command = "%s update project --path %s --name %s --target android-19" \ % (android_bat, workspace, project_name) else : command = "%s update lib-project --path %s --target android-19" \ % (android_bat, workspace) if os.path.isfile(os.path.join(workspace, "build.xml")): util.print_W("WARNNING: 该项目已经存在build.xml文件,如需重新生成,请删除该项目中的build.xml文件") status,output = 0, "" else: util.print_D(command) (status, output) = commands.getstatusoutput(command) print output if (not status == 0) or (output.find("Error:") > -1): util.print_E("ERROR: ant配置文件更新失败") else: #读取android.library.reference.n 生成依赖库中的ant配置文件 fproject_properties.seek(0) for line in fproject_properties: if line.startswith("android.library.reference."): ref_library.append(line.split('=')[1].strip().replace("\\", "/")) util.print_D(ref_library) #将external jar 写入project.properties文件 if len(extern_jar) > 0: fproject_properties.seek(0) lines = fproject_properties.readlines() new_lines = [] skip = False for line in lines: if line.startswith("java.compiler.classpath="): new_lines.append("java.compiler.classpath=" + ";".join(extern_jar) + "\n") skip = True else: new_lines.append(line) if not skip: new_lines.append("\njava.compiler.classpath=" + ";".join(extern_jar)) new_lines.append("\n"); util.print_D(new_lines) fproject_properties.truncate(0) fproject_properties.seek(0) fproject_properties.write("".join(new_lines)) fproject_properties.close() #如果有jni目录,添加ndk编译 if os.path.isdir(os.path.join(workspace, "jni")): util.print_W("添加NDK编译") util.print_D(ndk_build_xml_str) fcustom_rule = open(os.path.join(workspace, "custom_rules.xml"), "w") fcustom_rule.write(ndk_build_xml_str) fcustom_rule.close() #添加签名信息 if not islib.lower() == "true": current = os.path.abspath(workspace) while True: if os.path.isdir(os.path.join(current, "common")): break else: current = os.path.join(current, "..") signature_properties_string = (signature_properties_str % current.split(os.path.basename(os.path.abspath(workspace))+"/")[1]) fant_proper = open(os.path.join(workspace, "ant.properties"), "w") fant_proper.write(signature_properties_string) fant_proper.close() #生成依赖库的ant脚本 for lib_dir in ref_library: config(os.path.join(workspace, lib_dir)) #如果lib需要混淆,则把lib的proguard-project.txt include到本工程中proguard-project.txt fproguard = open(os.path.join(workspace, "proguard-project.txt"), "a") for lib_dir in ref_library: f = open(os.path.join(workspace, lib_dir, "project.properties"), "r") for line in f.readlines(): if line.startswith("proguard.config="): fproguard.write("\n-include " + os.path.join(lib_dir, "proguard-project.txt") + "\n") current = os.path.abspath(workspace) while True: if os.path.isdir(os.path.join(current, "common")): break else: current = os.path.join(current, "..") fproguard.write("\n-include " + os.path.join(current.split(os.path.basename(os.path.abspath(workspace))+"/")[1], \ "common", "LK_AntiRobot", "base-proguard-project.txt") + "\n") os.system("sed -i 's/^#proguard.config=/proguard.config=/' " + os.path.join(workspace, "project.properties")) util.print_W("\n" + workspace + " 混淆打开") f.close() fproguard.close()
add_out_release_list(srcname, dstname, srcqueue, dstqueue) copy_result_list(srcqueue, dstqueue) del_svn(dstname) print "拷贝完成" if __name__ == "__main__": srcqueue = deque([]) dstqueue = deque([]) srcdir = os.getcwd() dstdir = os.path.join(os.getcwd(), "..", "release") if os.path.isdir(dstdir): print dstdir util.print_W("release文件夹已存在,清除文件夹内容重新拷贝?") ans = raw_input("y删除原来文件夹,n直接覆盖原文件夹(y/n):") if ans.lower() == "y": shutil.rmtree(dstdir) os.makedirs(dstdir) elif os.path.isfile(dstdir): print dstdir ans = raw_input("release是一个文件,删除该文件?(y/n)") if ans.lower() == "y": os.remove(dstdir) os.makedirs(dstdir) else: util.print_E("拷贝失败!请确认release文件内容,或者备份之后再执行该脚本。") else: os.makedirs(dstdir)