增加日志逻辑

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. 19
      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. 7
      fir_ser/api/utils/utils.py
  14. 2
      fir_ser/api/views/apps.py
  15. 9
      fir_ser/api/views/download.py
  16. 1
      fir_ser/api/views/logout.py
  17. 7
      fir_ser/api/views/receiveudids.py
  18. 11
      fir_ser/api/views/storage.py
  19. 9
      fir_ser/api/views/supersign.py
  20. 18
      fir_ser/api/views/uploads.py
  21. 5
      fir_ser/fir_ser/settings.py

@ -9,6 +9,9 @@ import random
import time
from django.core.cache import cache
from fir_ser.settings import CACHE_KEY_TEMPLATE
import logging
logger = logging.getLogger(__file__)
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 = cache.get(token_key)
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
else:
random_str = uuid.uuid1().__str__().split("-")[0:-1]
@ -28,17 +33,21 @@ class DownloadToken(object):
"data": release_id
}, time_limit)
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
def verify_token(self, token, release_id):
try:
values = cache.get(token)
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
except Exception as e:
print(e)
logger.error("verify_token token:%s release_id:%s failed Exception:%s" % (token, release_id, e))
return False
logger.error("verify_token token:%s release_id:%s failed" % (token, release_id))
return False

@ -9,7 +9,9 @@ import random
from api.utils.storage.storage import Storage
from api.utils.storage.caches import del_cache_response_by_short
import logging
logger=logging.getLogger(__file__)
logger = logging.getLogger(__file__)
def make_resigned(bin_url, img_url, bundle_id, app_version, name):
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:
appmobj = Apps.objects.create(**appdata)
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
else:
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.save()
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.name = appinfo["labelname"]
appmobj.save()
@ -164,13 +166,15 @@ def SaveAppInfos(app_file_name, user_obj, appinfo, bundle_id, app_img, short, si
except Exception as e:
logging.error("create app release failed,release_data:%s Exception:%s" % (release_data, e))
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()
return False
try:
history_release_limit = int(user_obj.history_release_limit)
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
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:
flag += 1
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.icon_url)
release_obj.delete()

@ -9,8 +9,10 @@ from fir_ser.settings import SUPER_SIGN_ROOT
import os
from api.utils.app.randomstrings import make_app_uuid
import logging
logger = logging.getLogger(__file__)
def exec_shell(cmd, remote=False, timeout=None):
if remote:
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)
return result
else:
logger.info("exec_shell cmd:%s"%(cmd))
logger.info("exec_shell cmd:%s" % (cmd))
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:
err_info = result.get("err_info", None)
if err_info:
@ -46,11 +48,11 @@ class AppDeveloperApi(object):
def active(self, user_obj):
self.cmd = self.cmd + " active "
logger.info("ios developer active cmd:%s"%(self.cmd))
logger.info("ios developer active cmd:%s" % (self.cmd))
result = {}
try:
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:
return True, result
except Exception as e:

@ -10,8 +10,10 @@ import paramiko, json
import socket
import pexpect
from api.utils.storage.caches import developer_auth_code
logger = logging.getLogger(__file__)
def default_result():
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)
return result
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)
result['exit_code'] = 0
result['return_info'] = 'Success'
@ -182,7 +185,7 @@ def use_user_pass(hostip, port, user, passwd, cmdstrs):
result['return_info'] = outs
result['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']))
conn.close()
return result

