|
|
@@ -0,0 +1,121 @@
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+import os
|
|
|
+import sys
|
|
|
+import json
|
|
|
+import requests
|
|
|
+import xml.etree.ElementTree as ETree
|
|
|
+
|
|
|
+from qiniu import CdnManager
|
|
|
+from qiniu import Auth, put_file
|
|
|
+
|
|
|
+default_encoding = 'utf-8'
|
|
|
+if sys.getdefaultencoding() != default_encoding:
|
|
|
+ reload(sys)
|
|
|
+ sys.setdefaultencoding(default_encoding)
|
|
|
+
|
|
|
+# 七牛云
|
|
|
+remote_url = "http://qndownload.shotshock.shop"
|
|
|
+accessKey = "SneSBtnWLdStBhCx0O_QogNkXoRlKNOiv1--XMBB"
|
|
|
+secretKey = "GXMg-ENcp2UKYQWdeaf43tk_06NnMoA4OVFxdkYw"
|
|
|
+bucket_name = 'twongupdates'
|
|
|
+# 安卓包文件地址
|
|
|
+apk_path = "./cordova/platforms/android/app/build/outputs/apk/release/app-release.apk"
|
|
|
+# cordova 配置文件地址
|
|
|
+cordova_xml = "./cordova/config.xml"
|
|
|
+# cordova 版本号替换文本
|
|
|
+replace = 'widget id="com.shotshock.twong" version="'
|
|
|
+
|
|
|
+# android
|
|
|
+manifest = "./cordova/platforms/android/app/src/main/AndroidManifest.xml"
|
|
|
+android_repl = ""
|
|
|
+
|
|
|
+
|
|
|
+# 设置 cordova 配置中的 APP 版本号
|
|
|
+def apk_version(version):
|
|
|
+ conf = ETree.parse(cordova_xml)
|
|
|
+ root = conf.getroot()
|
|
|
+ apk_ver = root.get("version")
|
|
|
+ print("local version: " + apk_ver)
|
|
|
+
|
|
|
+ conf = open(cordova_xml, "r")
|
|
|
+ text = conf.read()
|
|
|
+ conf.flush()
|
|
|
+ conf.close()
|
|
|
+
|
|
|
+ text = text.replace(replace + apk_ver, replace + version)
|
|
|
+ new = open(cordova_xml, "w")
|
|
|
+ new.write(text)
|
|
|
+ new.flush()
|
|
|
+ new.close()
|
|
|
+
|
|
|
+
|
|
|
+# 获取远程的版本号
|
|
|
+def get_version():
|
|
|
+ res = requests.get(remote_url + "/version")
|
|
|
+ version = json.loads(res.text)
|
|
|
+ print("remote version: " + version["version"])
|
|
|
+ return version
|
|
|
+
|
|
|
+
|
|
|
+# 生成新的版本号
|
|
|
+def new_version(version):
|
|
|
+ olds = version.split('.')
|
|
|
+ new_2 = int(olds[2])
|
|
|
+ new_1 = int(olds[1])
|
|
|
+ new_0 = int(olds[0])
|
|
|
+ if new_2 + 1 > 9:
|
|
|
+ if new_1 + 1 > 9:
|
|
|
+ new_0 = new_0 + 1
|
|
|
+ new_1 = 0
|
|
|
+ new_2 = 0
|
|
|
+ else:
|
|
|
+ new_1 = new_1 + 1
|
|
|
+ new_2 = 0
|
|
|
+ else:
|
|
|
+ new_2 = new_2 + 1
|
|
|
+ new = str(new_0) + "." + str(new_1) + "." + str(new_2)
|
|
|
+ print("new version: " + new)
|
|
|
+ return new
|
|
|
+
|
|
|
+
|
|
|
+# 上传七牛云
|
|
|
+def upload(local_file, remote_file):
|
|
|
+ auth = Auth(accessKey, secretKey)
|
|
|
+ token = auth.upload_token(bucket_name, remote_file, 3600)
|
|
|
+ ret, info = put_file(token, remote_file, local_file)
|
|
|
+
|
|
|
+ if ret['key'] != remote_file:
|
|
|
+ print(remote_file + " upload failed !")
|
|
|
+ print(info)
|
|
|
+ return False
|
|
|
+ else:
|
|
|
+ print(remote_file + " upload ok !")
|
|
|
+ cdn_manager = CdnManager(auth)
|
|
|
+ urls = [remote_url + "/" + remote_file]
|
|
|
+ ret = cdn_manager.refresh_urls(urls)[0]
|
|
|
+ if ret["code"] == 200:
|
|
|
+ print("refresh success !")
|
|
|
+ else:
|
|
|
+ print("refresh failed !\n", ret)
|
|
|
+ return True
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ ver = get_version()
|
|
|
+ ver_new = ver["version"]
|
|
|
+ ver_new = new_version(ver_new)
|
|
|
+ apk_version(ver_new)
|
|
|
+
|
|
|
+ os.system("sh ./build.sh app")
|
|
|
+
|
|
|
+ if not upload(apk_path, "twong-" + ver_new + ".apk"):
|
|
|
+ exit(-1)
|
|
|
+
|
|
|
+ ver["version"] = ver_new
|
|
|
+ ver["download"] = remote_url + "/twong-" + ver_new + ".apk"
|
|
|
+ verFile = open("version.json", "w")
|
|
|
+ json.dump(ver, verFile)
|
|
|
+ verFile.close()
|
|
|
+
|
|
|
+ if not upload("version.json", "version"):
|
|
|
+ exit(-1)
|