From 3360a3cab5430ecf6c2d231eecaf9fb56cf00ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=81=E5=85=89?= <1004383796@qq.com> Date: Mon, 17 Sep 2018 09:30:04 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=20=E4=BF=AE=E5=A4=8Dpython?= =?UTF-8?q?27=E4=B8=8A=E8=BF=90=E8=A1=8C=E9=94=99=E8=AF=AF,=20=E7=9B=AE?= =?UTF-8?q?=E5=89=8Dpython27=E5=92=8C37=E9=83=BD=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E8=BF=90=E8=A1=8C.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buildpkg.py | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/buildpkg.py b/buildpkg.py index fdef012..fdbcb42 100644 --- a/buildpkg.py +++ b/buildpkg.py @@ -67,12 +67,20 @@ def buildpkg_add_readme(pkgname, version): log.debug("find readme.md template: \"%s\"" % (template_readme_path)) - with open(template_readme_path, 'r', encoding='utf-8') as file_in, open(readme_path, 'w+', encoding='utf-8') as file_out: - textlist = file_in.readlines() - for line in textlist: - line = line.replace("{{name}}", pkgname) - line = line.replace("{{version}}", version) - file_out.write(line) + if sys.version_info < (3, 0): + with open(template_readme_path, 'r') as file_in, open(readme_path, 'w+') as file_out: + textlist = file_in.readlines() + for line in textlist: + line = line.replace("{{name}}", pkgname) + line = line.replace("{{version}}", version) + file_out.write(line) + else: + with open(template_readme_path, 'r', encoding='utf-8') as file_in, open(readme_path, 'w+', encoding='utf-8') as file_out: + textlist = file_in.readlines() + for line in textlist: + line = line.replace("{{name}}", pkgname) + line = line.replace("{{version}}", version) + file_out.write(line) log.info("add readme.md success...") # add SConscript file @@ -83,14 +91,24 @@ def buildpkg_add_sconscript(pkgname, version): log.debug("find SConscript template: \"%s\"" % (template_sconscript_path)) - with open(template_sconscript_path, 'r', encoding='utf-8') as file_in, open(sconscript_path, 'w+', encoding='utf-8') as file_out: - textlist = file_in.readlines() - for line in textlist: - line = line.replace("{{name}}", pkgname) - line = line.replace("{{version}}", version) - line = line.replace("{{date}}", time.strftime("%Y-%m-%d", time.localtime())) - line = line.replace("{{datetime}}", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) - file_out.write(line) + if sys.version_info < (3, 0): + with open(template_sconscript_path, 'r') as file_in, open(sconscript_path, 'w+') as file_out: + textlist = file_in.readlines() + for line in textlist: + line = line.replace("{{name}}", pkgname) + line = line.replace("{{version}}", version) + line = line.replace("{{date}}", time.strftime("%Y-%m-%d", time.localtime())) + line = line.replace("{{datetime}}", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) + file_out.write(line) + else: + with open(template_sconscript_path, 'r', encoding='utf-8') as file_in, open(sconscript_path, 'w+', encoding='utf-8') as file_out: + textlist = file_in.readlines() + for line in textlist: + line = line.replace("{{name}}", pkgname) + line = line.replace("{{version}}", version) + line = line.replace("{{date}}", time.strftime("%Y-%m-%d", time.localtime())) + line = line.replace("{{datetime}}", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) + file_out.write(line) log.info("add SConscript success...") # add git repository