增加日志逻辑

super_signature
nineven 5 years ago
parent 9f21a2f51e
commit a1167f6303
  1. 13
      fir_ser/api/utils/TokenManager.py
  2. 17
      fir_ser/api/utils/app/apputils.py
  3. 10
      fir_ser/api/utils/app/iossignapi.py
  4. 7
      fir_ser/api/utils/app/shellcmds.py
  5. 15
      fir_ser/api/utils/app/supersignutils.py
  6. 3
      fir_ser/api/utils/crontab/run.py
  7. 6
      fir_ser/api/utils/crontab/sync_cache.py
  8. 5
      fir_ser/api/utils/middlewares.py
  9. 2
      fir_ser/api/utils/storage/caches.py
  10. 5
      fir_ser/api/utils/storage/localApi.py
  11. 1
      fir_ser/api/utils/storage/qiniuApi.py
  12. 8
      fir_ser/api/utils/storage/storage.py
  13. 5
      fir_ser/api/utils/utils.py
  14. 9
      fir_ser/api/views/download.py
  15. 1
      fir_ser/api/views/logout.py
  16. 7
      fir_ser/api/views/receiveudids.py
  17. 11
      fir_ser/api/views/storage.py
  18. 9
      fir_ser/api/views/supersign.py
  19. 16
      fir_ser/api/views/uploads.py
  20. 5
      fir_ser/fir_ser/settings.py

@ -9,6 +9,9 @@ import random
import time import time
from django.core.cache import cache from django.core.cache import cache
from fir_ser.settings import CACHE_KEY_TEMPLATE from fir_ser.settings import CACHE_KEY_TEMPLATE
import logging
logger = logging.getLogger(__file__)
class DownloadToken(object): class DownloadToken(object):
@ -17,6 +20,8 @@ class DownloadToken(object):
token_key = "_".join([key.lower(), CACHE_KEY_TEMPLATE.get("make_token_key"), release_id]) token_key = "_".join([key.lower(), CACHE_KEY_TEMPLATE.get("make_token_key"), release_id])
token = cache.get(token_key) token = cache.get(token_key)
if token and not force_new: if token and not force_new:
logger.debug("make_token cache exists get token:%s release_id:%s force_new:%s token_key:%s" % (
token, release_id, force_new, token_key))
return token return token
else: else:
random_str = uuid.uuid1().__str__().split("-")[0:-1] random_str = uuid.uuid1().__str__().split("-")[0:-1]
@ -28,17 +33,21 @@ class DownloadToken(object):
"data": release_id "data": release_id
}, time_limit) }, time_limit)
cache.set(token_key, token, time_limit - 1) cache.set(token_key, token, time_limit - 1)
logger.debug(
"make_token cache not exists get token:%s release_id:%s force_new:%s token_key:%s" % (
token, release_id, force_new, token_key))
return token return token
def verify_token(self, token, release_id): def verify_token(self, token, release_id):
try: try:
values = cache.get(token) values = cache.get(token)
if values and release_id in values.get("data", None): if values and release_id in values.get("data", None):
logger.debug("verify_token token:%s release_id:%s success" % (token, release_id))
return True return True
except Exception as e: except Exception as e:
print(e) logger.error("verify_token token:%s release_id:%s failed Exception:%s" % (token, release_id, e))
return False return False
logger.error("verify_token token:%s release_id:%s failed" % (token, release_id))
return False return False

