diff --git a/fir_ser/api/utils/app/iossignapi.py b/fir_ser/api/utils/app/iossignapi.py index 71612b0..1858f27 100644 --- a/fir_ser/api/utils/app/iossignapi.py +++ b/fir_ser/api/utils/app/iossignapi.py @@ -301,7 +301,7 @@ class AppDeveloperApiV2(object): except Exception as e: logger.error(f"app_id {app_obj.app_id} ios developer make profile Failed Exception:{e}") result['return_info'] = "%s" % e - if "There are no current ios devices" in e: + if "There are no current ios devices" in str(e): err_callback() return False, result diff --git a/fir_ser/api/utils/app/supersignutils.py b/fir_ser/api/utils/app/supersignutils.py index 13db34e..5d2a017 100644 --- a/fir_ser/api/utils/app/supersignutils.py +++ b/fir_ser/api/utils/app/supersignutils.py @@ -192,9 +192,9 @@ def get_apple_udid_key(auth): return m_key -def err_callback(func, a, b): +def err_callback(func, *args, **kwargs): def wrapper(): - return func(a, b) + return func(*args, **kwargs) return wrapper @@ -327,6 +327,10 @@ class IosUtils(object): sync_device_obj = UDIDsyncDeveloper.objects.filter(udid=udid_info.get('udid'), developerid=developer_obj).first() if sync_device_obj: + DeveloperDevicesID.objects.update_or_create(did=sync_device_obj.serial, udid=sync_device_obj, + developerid=developer_obj, + app_id=app_obj) + device_id_lists.append(sync_device_obj.serial) udid_info = None add_did_flag = True @@ -336,7 +340,7 @@ class IosUtils(object): get_profile_full_path(developer_obj, app_obj), auth, developer_app_id, device_id_lists, err_callback(IosUtils.get_device_from_developer, - developer_obj, developer_obj.user_id)) + developer_obj)) if add_did_flag and sync_device_obj: result['did'] = sync_device_obj.serial result['did_exists'] = True @@ -421,20 +425,11 @@ class IosUtils(object): storage_obj.upload_file(os.path.join(MEDIA_ROOT, random_file_name + ".ipa")) def update_developer_used_data(self): - appsupersign_obj = APPSuperSignUsedInfo.objects.filter(udid__udid=self.udid_info.get('udid'), - developerid=self.developer_obj) - if appsupersign_obj.count() == 0: - developer_obj = self.developer_obj - developer_obj.use_number = developer_obj.use_number + 1 - logger.info( - f"developer {developer_obj} use_number+1 now {developer_obj.use_number} udid {self.udid_info.get('udid')} app_id {self.app_obj}") - developer_obj.save(update_fields=['use_number']) - - if not appsupersign_obj.filter(app_id=self.app_obj, user_id=self.user_obj).first(): - APPSuperSignUsedInfo.objects.create(app_id=self.app_obj, user_id=self.user_obj, - developerid=self.developer_obj, - udid=AppUDID.objects.filter(app_id=self.app_obj, - udid=self.udid_info.get('udid')).first()) + udid_obj = AppUDID.objects.filter(app_id=self.app_obj, udid=self.udid_info.get('udid')).first() + APPSuperSignUsedInfo.objects.update_or_create(app_id=self.app_obj, + user_id=self.user_obj, + developerid=self.developer_obj, + udid=udid_obj) def update_sign_data(self, random_file_name, release_obj): newdata = { @@ -530,7 +525,7 @@ class IosUtils(object): "call_loop download_profile appid:%s developer:%s count:%s" % (self.app_obj, self.developer_obj, count)) if self.developer_obj: with cache.lock("%s_%s_%s" % ('download_profile', self.app_obj.app_id, self.developer_obj.issuer_id), - timeout=60): + timeout=180): download_flag, result = IosUtils.exec_download_profile(self.app_obj, self.developer_obj, self.udid_info, sign_try_attempts) if download_flag: @@ -609,10 +604,6 @@ class IosUtils(object): app_api_obj.set_device_status("disable", udid_obj.udid) UDIDsyncDeveloper.objects.filter(udid=udid_obj.udid, developerid=developer_obj).delete() - if developer_obj.use_number > 0: - developer_obj.use_number = developer_obj.use_number - 1 - developer_obj.save(update_fields=['use_number']) - udid_obj.delete() @staticmethod @@ -679,12 +670,6 @@ class IosUtils(object): new_full_path = os.path.join(os.path.dirname(new_full_path_dir), '%s_%s_%s' % ('remove', new_full_path_name, get_format_time())) os.rename(new_full_path_dir, new_full_path) - # for root, dirs, files in os.walk(full_path, topdown=False): - # for name in files: - # os.remove(os.path.join(root, name)) - # for name in dirs: - # os.rmdir(os.path.join(root, name)) - # os.rmdir(full_path) except Exception as e: logger.error("clean_developer developer_obj:%s user_obj:%s delete file failed Exception:%s" % ( developer_obj, user_obj, e)) @@ -777,54 +762,34 @@ class IosUtils(object): return status, result @staticmethod - def get_device_from_developer(developer_obj, user_obj): + def get_device_from_developer(developer_obj): auth = get_auth_form_developer(developer_obj) app_api_obj = get_api_obj(auth) status, result = app_api_obj.get_device() - if status: - if auth.get("issuer_id"): - UDIDsyncDeveloper.objects.filter(developerid=developer_obj, platform=1).delete() - for device_obj in result: - device = { - "serial": device_obj.id, - "product": device_obj.name, - "udid": device_obj.udid, - "version": device_obj.model, - "platform": 1 - } - app_udid_obj = UDIDsyncDeveloper.objects.filter(developerid=developer_obj, udid=device.get("udid")) - if app_udid_obj: - pass - else: - UDIDsyncDeveloper.objects.create(developerid=developer_obj, **device) - else: + if status and auth.get("issuer_id"): + + udid_developer_obj_list = UDIDsyncDeveloper.objects.filter(developerid=developer_obj).values_list('udid') + udid_developer_list = [x[0] for x in udid_developer_obj_list if len(x) > 0] + udid_result_list = [device.udid for device in result] + + will_del_udid_list = list(set(udid_developer_list) - set(udid_result_list)) + + for device_obj in result: + device = { + "serial": device_obj.id, + "product": device_obj.name, + "udid": device_obj.udid, + "version": device_obj.model, + "platform": 1 + } + obj, create = UDIDsyncDeveloper.objects.update_or_create(developerid=developer_obj, + udid=device_obj.udid, defaults=device) + if not create: + DeveloperDevicesID.objects.filter(udid=obj, developerid=developer_obj).update( + **{'did': device_obj.id}) + AppUDID.objects.filter(udid__in=will_del_udid_list, + app_id__developerdevicesid__udid__in=UDIDsyncDeveloper.objects.filter( + udid__in=will_del_udid_list)).delete() + UDIDsyncDeveloper.objects.filter(udid__in=will_del_udid_list).delete() - file_format_path_name = file_format_path(user_obj, auth) - devices_info = "" - try: - with open(file_format_path_name + ".devices.info", "r") as f: - devices_info = f.read().replace("\n\t", "").replace("[", "").replace("]", "") - except Exception as e: - logger.error( - "get_device_from_developer developer_obj:%s user_obj:%s delete file failed Exception:%s" % ( - developer_obj, user_obj, e)) - - UDIDsyncDeveloper.objects.filter(developerid=developer_obj, platform=1).delete() - for devicestr in devices_info.split(">"): - formatdevice = re.findall(r'.*Device id="(.*)",.*name="(.*)",.*udid="(.*?)",.*model=(.*),.*', - devicestr) - if formatdevice: - device = { - "serial": formatdevice[0][0], - "product": formatdevice[0][1], - "udid": formatdevice[0][2], - "version": formatdevice[0][3], - "platform": 1 - } - app_udid_obj = UDIDsyncDeveloper.objects.filter(developerid=developer_obj, - udid=device.get("udid")) - if app_udid_obj: - pass - else: - UDIDsyncDeveloper.objects.create(developerid=developer_obj, **device) return status, result diff --git a/fir_ser/api/utils/serializer.py b/fir_ser/api/utils/serializer.py index f2a807e..75bddd1 100644 --- a/fir_ser/api/utils/serializer.py +++ b/fir_ser/api/utils/serializer.py @@ -404,6 +404,7 @@ class DeveloperSerializer(serializers.ModelSerializer): developer_used_number = serializers.SerializerMethodField() developer_used_other_number = serializers.SerializerMethodField() + use_number = serializers.SerializerMethodField() def get_developer_used_number(self, obj): return models.UDIDsyncDeveloper.objects.filter(developerid=obj).count() @@ -411,6 +412,9 @@ class DeveloperSerializer(serializers.ModelSerializer): def get_developer_used_other_number(self, obj): return get_developer_udided(obj)[0] + def get_use_number(self, obj): + return models.DeveloperDevicesID.objects.filter(developerid=obj).count() + class AdminDeveloperSerializer(DeveloperSerializer): class Meta: diff --git a/fir_ser/api/utils/utils.py b/fir_ser/api/utils/utils.py index d3b09e6..194fde9 100644 --- a/fir_ser/api/utils/utils.py +++ b/fir_ser/api/utils/utils.py @@ -7,7 +7,7 @@ import os, datetime, random import binascii from fir_ser.settings import SERVER_DOMAIN, CAPTCHA_LENGTH, MEDIA_ROOT, CACHE_KEY_TEMPLATE from api.models import APPSuperSignUsedInfo, APPToDeveloper, \ - UDIDsyncDeveloper, UserInfo, AppReleaseInfo, AppScreenShot, Token + UDIDsyncDeveloper, UserInfo, AppReleaseInfo, AppScreenShot, Token, DeveloperDevicesID from api.utils.storage.caches import get_app_d_count_by_app_id from api.utils.storage.localApi import LocalStorage from api.utils.storage.storage import Storage @@ -36,8 +36,8 @@ def delete_app_to_dev_and_file(developer_obj, app_id): def get_developer_udided(developer_obj): - super_sing_used_obj = APPSuperSignUsedInfo.objects.filter(developerid=developer_obj) - udid_sync_developer_obj = UDIDsyncDeveloper.objects.filter(developerid=developer_obj) + super_sing_used_obj = APPSuperSignUsedInfo.objects.filter(developerid=developer_obj).all() + udid_sync_developer_obj = UDIDsyncDeveloper.objects.filter(developerid=developer_obj).all() develoer_udid_lists = [] supersign_udid_lists = [] if udid_sync_developer_obj: @@ -55,16 +55,19 @@ def get_developer_devices(developer_obj_lists): other_used_sum += other_used flyapp_used_sum += flyapp_used - use_number_obj = developer_obj_lists.filter(is_actived=True) - if use_number_obj: - use_number_dict = use_number_obj.aggregate(usable_number=Sum('usable_number'), use_number=Sum('use_number')) - use_num = { - "all_usable_number": use_number_dict.get("usable_number", 0), - "all_use_number": use_number_dict.get("use_number", 0), - "other_used_sum": other_used_sum, - "flyapp_used_sum": flyapp_used_sum, - } - return use_num + use_number_obj_list = developer_obj_lists.filter(is_actived=True) + all_use_number = 0 + all_usable_number = 0 + for use_number_obj in use_number_obj_list: + all_usable_number += use_number_obj.usable_number + all_use_number += DeveloperDevicesID.objects.filter(developerid=use_number_obj).count() + use_num = { + "all_usable_number": all_usable_number, + "all_use_number": all_use_number, + "other_used_sum": other_used_sum, + "flyapp_used_sum": flyapp_used_sum, + } + return use_num def get_captcha(): diff --git a/fir_ser/api/views/supersign.py b/fir_ser/api/views/supersign.py index 3527ff0..aad992b 100644 --- a/fir_ser/api/views/supersign.py +++ b/fir_ser/api/views/supersign.py @@ -69,7 +69,7 @@ class DeveloperView(APIView): status, result = IosUtils.active_developer(developer_obj) if status: if not developer_obj.certid: - IosUtils.get_device_from_developer(developer_obj, request.user) + IosUtils.get_device_from_developer(developer_obj) return self.get(request) else: res.code = 1008 @@ -80,7 +80,7 @@ class DeveloperView(APIView): if not developer_obj.certid: status, result = IosUtils.create_developer_cert(developer_obj, request.user) if status: - IosUtils.get_device_from_developer(developer_obj, request.user) + IosUtils.get_device_from_developer(developer_obj) else: res.code = 1008 res.msg = result.get("err_info") @@ -104,7 +104,7 @@ class DeveloperView(APIView): res.msg = result.get("err_info", '') return Response(res.dict) elif act == "syncdevice": - status, result = IosUtils.get_device_from_developer(developer_obj, request.user) + status, result = IosUtils.get_device_from_developer(developer_obj) if not status: res.code = 1008 res.msg = result.get("err_info")