@ -4,7 +4,7 @@
# author: liuyu
# 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 api.utils.app.iossignapi import AppDeveloperApi, ResignApp
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.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
logger=logging.getLogger(__file__)
logger = logging.getLogger(__file__)
def udid_bytes_to_dict(xml_stream):
new_uuid_info = {}
@ -25,7 +27,8 @@ def udid_bytes_to_dict(xml_stream):
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]
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
@ -340,7 +343,8 @@ class IosUtils(object):
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))
logger.error("clean_developer developer_obj:%s user_obj:%s delete file failed Exception:%s" % (
developer_obj, user_obj, e))
@staticmethod
def active_developer(developer_obj, user_obj):
@ -379,7 +383,7 @@ class IosUtils(object):
cert_info = f.read()
except Exception as e:
logger.error("create_developer_cert developer_obj:%s user_obj:%s delete file failed Exception:%s" % (
developer_obj, user_obj, e))
developer_obj, user_obj, e))
if cert_info:
cert_id = re.findall(r'.*\n\tid=(.*),.*', cert_info)[0].replace('"', '')
AppIOSDeveloperInfo.objects.filter(user_id=user_obj, email=auth.get("username")).update(is_actived=True,
@ -402,8 +406,9 @@ class IosUtils(object):
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))
logger.error(
"get_device_from_developer developer_obj:%s user_obj:%s delete file failed Exception:%s" % (
developer_obj, user_obj, e))
for devicestr in devices_info.split(">"):
formatdevice = re.findall(r'.*Device id="(.*)",.*name="(.*)",.*udid="(.*?)",.*model=(.*),.*', devicestr)

@ -9,6 +9,7 @@ from django_apscheduler.jobstores import DjangoJobStore, register_events, regist
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
import logging
logger = logging.getLogger(__file__)
import atexit
@ -47,7 +48,7 @@ try:
register_events(scheduler)
scheduler.start()
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()

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

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

@ -18,7 +18,7 @@ logger = logging.getLogger(__file__)
try:
from api.utils.crontab import run
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):

@ -10,6 +10,7 @@ from api.utils.TokenManager import DownloadToken
from fir_ser import settings
import os
import logging
logger = logging.getLogger(__file__)
@ -43,7 +44,7 @@ class LocalStorage(object):
os.remove(file)
return True
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
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))
return True
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

@ -30,7 +30,6 @@ class QiNiuOss(object):
}
# 3600为token过期时间,秒为单位。3600等于一小时
token = self.qiniu_obj.upload_token(self.bucket_name, name, expires, policy)
# print(token)
return token
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 django.core.cache import cache
import logging
logger=logging.getLogger(__file__)
logger = logging.getLogger(__file__)
class Storage(object):
@ -20,7 +21,7 @@ class Storage(object):
try:
self.storage = self.get_storage(user)
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
def get_upload_token(self, filename, expires=900):
@ -121,6 +122,7 @@ class Storage(object):
try:
additionalparameters = json.loads(storage_obj.additionalparameters)
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 = {}
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):
file = get_profile_full_path(developer_obj, app_obj)
try:
os.remove(get_profile_full_path(developer_obj, app_obj))
if os.path.isfile(file):
os.remove(get_profile_full_path(developer_obj, app_obj))
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):

@ -57,7 +57,7 @@ class AppsView(APIView):
if count_hits > 0:
logger.info(
"update user all_download_times old:%s now:%s" % (
count_hits, request.user.all_download_times))
count_hits, request.user.all_download_times))
UserInfo.objects.filter(pk=request.user.id).update(
all_download_times=count_hits)
else:

@ -17,8 +17,11 @@ from api.utils.storage.caches import get_app_instance_by_cache, get_download_url
import os
from rest_framework_extensions.cache.decorators import cache_response
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
import logging
logger = logging.getLogger(__file__)
class DownloadView(APIView):
@ -83,7 +86,7 @@ class DownloadView(APIView):
else:
response = FileResponse()
except Exception as e:
print(e)
logger.error("read %s failed Exception:%s" % (file_path, e))
response = FileResponse()
response['content_type'] = "application/octet-stream"
response['Content-Disposition'] = 'attachment; filename=' + filename
@ -132,7 +135,7 @@ class ShortDownloadView(APIView):
udid = time
if not udid:
udid = ""
logging.info("make cache_response release_id:%s udid:%s" % (release_id, udid))
return "_".join(
[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
class LogoutView(APIView):
authentication_classes = [ExpiringTokenAuthentication]

@ -7,7 +7,10 @@
from api.utils.app.supersignutils import udid_bytes_to_dict, get_redirect_server_domain, IosUtils
from api.models import Apps, AppUDID
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):
@ -32,5 +35,5 @@ class IosUDIDView(View):
return HttpResponsePermanentRedirect(
"%s/%s" % (server_domain, short))
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")))

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

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

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

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

Loading…
Cancel
Save