def __add_task(_user: UserInfo): _account = IosAccountInfo.objects.get(account=_user.account) _project = IosProjectInfo.objects.get(project=_user.project) _profile = IosProfileInfo.objects.get(sid="%s:%s" % (_user.account, _user.project)) _cert = IosCertInfo.objects.get( sid="%s:%s" % (_user.account, str_json_a(_profile.certs)[0])) Assert(_profile, "[%s][%s]证书无效" % (_project.project, _account.account)) Assert(_project.md5sum, "项目[%s]原始ipa还没上传" % _project.project) Assert(_cert.cert_p12, "项目[%s]p12还没上传" % _project.project) Log("[%s]发布任务[%s]" % (_user.project, _user.account)) _task, _ = TaskInfo.objects.get_or_create(uuid=_user.uuid) _task.state = "none" _task.worker = "" _task.save() resign_ipa.delay( **{ "uuid": _user.uuid, "cert": "iPhone Developer: %s" % _cert.name, "cert_url": entry("/apple/download_cert?uuid=%s" % _user.uuid), "cert_md5": md5bytes(base64decode(_cert.cert_p12)), "mp_url": entry("/apple/download_mp?uuid=%s" % _user.uuid), "mp_md5": md5bytes(base64decode(_profile.profile)), "project": _project.project, "ipa_url": entry("/projects/%s/orig.ipa" % _user.project), "ipa_md5": _project.md5sum, "ipa_new": "%s_%s.ipa" % (_account.team_id, _account.devices_num), "upload_url": entry("/apple/upload_ipa?uuid=%s" % _user.uuid), "process_url": entry("/apple/task_state?uuid=%s" % _user.uuid), })
def __add_task(_user: UserInfo): _account = IosAccountInfo.objects.filter( account=_user.account).first() # type:IosAccountInfo _project = IosProjectInfo.objects.filter( project=_user.project).first() # type:IosProjectInfo _profile = IosProfileInfo.objects.filter( sid="%s:%s" % (_user.account, _user.project)).first() # type:IosProfileInfo Assert(_profile, "[%s][%s]证书无效" % (_project.project, _account.account)) Log("[%s]发布任务[%s]" % (_user.project, _user.account)) db_session.publish( "task:package", json_str({ "cert": "iPhone Developer: zhangming luo", "cert_p12": "", "mp_url": entry("/apple/download_mp?uuid=%s" % _user.uuid), "mp_md5": md5bytes(base64decode(_profile.profile)), "project": _project.project, "ipa_url": _asset_url("%s/orig.ipa" % _user.project), "ipa_md5": _project.md5sum, "ipa_new": "%s_%s.ipa" % (_account.team_id, _account.devices_num), "upload_url": entry("/apple/upload_ipa?project=%s&account=%s" % (_user.project, _user.account)), "ts": now(), }))
def download_cert(uuid: str, filename: str = "cert.p12"): _user = UserInfo.objects.get(uuid=uuid) _cert = IosCertInfo.objects.get(app=_user.account) response = HttpResponse(base64decode(_cert.cert_p12)) response['Content-Type'] = 'application/octet-stream' response['Content-Disposition'] = 'attachment;filename="%s"' % filename return response
def download_mp(uuid: str, filename: str = "package.mobileprovision"): _user = UserInfo.objects.filter(uuid=uuid).first() # type: UserInfo _info = IosAccountInfo.objects.filter( account=_user.account).first() # type:IosAccountInfo _profile = IosProfileInfo.objects.filter( sid="%s:%s" % (_user.account, _user.project)).first() # type:IosProfileInfo response = HttpResponse(base64decode(_profile.profile)) response['Content-Type'] = 'application/octet-stream' response['Content-Disposition'] = 'attachment;filename="%s"' % filename return response
def post(self, title: str, url: str, data: Union[Dict, str] = None, is_json=True, log=True, cache: Union[bool, int] = False, csrf=False, json_api=True, method="POST", is_binary=False, ex_headers=None, status=200): if cache is True: expire = 3600 * 1000 else: expire = cache if not self.is_login: self.__login() start = now() rsp_str = "#NODATA#" try: if "teamId=" in url: if "teamId=%s" % self.team_id not in url: url = url.replace("teamId=", "teamId=%s" % self.team_id) if cache: rsp_str = _cache(url, data) or rsp_str headers = { 'cookie': to_form_url({"myacinfo": self.cookie["myacinfo"]}, split=';'), } if csrf: headers.update({ 'csrf': self.csrf, 'csrf_ts': self.csrf_ts, }) if ex_headers: headers.update(ex_headers) if rsp_str == "#NODATA#": if method.upper() == "GET": rsp = requests.get(url, params=data, headers=headers, timeout=3, verify=False) else: rsp = requests.post(url, data=data, headers=headers, timeout=3, verify=False) rsp_str = rsp.text if rsp.headers.get("csrf"): self.csrf = rsp.headers["csrf"] self.csrf_ts = int(rsp.headers["csrf_ts"]) Assert(rsp.status_code == status, "请求[%s]异常[%s]" % (title, rsp.status_code)) if json_api: _data = str_json_i(rsp_str) or {} if _data.get("resultCode") == 1100: self.__logout() raise Fail("登录[%s]过期了[%s][%s]" % (self.account, _data.get("resultString"), _data.get("userString"))) Assert( _data.get("resultCode") == 0, "请求业务[%s]失败[%s][%s]" % (title, _data.get("resultString"), _data.get("userString"))) if log: Log("apple请求[%s][%s]发送[%r]成功[%r]" % (title, now() - start, data, rsp_str)) if is_binary: rsp_str = base64(rsp.content) if cache: _set_cache(url, data, rsp_str, expire=expire) if is_json: return str_json(rsp_str) elif is_binary: return base64decode(rsp_str) else: return rsp_str except Exception as e: if log: Log("apple请求[%s][%s]发送[%r]失败[%r]" % (title, now() - start, data, rsp_str)) raise e