@ -9,7 +9,9 @@ import random
from api.utils.storage.storage import Storage from api.utils.storage.storage import Storage
from api.utils.storage.caches import del_cache_response_by_short from api.utils.storage.caches import del_cache_response_by_short
import logging import logging
logger=logging.getLogger(__file__)
logger = logging.getLogger(__file__)
def make_resigned(bin_url, img_url, bundle_id, app_version, name): def make_resigned(bin_url, img_url, bundle_id, app_version, name):
ios_plist_tem = """<?xml version="1.0" encoding="UTF-8"?> ios_plist_tem = """<?xml version="1.0" encoding="UTF-8"?>
@ -128,7 +130,7 @@ def SaveAppInfos(app_file_name, user_obj, appinfo, bundle_id, app_img, short, si
try: try:
appmobj = Apps.objects.create(**appdata) appmobj = Apps.objects.create(**appdata)
except Exception as e: except Exception as e:
logger.error("create new app failed,appdata:%s Exception:%s"%(appdata,e)) logger.error("create new app failed,appdata:%s Exception:%s" % (appdata, e))
return False return False
else: else:
try: try:
@ -139,7 +141,7 @@ def SaveAppInfos(app_file_name, user_obj, appinfo, bundle_id, app_img, short, si
appmobj.bundle_id = bundle_id appmobj.bundle_id = bundle_id
appmobj.save() appmobj.save()
except Exception as e: except Exception as e:
logger.error("save app info failed,appmobj:%s Exception:%s"%(appmobj,e)) logger.error("save app info failed,appmobj:%s Exception:%s" % (appmobj, e))
appmobj.bundle_id = bundle_id appmobj.bundle_id = bundle_id
appmobj.name = appinfo["labelname"] appmobj.name = appinfo["labelname"]
appmobj.save() appmobj.save()
@ -164,13 +166,15 @@ def SaveAppInfos(app_file_name, user_obj, appinfo, bundle_id, app_img, short, si
except Exception as e: except Exception as e:
logging.error("create app release failed,release_data:%s Exception:%s" % (release_data, e)) logging.error("create app release failed,release_data:%s Exception:%s" % (release_data, e))
if newapp: if newapp:
logger.info("create app release failed,release_data:%s ,and app is new ,so delete this app:%s" % (release_data, appmobj)) logger.info("create app release failed,release_data:%s ,and app is new ,so delete this app:%s" % (
release_data, appmobj))
appmobj.delete() appmobj.delete()
return False return False
try: try:
history_release_limit = int(user_obj.history_release_limit) history_release_limit = int(user_obj.history_release_limit)
except Exception as e: except Exception as e:
logger.error("get history_release_limit failed,history_release_limit:%s Exception:%s" % (user_obj.history_release_limit, e)) logger.error("get history_release_limit failed,history_release_limit:%s Exception:%s" % (
user_obj.history_release_limit, e))
return True return True
if history_release_limit != 0: if history_release_limit != 0:
@ -180,7 +184,8 @@ def SaveAppInfos(app_file_name, user_obj, appinfo, bundle_id, app_img, short, si
for release_obj in release_queryset: for release_obj in release_queryset:
flag += 1 flag += 1
if flag > history_release_limit: if flag > history_release_limit:
logging.info("history_release_limit:%s this release is to more,so delete it release_id:%s"%(history_release_limit,release_obj.release_id)) logging.info("history_release_limit:%s this release is to more,so delete it release_id:%s" % (
history_release_limit, release_obj.release_id))
storage.delete_file(release_obj.release_id, appmobj.type) storage.delete_file(release_obj.release_id, appmobj.type)
storage.delete_file(release_obj.icon_url) storage.delete_file(release_obj.icon_url)
release_obj.delete() release_obj.delete()

@ -9,8 +9,10 @@ from fir_ser.settings import SUPER_SIGN_ROOT
import os import os
from api.utils.app.randomstrings import make_app_uuid from api.utils.app.randomstrings import make_app_uuid
import logging import logging
logger = logging.getLogger(__file__) logger = logging.getLogger(__file__)
def exec_shell(cmd, remote=False, timeout=None): def exec_shell(cmd, remote=False, timeout=None):
if remote: if remote:
hostip = "10.66.6.66" hostip = "10.66.6.66"
@ -20,9 +22,9 @@ def exec_shell(cmd, remote=False, timeout=None):
result = use_user_pass(hostip, port, user, passwd, cmd) result = use_user_pass(hostip, port, user, passwd, cmd)
return result return result
else: else:
logger.info("exec_shell cmd:%s"%(cmd)) logger.info("exec_shell cmd:%s" % (cmd))
result = shell_command(cmd, timeout) result = shell_command(cmd, timeout)
logger.info("exec_shell cmd:%s result:%s"%(cmd,result)) logger.info("exec_shell cmd:%s result:%s" % (cmd, result))
if result.get("exit_code") != 0: if result.get("exit_code") != 0:
err_info = result.get("err_info", None) err_info = result.get("err_info", None)
if err_info: if err_info:
@ -46,11 +48,11 @@ class AppDeveloperApi(object):
def active(self, user_obj): def active(self, user_obj):
self.cmd = self.cmd + " active " self.cmd = self.cmd + " active "
logger.info("ios developer active cmd:%s"%(self.cmd)) logger.info("ios developer active cmd:%s" % (self.cmd))
result = {} result = {}
try: try:
result = pshell_command(self.cmd, user_obj, self.username) result = pshell_command(self.cmd, user_obj, self.username)
logger.info("ios developer active cmd:%s result:%s" % (self.cmd ,result)) logger.info("ios developer active cmd:%s result:%s" % (self.cmd, result))
if result["exit_code"] == 0: if result["exit_code"] == 0:
return True, result return True, result
except Exception as e: except Exception as e:

@ -10,8 +10,10 @@ import paramiko, json
import socket import socket
import pexpect import pexpect
from api.utils.storage.caches import developer_auth_code from api.utils.storage.caches import developer_auth_code
logger = logging.getLogger(__file__) logger = logging.getLogger(__file__)
def default_result(): def default_result():
return {'exit_code': '99', 'return_info': 'Failed to run, function_name is not existed'} return {'exit_code': '99', 'return_info': 'Failed to run, function_name is not existed'}
@ -115,7 +117,8 @@ def pshell_command(cmdstrs, user_obj, developer_email, timeout=60 * 10):
developer_auth_code("del", user_obj, developer_email) developer_auth_code("del", user_obj, developer_email)
return result return result
except Exception as e: except Exception as e:
logger.error("cmdstrs:%s developer_email:%s user_obj:%s Exception:%s"%(cmdstrs,developer_email,user_obj,e)) logger.error("cmdstrs:%s developer_email:%s user_obj:%s Exception:%s" % (
cmdstrs, developer_email, user_obj, e))
developer_auth_code("del", user_obj, developer_email) developer_auth_code("del", user_obj, developer_email)
result['exit_code'] = 0 result['exit_code'] = 0
result['return_info'] = 'Success' result['return_info'] = 'Success'
@ -182,7 +185,7 @@ def use_user_pass(hostip, port, user, passwd, cmdstrs):
result['return_info'] = outs result['return_info'] = outs
result['exit_code'] = out['status'] result['exit_code'] = out['status']
# logging.info(u'shell: %s - %s%s - %s%d' % (cmdstrs, 'return_info: ', out, 'exit_code: ', out['status'])) # logging.info(u'shell: %s - %s%s - %s%d' % (cmdstrs, 'return_info: ', out, 'exit_code: ', out['status']))
print('host: %s user:%s - shell: %s - %s%s - %s%d' % ( logger.info('host: %s user:%s - shell: %s - %s%s - %s%d' % (
hostip, user, cmdstrs, 'return_info: ', out, 'exit_code: ', out['status'])) hostip, user, cmdstrs, 'return_info: ', out, 'exit_code: ', out['status']))
conn.close() conn.close()
return result return result

@ -4,7 +4,7 @@
# author: liuyu # author: liuyu
# date: 2020/3/6 # date: 2020/3/6
import uuid, xmltodict, os, re ,logging import uuid, xmltodict, os, re, logging
from fir_ser.settings import SUPER_SIGN_ROOT, MEDIA_ROOT, SERVER_DOMAIN from fir_ser.settings import SUPER_SIGN_ROOT, MEDIA_ROOT, SERVER_DOMAIN
from api.utils.app.iossignapi import AppDeveloperApi, ResignApp from api.utils.app.iossignapi import AppDeveloperApi, ResignApp
from api.models import APPSuperSignUsedInfo, AppUDID, AppIOSDeveloperInfo, AppReleaseInfo, Apps, APPToDeveloper, \ from api.models import APPSuperSignUsedInfo, AppUDID, AppIOSDeveloperInfo, AppReleaseInfo, Apps, APPToDeveloper, \
@ -14,7 +14,9 @@ from api.utils.serializer import get_developer_udided
from api.utils.storage.localApi import LocalStorage from api.utils.storage.localApi import LocalStorage
from api.utils.storage.caches import del_cache_response_by_short from api.utils.storage.caches import del_cache_response_by_short
from api.utils.utils import file_format_path, delete_app_to_dev_and_file, delete_app_profile_file from api.utils.utils import file_format_path, delete_app_to_dev_and_file, delete_app_profile_file
logger=logging.getLogger(__file__)
logger = logging.getLogger(__file__)
def udid_bytes_to_dict(xml_stream): def udid_bytes_to_dict(xml_stream):
new_uuid_info = {} new_uuid_info = {}
@ -25,7 +27,8 @@ def udid_bytes_to_dict(xml_stream):
for i in range(len(xml_dict['plist']['dict']['key'])): for i in range(len(xml_dict['plist']['dict']['key'])):
new_uuid_info[xml_dict['plist']['dict']['key'][i].lower()] = xml_dict['plist']['dict']['string'][i] new_uuid_info[xml_dict['plist']['dict']['key'][i].lower()] = xml_dict['plist']['dict']['string'][i]
except Exception as e: except Exception as e:
logger.error("udid_xml_stream:%s Exception:%s"%(xml_stream,e)) logger.error("udid_xml_stream:%s Exception:%s" % (xml_stream, e))
return None
return new_uuid_info return new_uuid_info
@ -340,7 +343,8 @@ class IosUtils(object):
os.rmdir(os.path.join(root, name)) os.rmdir(os.path.join(root, name))
os.rmdir(full_path) os.rmdir(full_path)
except Exception as e: except Exception as e:
logger.error("clean_developer developer_obj:%s user_obj:%s delete file failed Exception:%s"%(developer_obj,user_obj,e)) logger.error("clean_developer developer_obj:%s user_obj:%s delete file failed Exception:%s" % (
developer_obj, user_obj, e))
@staticmethod @staticmethod
def active_developer(developer_obj, user_obj): def active_developer(developer_obj, user_obj):
@ -402,7 +406,8 @@ class IosUtils(object):
with open(file_format_path_name + ".devices.info", "r") as f: with open(file_format_path_name + ".devices.info", "r") as f:
devices_info = f.read().replace("\n\t", "").replace("[", "").replace("]", "") devices_info = f.read().replace("\n\t", "").replace("[", "").replace("]", "")
except Exception as e: except Exception as e:
logger.error("get_device_from_developer developer_obj:%s user_obj:%s delete file failed Exception:%s" % ( logger.error(
"get_device_from_developer developer_obj:%s user_obj:%s delete file failed Exception:%s" % (
developer_obj, user_obj, e)) developer_obj, user_obj, e))
for devicestr in devices_info.split(">"): for devicestr in devices_info.split(">"):

@ -9,6 +9,7 @@ from django_apscheduler.jobstores import DjangoJobStore, register_events, regist
from fir_ser.settings import SYNC_CACHE_TO_DATABASE from fir_ser.settings import SYNC_CACHE_TO_DATABASE
from api.utils.crontab.sync_cache import sync_download_times, auto_clean_upload_tmp_file, auto_delete_job_log from api.utils.crontab.sync_cache import sync_download_times, auto_clean_upload_tmp_file, auto_delete_job_log
import logging import logging
logger = logging.getLogger(__file__) logger = logging.getLogger(__file__)
import atexit import atexit
@ -47,7 +48,7 @@ try:
register_events(scheduler) register_events(scheduler)
scheduler.start() scheduler.start()
except Exception as e: except Exception as e:
logger.error("scheduler failed,so shutdown it Exception:%s"%(e)) logger.error("scheduler failed,so shutdown it Exception:%s" % (e))
# 有错误就停止定时器 # 有错误就停止定时器
scheduler.shutdown() scheduler.shutdown()

@ -11,8 +11,10 @@ from fir_ser.settings import CACHE_KEY_TEMPLATE, SYNC_CACHE_TO_DATABASE
import time import time
from django_apscheduler.models import DjangoJobExecution from django_apscheduler.models import DjangoJobExecution
import logging import logging
logger = logging.getLogger(__file__) logger = logging.getLogger(__file__)
def sync_download_times(): def sync_download_times():
down_tem_key = CACHE_KEY_TEMPLATE.get("download_times_key") down_tem_key = CACHE_KEY_TEMPLATE.get("download_times_key")
key = "_".join([down_tem_key, '*']) key = "_".join([down_tem_key, '*'])
@ -20,7 +22,7 @@ def sync_download_times():
count_hits = cache.get(app_download) count_hits = cache.get(app_download)
app_id = app_download.split(down_tem_key)[1].strip('_') app_id = app_download.split(down_tem_key)[1].strip('_')
Apps.objects.filter(app_id=app_id).update(count_hits=count_hits) Apps.objects.filter(app_id=app_id).update(count_hits=count_hits)
logger.info("sync_download_times app_id:%s count_hits:%s"%(app_id,count_hits)) logger.info("sync_download_times app_id:%s count_hits:%s" % (app_id, count_hits))
def sync_download_times_by_app_id(app_ids): def sync_download_times_by_app_id(app_ids):
@ -32,7 +34,7 @@ def sync_download_times_by_app_id(app_ids):
for k, v in down_times_lists.items(): for k, v in down_times_lists.items():
app_id = k.split(CACHE_KEY_TEMPLATE.get("download_times_key"))[1].strip('_') app_id = k.split(CACHE_KEY_TEMPLATE.get("download_times_key"))[1].strip('_')
Apps.objects.filter(app_id=app_id).update(count_hits=v) Apps.objects.filter(app_id=app_id).update(count_hits=v)
logger.info("sync_download_times_by_app_id app_id:%s count_hits:%s"%(app_id,v)) logger.info("sync_download_times_by_app_id app_id:%s count_hits:%s" % (app_id, v))
def auto_clean_upload_tmp_file(): def auto_clean_upload_tmp_file():

@ -1,4 +1,7 @@
from django.utils.deprecation import MiddlewareMixin from django.utils.deprecation import MiddlewareMixin
import logging
logger = logging.getLogger(__file__)
class CorsMiddleWare(MiddlewareMixin): class CorsMiddleWare(MiddlewareMixin):
@ -14,5 +17,5 @@ class CorsMiddleWare(MiddlewareMixin):
response["Cache-Control"] = "no-cache" response["Cache-Control"] = "no-cache"
except Exception as e: except Exception as e:
print(e) logger.error(e)
return response return response

@ -18,7 +18,7 @@ logger = logging.getLogger(__file__)
try: try:
from api.utils.crontab import run from api.utils.crontab import run
except Exception as e: except Exception as e:
logger.error("import crontab.run failed Exception:%s"%(e)) logger.error("import crontab.run failed Exception:%s" % (e))
def get_download_url_by_cache(app_obj, filename, limit, isdownload=True, key='', udid=None): def get_download_url_by_cache(app_obj, filename, limit, isdownload=True, key='', udid=None):

@ -10,6 +10,7 @@ from api.utils.TokenManager import DownloadToken
from fir_ser import settings from fir_ser import settings
import os import os
import logging import logging
logger = logging.getLogger(__file__) logger = logging.getLogger(__file__)
@ -43,7 +44,7 @@ class LocalStorage(object):
os.remove(file) os.remove(file)
return True return True
except Exception as e: except Exception as e:
logger.error("delete file %s failed Exception %s"%(file,e)) logger.error("delete file %s failed Exception %s" % (file, e))
return False return False
def rename_file(self, oldfilename, newfilename): def rename_file(self, oldfilename, newfilename):
@ -51,5 +52,5 @@ class LocalStorage(object):
os.rename(os.path.join(settings.MEDIA_ROOT, oldfilename), os.path.join(settings.MEDIA_ROOT, newfilename)) os.rename(os.path.join(settings.MEDIA_ROOT, oldfilename), os.path.join(settings.MEDIA_ROOT, newfilename))
return True return True
except Exception as e: except Exception as e:
logger.error("rename_file file %s to %s failed Exception %s" % (oldfilename,newfilename, e)) logger.error("rename_file file %s to %s failed Exception %s" % (oldfilename, newfilename, e))
return False return False

@ -30,7 +30,6 @@ class QiNiuOss(object):
} }
# 3600为token过期时间,秒为单位。3600等于一小时 # 3600为token过期时间,秒为单位。3600等于一小时
token = self.qiniu_obj.upload_token(self.bucket_name, name, expires, policy) token = self.qiniu_obj.upload_token(self.bucket_name, name, expires, policy)
# print(token)
return token return token
def get_download_url(self, name, expires=1800, force_new=False): def get_download_url(self, name, expires=1800, force_new=False):

@ -12,7 +12,8 @@ import json, time, base64
from fir_ser.settings import THIRD_PART_CONFIG, CACHE_KEY_TEMPLATE from fir_ser.settings import THIRD_PART_CONFIG, CACHE_KEY_TEMPLATE
from django.core.cache import cache from django.core.cache import cache
import logging import logging
logger=logging.getLogger(__file__)
logger = logging.getLogger(__file__)
class Storage(object): class Storage(object):
@ -20,7 +21,7 @@ class Storage(object):
try: try:
self.storage = self.get_storage(user) self.storage = self.get_storage(user)
except Exception as e: except Exception as e:
logger.error("get %s storage failed Exception:%s"%(user,e)) logger.error("get %s storage failed Exception:%s" % (user, e))
self.storage = None self.storage = None
def get_upload_token(self, filename, expires=900): def get_upload_token(self, filename, expires=900):
@ -121,6 +122,7 @@ class Storage(object):
try: try:
additionalparameters = json.loads(storage_obj.additionalparameters) additionalparameters = json.loads(storage_obj.additionalparameters)
except Exception as e: except Exception as e:
logger.error("%s get_storage_auth additionalparameters %s loads failed Exception:%s"%(storage_obj.user_id,storage_obj.additionalparameters,e)) logger.error("%s get_storage_auth additionalparameters %s loads failed Exception:%s" % (
storage_obj.user_id, storage_obj.additionalparameters, e))
additionalparameters = {} additionalparameters = {}
return {**auth_dict, **additionalparameters} return {**auth_dict, **additionalparameters}

@ -46,10 +46,13 @@ def delete_app_to_dev_and_file(developer_obj, app_id):
def delete_app_profile_file(developer_obj, app_obj): def delete_app_profile_file(developer_obj, app_obj):
file = get_profile_full_path(developer_obj, app_obj)
try: try:
if os.path.isfile(file):
os.remove(get_profile_full_path(developer_obj, app_obj)) os.remove(get_profile_full_path(developer_obj, app_obj))
except Exception as e: except Exception as e:
print(e) logger.error("delete_app_profile_file developer_obj:%s app_obj:%s file:%s Exception:%s" % (
developer_obj, app_obj, file, e))
def get_developer_udided(developer_obj): def get_developer_udided(developer_obj):

@ -17,8 +17,11 @@ from api.utils.storage.caches import get_app_instance_by_cache, get_download_url
import os import os
from rest_framework_extensions.cache.decorators import cache_response from rest_framework_extensions.cache.decorators import cache_response
from api.utils.serializer import AppsShortSerializer from api.utils.serializer import AppsShortSerializer
from api.models import Apps, AppReleaseInfo, APPToDeveloper, APPSuperSignUsedInfo from api.models import Apps, AppReleaseInfo, APPToDeveloper
from django.http import FileResponse from django.http import FileResponse
import logging
logger = logging.getLogger(__file__)
class DownloadView(APIView): class DownloadView(APIView):
@ -83,7 +86,7 @@ class DownloadView(APIView):
else: else:
response = FileResponse() response = FileResponse()
except Exception as e: except Exception as e:
print(e) logger.error("read %s failed Exception:%s" % (file_path, e))
response = FileResponse() response = FileResponse()
response['content_type'] = "application/octet-stream" response['content_type'] = "application/octet-stream"
response['Content-Disposition'] = 'attachment; filename=' + filename response['Content-Disposition'] = 'attachment; filename=' + filename
@ -132,7 +135,7 @@ class ShortDownloadView(APIView):
udid = time udid = time
if not udid: if not udid:
udid = "" udid = ""
logging.info("make cache_response release_id:%s udid:%s" % (release_id, udid))
return "_".join( return "_".join(
[settings.CACHE_KEY_TEMPLATE.get("download_short_key"), kwargs.get("short", ''), release_id, udid]) [settings.CACHE_KEY_TEMPLATE.get("download_short_key"), kwargs.get("short", ''), release_id, udid])

@ -5,7 +5,6 @@ from django.core.cache import cache
from rest_framework.response import Response from rest_framework.response import Response
class LogoutView(APIView): class LogoutView(APIView):
authentication_classes = [ExpiringTokenAuthentication] authentication_classes = [ExpiringTokenAuthentication]

@ -7,7 +7,10 @@
from api.utils.app.supersignutils import udid_bytes_to_dict, get_redirect_server_domain, IosUtils from api.utils.app.supersignutils import udid_bytes_to_dict, get_redirect_server_domain, IosUtils
from api.models import Apps, AppUDID from api.models import Apps, AppUDID
from django.views import View from django.views import View
from django.http import HttpResponsePermanentRedirect, Http404 from django.http import HttpResponsePermanentRedirect
import logging
logger = logging.getLogger(__file__)
class IosUDIDView(View): class IosUDIDView(View):
@ -32,5 +35,5 @@ class IosUDIDView(View):
return HttpResponsePermanentRedirect( return HttpResponsePermanentRedirect(
"%s/%s" % (server_domain, short)) "%s/%s" % (server_domain, short))
except Exception as e: except Exception as e:
print(e) logger.error("short %s receive udid Exception:%s" % (short, e))
return HttpResponsePermanentRedirect("%s/%s?udid=%s" % (server_domain, short, format_udid_info.get("udid"))) return HttpResponsePermanentRedirect("%s/%s?udid=%s" % (server_domain, short, format_udid_info.get("udid")))

@ -12,6 +12,9 @@ import json
from api.utils.storage.caches import del_cache_storage from api.utils.storage.caches import del_cache_storage
from api.models import AppStorage, UserInfo from api.models import AppStorage, UserInfo
from api.utils.serializer import StorageSerializer from api.utils.serializer import StorageSerializer
import logging
logger = logging.getLogger(__file__)
class StorageView(APIView): class StorageView(APIView):
@ -56,7 +59,8 @@ class StorageView(APIView):
try: try:
data['additionalparameters'] = json.dumps(data.get('additionalparameter', '')) data['additionalparameters'] = json.dumps(data.get('additionalparameter', ''))
except Exception as e: except Exception as e:
print(e) logger.error("user:%s additionalparameters %s dumps failed Exception:%s" % (
request.user, data.get('additionalparameter', ''), e))
serializer = StorageSerializer(data=data, context={'user_obj': request.user}) serializer = StorageSerializer(data=data, context={'user_obj': request.user})
if serializer.is_valid(): if serializer.is_valid():
@ -81,7 +85,7 @@ class StorageView(APIView):
UserInfo.objects.filter(pk=request.user.pk).update(storage_id=use_storage_id) UserInfo.objects.filter(pk=request.user.pk).update(storage_id=use_storage_id)
del_cache_storage(request.user) del_cache_storage(request.user)
except Exception as e: except Exception as e:
print(e) logger.error("update user %s storage failed Exception:%s" % (request.user, e))
res.code = 1006 res.code = 1006
res.msg = '修改失败' res.msg = '修改失败'
return Response(res.dict) return Response(res.dict)
@ -89,7 +93,8 @@ class StorageView(APIView):
try: try:
data['additionalparameters'] = json.dumps(data.get('additionalparameter', '')) data['additionalparameters'] = json.dumps(data.get('additionalparameter', ''))
except Exception as e: except Exception as e:
print(e) logger.error("user:%s additionalparameters %s dumps failed Exception:%s" % (
request.user, data.get('additionalparameter', ''), e))
storage_id = data.get("id", None) storage_id = data.get("id", None)
if storage_id: if storage_id:

@ -14,6 +14,9 @@ from rest_framework.pagination import PageNumberPagination
from api.utils.app.supersignutils import IosUtils from api.utils.app.supersignutils import IosUtils
from api.utils.utils import get_developer_devices from api.utils.utils import get_developer_devices
from api.utils.storage.caches import developer_auth_code from api.utils.storage.caches import developer_auth_code
import logging
logger = logging.getLogger(__file__)
class AppsPageNumber(PageNumberPagination): class AppsPageNumber(PageNumberPagination):
@ -109,7 +112,8 @@ class DeveloperView(APIView):
if usable_number >= 0 and usable_number <= 100: if usable_number >= 0 and usable_number <= 100:
developer_obj.usable_number = usable_number developer_obj.usable_number = usable_number
except Exception as e: except Exception as e:
print(e) logger.error("developer %s usable_number %s get failed Exception:%s" % (
developer_obj, data.get("usable_number", developer_obj.usable_number), e))
developer_obj.description = data.get("description", developer_obj.description) developer_obj.description = data.get("description", developer_obj.description)
password = data.get("password", developer_obj.password) password = data.get("password", developer_obj.password)
if password != "" and password != developer_obj.password: if password != "" and password != developer_obj.password:
@ -130,7 +134,8 @@ class DeveloperView(APIView):
try: try:
AppIOSDeveloperInfo.objects.create(user_id=request.user, **datainfo) AppIOSDeveloperInfo.objects.create(user_id=request.user, **datainfo)
except Exception as e: except Exception as e:
print(e) logger.error("user %s create developer %s failed Exception:%s" % (
request.user, datainfo, e))
res = BaseResponse() res = BaseResponse()
res.code = 1005 res.code = 1005
res.msg = "添加失败" res.msg = "添加失败"

@ -16,7 +16,9 @@ from api.utils.app.randomstrings import make_from_user_uuid
from rest_framework.response import Response from rest_framework.response import Response
from fir_ser import settings from fir_ser import settings
from api.utils.TokenManager import DownloadToken from api.utils.TokenManager import DownloadToken
import os, json import os, json, logging
logger = logging.getLogger(__file__)
class AppAnalyseView(APIView): class AppAnalyseView(APIView):
@ -113,7 +115,7 @@ class AppAnalyseView(APIView):
upload_file_tmp_name("del", png_tmp_filename, request.user.id) upload_file_tmp_name("del", png_tmp_filename, request.user.id)
except Exception as e: except Exception as e:
print(e) logger.error("%s %s save app info failed Exception:%s" % (request.user, data.get("bundleid"), e))
res.code = 10003 res.code = 10003
return Response(res.dict) return Response(res.dict)
@ -180,7 +182,7 @@ class UploadView(APIView):
res.code = 1006 res.code = 1006
return Response(res.dict) return Response(res.dict)
except Exception as e: except Exception as e:
print(e) logger.error("%s certinfo:%s get failed Exception:%s" % (request.user, certinfo, e))
res.msg = "token 校验失败" res.msg = "token 校验失败"
res.code = 1006 res.code = 1006
return Response(res.dict) return Response(res.dict)
@ -216,9 +218,10 @@ class UploadView(APIView):
if app_type == "tmp": if app_type == "tmp":
app_type = file_obj.name.split(".")[-2] app_type = file_obj.name.split(".")[-2]
if app_type not in ["apk", "ipa", 'png', 'jpeg', 'jpg']: if app_type not in ["apk", "ipa", 'png', 'jpeg', 'jpg']:
logger.error("user:%s upload file type error file:%s " % (request.user, file_obj.name))
raise TypeError raise TypeError
except Exception as e: except Exception as e:
print(e) logger.error("user:%s upload file type error Exception:%s " % (request.user, e))
res.code = 1003 res.code = 1003
res.msg = "错误的类型" res.msg = "错误的类型"
return Response(res.dict) return Response(res.dict)
@ -233,13 +236,14 @@ class UploadView(APIView):
destination.close() destination.close()
except Exception as e: except Exception as e:
print(e) logger.error("user:%s save file:%s error Exception:%s " % (request.user, local_file, e))
res.code = 1003 res.code = 1003
res.msg = "数据写入失败" res.msg = "数据写入失败"
try: try:
if os.path.isfile(local_file):
os.remove(local_file) os.remove(local_file)
except Exception as e: except Exception as e:
print(e) logger.error("user:%s delete file:%s error Exception:%s " % (request.user, local_file, e))
return Response(res.dict) return Response(res.dict)
else: else:
res.msg = "token 校验失败" res.msg = "token 校验失败"

@ -279,9 +279,6 @@ LOGGING = {
'simple': { 'simple': {
'format': '[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s' 'format': '[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s'
}, },
'collect': {
'format': '%(message)s'
}
}, },
'filters': { 'filters': {
'require_debug_true': { 'require_debug_true': {
@ -290,7 +287,7 @@ LOGGING = {
}, },
'handlers': { 'handlers': {
'console': { 'console': {
'level': 'DEBUG', 'level': 'INFO',
'filters': ['require_debug_true'], # 只有在Django debug为True时才在屏幕打印日志 'filters': ['require_debug_true'], # 只有在Django debug为True时才在屏幕打印日志
'class': 'logging.StreamHandler', 'class': 'logging.StreamHandler',
'formatter': 'simple' 'formatter': 'simple'

Loading…
Cancel
Save