|
@@ -16,8 +16,6 @@ from Object.ResponseObject import ResponseObject
|
|
|
from Service.CommonService import CommonService
|
|
|
from Model.models import Equipment_Version, App_Info, AppSetModel, App_Colophon, Pc_Info
|
|
|
|
|
|
-LOGGER = logging.getLogger('info')
|
|
|
-
|
|
|
|
|
|
class VersionManagement(View):
|
|
|
def get(self, request, *args, **kwargs):
|
|
@@ -121,61 +119,55 @@ class VersionManagement(View):
|
|
|
return response.json(444)
|
|
|
|
|
|
try:
|
|
|
- with transaction.atomic():
|
|
|
- channel = int(channel)
|
|
|
- resolutionRatio = int(resolutionRatio)
|
|
|
- status = int(status)
|
|
|
- # 文件名为设备版本,最后一个'.'的前面为软件版本,后面为设备规格名称
|
|
|
- # V2.2.4.16E201252CA,软件版本:2.2.4,设备规格名称:16E201252CA
|
|
|
- # V1.7.2.36C11680X30411F000600000150001Z,软件版本:1.7.2,设备规格名称:36C11680X30411F000600000150001Z
|
|
|
- file_name = str(file) # 文件名
|
|
|
- # .img和.tar.gz文件
|
|
|
- file_type_index = file_name.find('.img')
|
|
|
- if file_type_index == -1:
|
|
|
- file_type_index = file_name.find('.tar')
|
|
|
- if file_type_index == -1:
|
|
|
- return response.json(903)
|
|
|
- logging.info('成功获取上传信息{}'.format(request_dict))
|
|
|
- version = file_name[:file_type_index] # 设备版本
|
|
|
- version_index = version.rindex('.')
|
|
|
- softwareVersion = version[1:version_index] # 软件版本
|
|
|
- code = version[version_index + 1:] # 设备规格名称
|
|
|
- chipModelList2Code = code[:4] # 主芯片
|
|
|
- type = code[8:10] # 设备机型
|
|
|
- companyCode = code[-1:] # 公司代码
|
|
|
- fileSize = file.size
|
|
|
- logging.info('成功获取上传内容{}'.format(request_dict))
|
|
|
- filePath = '/'.join(('static/otapack', mci, lang, file_name))
|
|
|
-
|
|
|
- # file_data = file.read()
|
|
|
- # fileMd5 = hashlib.md5(file_name).hexdigest()
|
|
|
- data_dict = {'mci': mci, 'lang': lang, 'ESN': ESN, 'max_ver': max_ver, 'channel': channel,
|
|
|
- 'resolutionRatio': resolutionRatio, 'Description': Description, 'status': status,
|
|
|
- 'version': version, 'softwareVersion': softwareVersion, 'code': code,
|
|
|
- 'chipModelList2Code': chipModelList2Code, 'type': type, 'companyCode': companyCode,
|
|
|
- 'fileSize': fileSize, 'filePath': filePath, 'fileMd5': file_name}
|
|
|
- # Equipment_Version表创建或更新数据
|
|
|
- equipment_version_qs = Equipment_Version.objects.filter(code=code, lang=lang)
|
|
|
- if not equipment_version_qs.exists():
|
|
|
- Equipment_Version.objects.create(eid=CommonService.getUserID(getUser=False, setOTAID=True), **data_dict)
|
|
|
- else:
|
|
|
- equipment_version_qs.update(**data_dict)
|
|
|
- logging.info('成功记录内容{}'.format(data_dict))
|
|
|
- # 上传文件到服务器
|
|
|
- upload_path = '/'.join((BASE_DIR, 'static/otapack', mci, lang)).replace('\\', '/') + '/'
|
|
|
- if not os.path.exists(upload_path): # 上传目录不存在则创建
|
|
|
- os.makedirs(upload_path)
|
|
|
- # 文件上传
|
|
|
- full_name = upload_path + file_name
|
|
|
- if os.path.exists(full_name): # 删除同名文件
|
|
|
- os.remove(full_name)
|
|
|
- with open(full_name, 'wb+') as write_file:
|
|
|
- for chunk in file.chunks():
|
|
|
- write_file.write(chunk)
|
|
|
- logging.info('成功上传文件到服务器{}'.format(upload_path))
|
|
|
- return response.json(0)
|
|
|
+ channel = int(channel)
|
|
|
+ resolutionRatio = int(resolutionRatio)
|
|
|
+ status = int(status)
|
|
|
+ # # 文件名为设备版本,最后一个'.'的前面为软件版本,后面为设备规格名称
|
|
|
+ # # V2.2.4.16E201252CA,软件版本:2.2.4,设备规格名称:16E201252CA
|
|
|
+ # # V1.7.2.36C11680X30411F000600000150001Z,软件版本:1.7.2,设备规格名称:36C11680X30411F000600000150001Z
|
|
|
+ file_name = str(file) # 文件名
|
|
|
+ # # .img和.tar.gz文件
|
|
|
+ # file_type_index = file_name.find('.img')
|
|
|
+ # if file_type_index == -1:
|
|
|
+ # file_type_index = file_name.find('.tar')
|
|
|
+ # if file_type_index == -1:
|
|
|
+ # return response.json(903)
|
|
|
+ # version = file_name[:file_type_index] # 设备版本
|
|
|
+ # version_index = version.rindex('.')
|
|
|
+ # softwareVersion = version[1:version_index] # 软件版本
|
|
|
+ # code = version[version_index + 1:] # 设备规格名称
|
|
|
+ # chipModelList2Code = code[:4] # 主芯片
|
|
|
+ # type = code[8:10] # 设备机型
|
|
|
+ # companyCode = code[-1:] # 公司代码
|
|
|
+ # fileSize = file.size
|
|
|
+ # filePath = '/'.join(('static/otapack', mci, lang, file_name))
|
|
|
+ #
|
|
|
+ # # file_data = file.read()
|
|
|
+ # # fileMd5 = hashlib.md5(file_name).hexdigest()
|
|
|
+ # data_dict = {'mci': mci, 'lang': lang, 'ESN': ESN, 'max_ver': max_ver, 'channel': channel,
|
|
|
+ # 'resolutionRatio': resolutionRatio, 'Description': Description, 'status': status,
|
|
|
+ # 'version': version, 'softwareVersion': softwareVersion, 'code': code,
|
|
|
+ # 'chipModelList2Code': chipModelList2Code, 'type': type, 'companyCode': companyCode,
|
|
|
+ # 'fileSize': fileSize, 'filePath': filePath, 'fileMd5': file_name}
|
|
|
+ # # Equipment_Version表创建或更新数据
|
|
|
+ # equipment_version_qs = Equipment_Version.objects.filter(code=code, lang=lang)
|
|
|
+ # if not equipment_version_qs.exists():
|
|
|
+ # Equipment_Version.objects.create(eid=CommonService.getUserID(getUser=False, setOTAID=True), **data_dict)
|
|
|
+ # else:
|
|
|
+ # equipment_version_qs.update(**data_dict)
|
|
|
+ # 上传文件到服务器
|
|
|
+ upload_path = '/'.join((BASE_DIR, 'static/otapack', mci, lang)).replace('\\', '/') + '/'
|
|
|
+ if not os.path.exists(upload_path): # 上传目录不存在则创建
|
|
|
+ os.makedirs(upload_path)
|
|
|
+ # 文件上传
|
|
|
+ full_name = upload_path + file_name
|
|
|
+ if os.path.exists(full_name): # 删除同名文件
|
|
|
+ os.remove(full_name)
|
|
|
+ with open(full_name, 'wb+') as write_file:
|
|
|
+ for chunk in file.chunks():
|
|
|
+ write_file.write(chunk)
|
|
|
+ return response.json(0)
|
|
|
except Exception as e:
|
|
|
- logging.info('上传异常{}'.format(e))
|
|
|
print(e)
|
|
|
return response.json(500, repr(e))
|
|
|
|