def update_to(self, uploaded_size, total_size, status): if not status: # print("uploaded_size" + str(uploaded_size)) # print("total_size" + str(total_size)) # per = 100.0 * uploaded_size / total_size self.update((total_size - uploaded_size) / 100 / 0.7) else: Flog.i(self.avg_time)
def handle_res(sdk_dir: str) -> bool: try: # merge manifest merge_manifest(sdk_dir) copy_res(sdk_dir) copy_assets(sdk_dir) copy_libs(sdk_dir + "/libs", FPath.DECOMPILE_PATH + "/lib") return True except Exception as e: Flog.i(str(e)) return False
def merge_manifest(sdk_dir: str) -> None: """ merge manifest :param sdk_dir: :return: """ target_manifest_path = FPath.DECOMPILE_PATH + "/AndroidManifest.xml" sdk_manifest_path = sdk_dir + "/SDKManifest.xml" if not os.path.exists(target_manifest_path) or not os.path.exists( sdk_manifest_path): Flog.i("the manifest file is not exists.target_manifest:" + target_manifest_path + ";sdk_manifest:" + sdk_manifest_path) return android_ns = "http://schemas.android.com/apk/res/android" elementTree.register_namespace("android", android_ns) target_tree = elementTree.parse(target_manifest_path) target_root = target_tree.getroot() elementTree.register_namespace("android", android_ns) sdk_tree = elementTree.parse(sdk_manifest_path) sdk_root = sdk_tree.getroot() f = open(target_manifest_path, encoding="UTF-8", errors="ignore") target_content = f.read() f.close() permission_config_node = sdk_root.find("permissionConfig") if permission_config_node is not None and len(permission_config_node) > 0: for child in list(permission_config_node): key = "{" + android_ns + "}name" val = child.get(key) if val is not None and len(val) > 0: attr_index = target_content.find(val) if -1 == attr_index: target_root.append(child) # 不需要对application进行处理 app_config_node = sdk_root.find("applicationConfig") app_node = target_root.find("application") if app_config_node is not None: for child in list(app_config_node): app_node.append(child) target_tree.write(target_manifest_path, "UTF-8")
def merge_res_xml(copy_from, copy_to) -> bool: """ Merge all android res xml :param copy_from: :param copy_to: :return: """ if not os.path.exists(copy_to): return False ary_xml = [ "strings.xml", "styles.xml", "colors.xml", "dimens.xml", "ids.xml", "attrs.xml", "integers.xml", "arrays.xml", "bools.xml", "drawables.xml", "values.xml" ] basename = os.path.basename(copy_from) if basename in ary_xml: f = open(copy_to, "r", encoding="UTF-8") target_content = f.read() f.close() from_tree = elementTree.parse(copy_from) from_root = from_tree.getroot() to_tree = elementTree.parse(copy_to) to_root = to_tree.getroot() for node in list(from_root): val = node.get("name") if val is not None and len(val) > 0: val_matched = '"' + val + '"' attr_index = target_content.find(val_matched) if -1 == attr_index: to_root.append(node) else: Flog.i("The node " + val + " is already exists in " + basename) to_tree.write(copy_to, 'UTF-8') return True return False
def invoke_multi_upload(self) -> str: Flog.i("rest_multi_upload...") # file_name = os.path.basename(file_path) # remote_file = "/3kfast_auto/{0}/{1}/{2}/{3}/{4}".format(game_id, platform_id, version_code, timestamp, # file_name) try: # for chunk_data in MultiUpload.__file_iterator(local_file, unit): # print("upload chunk : " + str(i)) # uploader.upload(i, chunk_data) # i += 1 # else: # uploader.complete() # Flog.i("upload complete") # pool = multiprocessing.Pool(multiprocessing.cpu_count()) self.__upload() self.__pool.close() self.__pool.join() res = self.__uploader.complete() print(res) return Host.OSS_SERVICE_NAME + self.__remote_file except Exception as e: Flog.i(str(e)) return ""
def upload_file(file_path: str, timestamp: str, game_id: str, version_code: str, platform_id) -> str: try: file_name = os.path.basename(file_path) with open(file_path, "rb") as file: path = "/3kfast/{0}/{1}/{2}/{3}/{4}".format( timestamp, game_id, version_code, platform_id, file_name) with UploadHook(unit="B", unit_scale=True, unit_divisor=1024, miniters=1, desc=file_name) as hook: res = frequest.upyun_manager.put(path, file, checksum=True, need_resume=True, store=None, reporter=hook.update_to) url = Host.OSS_SERVICE_NAME + path return url except UpYunServiceException as se: Flog.i("upload bag file fail") Flog.i("Except an UpYunServiceException ...") Flog.i("Request Id : " + se.request_id) Flog.i("HTTP Status Code : " + str(se.status)) Flog.i("Error code : " + se.err) Flog.i(" ----> Error Message : " + se.msg) return "" except UpYunClientException as ce: Flog.i("upload bag file fail") Flog.i("Except an UpYunClientException ...") Flog.i(" Error Message : " + ce.msg) return "" except Exception as e: Flog.i("upload bag file fail") return ""
def rest_upload(file_path: str, timestamp: str, game_id: str, version_code: str, platform_id) -> str: try: file_name = os.path.basename(file_path) path = "/3kfast_auto/{0}/{1}/{2}/{3}/{4}".format( game_id, platform_id, version_code, timestamp, file_name) gmtdate = UploadApi.__gmt_date() auth = UploadApi.__sign_str(Host.UPYUN_USERNAME, Host.UPYUN_PASSWORD, "PUT", "/" + Host.UPYUN_SERVICE + path, UploadApi.__gmt_date(), policy=None) Flog.i(auth) headers = {'Date': gmtdate, 'Authorization': auth} with open(file_path, 'rb') as f: Flog.i('http://v0.api.upyun.com' + "/" + Host.UPYUN_SERVICE + path) r = requests.put('http://v0.api.upyun.com/yxupload' + path, data=f, headers=headers) return Host.OSS_SERVICE_NAME + path except UpYunServiceException as se: Flog.i("upload bag file fail") Flog.i("Except an UpYunServiceException ...") Flog.i("Request Id : " + se.request_id) Flog.i("HTTP Status Code : " + str(se.status)) Flog.i("Error code : " + se.err) Flog.i(" ----> Error Message : " + se.msg) return "" except UpYunClientException as ce: Flog.i("upload bag file fail") Flog.i("Except an UpYunClientException ...") Flog.i(" Error Message : " + ce.msg) return "" except Exception as e: Flog.i("upload bag file fail : " + str(e)) return ""