From 7ff34ef43d083778c7090834da79b0f8200da2b1 Mon Sep 17 00:00:00 2001 From: youngS Date: Mon, 29 Mar 2021 11:47:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=89=E5=8D=93=E5=8C=85?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E5=9B=BE=E6=A0=87=E5=A4=B1=E8=B4=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fir_ser/cli.py | 51 ++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/fir_ser/cli.py b/fir_ser/cli.py index a5354f7..1f267ce 100644 --- a/fir_ser/cli.py +++ b/fir_ser/cli.py @@ -88,7 +88,7 @@ class FLY_CLI_SER(object): def upload_app(self, app_path): appobj = AppInfo(app_path) appinfo = appobj.get_app_data() - icon_path = appobj.make_app_png() + icon_path = appobj.make_app_png(icon_path=appinfo.get("icon_path", None)) bundle_id = appinfo.get("bundle_id") upcretsdata = self.get_upload_token(bundle_id, appinfo.get("type")) if upcretsdata['storage'] == 1: @@ -121,7 +121,7 @@ class FLY_CLI_SER(object): "version": appinfo['version'], "buildversion": appinfo['versioncode'], "miniosversion": appinfo['miniosversion'], - "release_type": appinfo['release_type'], + "release_type": appinfo.get('release_type', ''), "release_type_id": 2, "udid": appinfo.get('udid', []), "type": appinfo['type'], @@ -134,30 +134,36 @@ class AppInfo(object): self.app_path = app_path self.result = {} - def make_app_png(self): + def make_app_png(self, icon_path): zf = zipfile.ZipFile(self.app_path) - name_list = zf.namelist() - if self.app_path.endswith("apk"): - pattern = re.compile(r'res/drawable[^/]*/app_icon.png') - elif self.app_path.endswith("ipa"): - pattern = re.compile(r'Payload/[^/]*.app/AppIcon[^/]*[^(ipad)].png') + iconfile = "" + if icon_path: + size = len(zf.read(icon_path)) + iconfile = icon_path else: - raise Exception("File type error") + name_list = zf.namelist() + if self.app_path.endswith("apk"): + pattern = re.compile(r'res/drawable[^/]*/app_icon.png') + elif self.app_path.endswith("ipa"): + pattern = re.compile(r'Payload/[^/]*.app/AppIcon[^/]*[^(ipad)].png') + else: + raise Exception("File type error") - size = 0 - iconfile = "" - for path in name_list: - m = pattern.match(path) - if m is not None: - filepath = m.group() - fsize = len(zf.read(filepath)) - if size == 0: - iconfile = filepath - if size < fsize: - size = fsize - iconfile = filepath + size = 0 + for path in name_list: + m = pattern.match(path) + if m is not None: + filepath = m.group() + fsize = len(zf.read(filepath)) + if size == 0: + iconfile = filepath + if size < fsize: + size = fsize + iconfile = filepath if size == 0: raise Exception("File size error") + if iconfile == "": + raise Exception("read File icon error") filename = ''.join(random.sample( ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', @@ -201,7 +207,8 @@ class AppInfo(object): "versioncode": versioncode, "version": version, "type": "Android", - "miniosversion": apkobj.get_min_sdk_version() + "miniosversion": apkobj.get_min_sdk_version(), + "icon_path": apkobj.get_app_icon() } return self.result