async def __call_release_list_fun(self, generator_cache: GeneratorCache, app_id: dict, auth: dict or None): """ 当软件源未实现 get_release_list 函数时,缺省调用 get_release 函数获取数据的协程函数 """ # 获取云端数据 release_list = None # noinspection PyBroadException try: release_list = self.get_release(app_id, auth) # 缓存数据,包括 404 None 数据 except HTTPError as e: status_code = e.response.status_code logging.warning(f"""app_id: {app_id} HTTP CODE {status_code} ERROR: {e}""") if status_code == 404: release_list = [] except asyncio.TimeoutError: logging.warning(f'app_id: {app_id} timeout!') except Exception: debug_mode = server_config.debug_mode log = f"app_id: {app_id}" if debug_mode: log += " \nERROR: " else: log += " ERROR" logging.exception(log, exc_info=debug_mode) return_value(generator_cache, app_id, release_list)
def GetCloudConfig(self, request, context) -> Str: dev_version = False # noinspection PyBroadException try: return Str(s=get_cloud_config_str( self.__get_cloud_config_version(request), True)) except Exception: logging.exception('gRPC: GetCloudConfig')
def InitHubAccount(self, request: AccountRequest, context) -> AccountResponse: hub_uuid: str = request.hub_uuid account: dict = grcp_dict_list_to_dict(request.account) # noinspection PyBroadException try: return self.__init_account(hub_uuid, account) except Exception: logging.exception(f'gRPC: InitHubAccount, hub_uuid: {hub_uuid}') return None
def DevGetDownloadInfo(self, request: GetDownloadRequest, context: RpcContext) -> GetDownloadResponse: hub_uuid: str = request.hub_uuid auth: dict = grcp_dict_list_to_dict(request.auth) app_id: dict = grcp_dict_list_to_dict(request.app_id) asset_index: list = request.asset_index # noinspection PyBroadException try: return self.__get_download_info_list(hub_uuid, auth, app_id, asset_index) except Exception: logging.exception(f'gRPC: GetDownloadInfo, hub_uuid: {hub_uuid}') return None
def GetAppRelease(self, request: ReleaseRequest, context) -> ReleaseResponse: hub_uuid: str = request.hub_uuid auth: dict = grcp_dict_list_to_dict(request.auth) app_id_list: list = [ grcp_dict_list_to_dict(item.app_id) for item in request.app_id_list ] logging.warning(f"{hub_uuid}, num: {len(app_id_list)}, auth: {auth}") # noinspection PyBroadException try: for item in self.__get_app_release(hub_uuid, auth, app_id_list): yield item except Exception: logging.exception(f'gRPC: GetAppStatus, hub_uuid: {hub_uuid}') return None
def GetAppStatus(self, request, context) -> Response: # noinspection PyBroadException try: request = MessageToDict(request, preserving_proto_field_name=True) hub_uuid: str = request['hub_uuid'] if 'app_id' in request: app_id: list = request['app_id'] else: app_id = [] app_id_dict = {} app_id_row = [] for i in app_id: app_id_dict[i["key"]] = i["value"] app_id_row.append({'k': i["key"], 'v': i["value"]}) new_d = MessageToDict(next( self.__get_app_release(hub_uuid, None, [app_id_dict])), preserving_proto_field_name=True) release = new_d["release"] app_id_l = release["app_id"] if app_id_row != app_id_l: logging.exception( f'gRPC: GetAppStatus: app_id 校验失败' f'app_id: {app_id_row}, app_id_l: {app_id_l}') valid_hub = new_d["valid_hub"] release_list = None if valid_hub: valid_data = "valid_data" in release and release["valid_data"] valid_app = valid_data and "release_list" in release and len( release["release_list"]) != 0 if valid_app: release_list = release["release_list"] app_status = { "valid_hub_uuid": valid_hub, "valid_app": valid_app, "valid_data": valid_data, "release_info": release_list } else: app_status = { "valid_hub_uuid": valid_hub, } return ParseDict({"app_status": app_status}, Response()) except Exception: logging.exception('gRPC: GetAppStatus') return None
def GetDownloadInfo(self, request, context) -> DownloadInfo: # noinspection PyBroadException try: request = MessageToDict(request, preserving_proto_field_name=True) app_id_info = request["app_id_info"] hub_uuid = app_id_info["hub_uuid"] app_id = app_id_info["app_id"] app_id_dict = {} for i in app_id: app_id_dict[i["key"]] = i["value"] asset_index = request["asset_index"] new_d = MessageToDict(self.__get_download_info( hub_uuid, None, app_id_dict, asset_index), preserving_proto_field_name=True) if "list" in new_d: return ParseDict(new_d["list"][0], DownloadInfo()) except Exception: logging.exception('gRPC: GetDownloadInfo') return None
def debug(hub_uuid: str, test_options: list, run_init_account: bool = False): try: app_id = {} auth = {} account = {} if test_options: l_size = len(test_options) auth_index = 0 if run_init_account: for i in range(0, l_size, 2): account[test_options[i]] = test_options[i + 1] else: if auth_key in test_options: l_size = auth_index = test_options.index(auth_key) for i in range(0, l_size, 2): app_id[test_options[i]] = test_options[i + 1] if auth_index: for i in range(auth_index + 1, len(test_options), 2): auth[test_options[i]] = test_options[i + 1] test_options = {'auth': auth, 'app_id': app_id, 'account': account} _debug(hub_uuid, test_options, run_init_account) except KeyboardInterrupt: logging.exception("手动停止 DEBUG")