Exemple #1
0
def add_device(_content: bytes, uuid: str, udid: str = ""):
    _key = "uuid:%s" % uuid
    _detail = str_json(db_session.get(_key) or "{}")
    _account = _detail.get("account")
    project = _detail["project"]
    if not _detail:
        raise Fail("无效的uuid[%s]" % uuid)
    if not udid:
        # todo: 验证来源
        with Block("提取udid", fail=False):
            udid = re.compile(br"<key>UDID</key>\n\s+<string>(\w+)</string>"
                              ).findall(_content)[0].decode("utf8")
    if not udid:
        # 提取udid失败后删除uuid
        db_session.delete(_key)
        return {
            "succ": False,
        }
    for _user in UserInfo.objects.filter(udid=udid):
        _account = _user.account
        if _user.project == _detail["project"]:
            if uuid != _user.uuid:
                Log("转移设备的[%s]的uuid[%s]=>[%s]" % (udid, uuid, _user.uuid))
                uuid = _user.uuid
                break

    if not _account:
        Log("为设备[%s]分配账号" % udid)
        _account = __fetch_account(udid, project, __add_device)
    else:
        _account = IosAccountInfo.objects.filter(account=_account).first()

    _user = UserInfo(uuid=uuid)
    _user.udid = udid
    _user.project = _detail["project"]
    _user.account = _account.account
    _user.save()
    if test_env():
        # 测试环境可能uuid要重复测
        pass
    else:
        db_session.delete(_key)
    __add_task(_user)
    return HttpResponsePermanentRedirect(
        "https://iosstore.sklxsj.com/detail.php?project=%s" % project)
Exemple #2
0
 def release(self):
     if self.__lock:
         db_session.delete(self.__key)