Commit 6c65e5d9 authored by 张永's avatar 张永

fix

parent 19754200
......@@ -4,6 +4,7 @@ from helios.rpc.exceptions import RPCFaultException
from utils.base import APIView
from utils.channel_package_tools import ChannelPackage
from utils.logger import error_logger
from utils.channel_task import version_release_task
class Vendor(APIView):
......@@ -15,10 +16,10 @@ class Vendor(APIView):
"""
query = request.GET.get('q', '')
page = int(request.GET.get('page', 1))
limit = int(request.GET.get('limit', 30))
offset = int(request.GET.get('offset', 30))
data = request.rpc.origin['endpoint'](
query=query, page=page, limit=limit,
query=query, start=(page - 1) * offset, offset=offset
).unwrap()
return data
......@@ -31,10 +32,12 @@ class ChannelList(APIView):
:return:
"""
page = int(request.GET.get('page', 1))
limit = int(request.GET.get('limit', 10))
offset = int(request.GET.get('limit', 10))
filters = self.handle_filter(request.GET.get('filter', ""))
try:
channel_list = self.rpc['endpoint'](offset=(page - 1) * limit, limit=limit, filters=filters).unwrap()
channel_list = self.rpc['endpoint'](
start=(page - 1) * offset, offset=offset, filters=filters
).unwrap()
except Exception as e:
error_logger.error(u'获取渠道列表失败:%s', e)
raise e
......@@ -99,6 +102,7 @@ class Channel(APIView):
).unwrap()
except RPCFaultException as e:
raise e
return self.write_success(message='操作成功', data={})
else: # 创建渠道信息
try:
self.rpc['endpoint'](
......@@ -106,6 +110,7 @@ class Channel(APIView):
).unwrap()
except RPCFaultException as e:
raise e
return self.write_success(message='操作成功', data={})
class ChannelPacked(APIView):
......@@ -147,13 +152,133 @@ class ChannelPacked(APIView):
error_logger.error(u'参数不完整')
return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整')
version2channel = self.rpc['endpoint'](id=version2channel_id).unwrap() # get
# get version-channel object
version2channel = self.rpc['endpoint'](id=version2channel_id).unwrap()
version = version2channel['version']
channel = version2channel['channel']
ChannelPackage.publish_apk(channel, version)
try:
self.rpc['endpoint'](id=version2channel_id).unwrap() # edit
self.rpc['endpoint'](id=version2channel_id).unwrap() #发布完成 修改状态
except RPCFaultException as e:
error_logger.error(u'获取渠道打包列表失败:%s', e)
error_logger.error(u'发布失败:%s', e)
return self.write_fail(code=-1, message='发布失败!')
return self.write_success(data={}, message='发布成功!')
class VersionPackedChannel(APIView):
def get(self, request):
"""
当前版本所有已打包渠道列表
:param request:
:return:
"""
version_id = request.GET.get('version__id', '')
page = int(request.GET.get('page', 1))
offset = int(request.GET.get('offset', 10))
if version_id:
version = self.rpc['endpoint'](version_id=version_id).unwrap()
# 母包地址 由七牛上传返回
base_apk_url = ChannelPackage.apk_url(channel='', version=version['version'])
else:
base_apk_url = ''
version = {}
version2channels = self.rpc['endpoint'](
version_id=version, start=(page - 1) * offset, offset=offset).unwrap()
data = {
'version': [{
'version': item.get('version'),
'name': item.get('name'),
'packed_time': item.get('packed_time'),
'download_url': '',
'release_time': item.get('release_time'),
'is_released': item.get('is_released'),
} for item in version2channels],
'base_apk_url': base_apk_url,
}
return self.write_success(data=data)
class VersionList(APIView):
def get(self, request):
"""
所有版本列表
:param request:
:return:
"""
page = int(request.GET.get('page', 1))
offset = int(request.GET.get('offset', 10))
filters = self.handle_filter(request.GET.get('filter', ""))
try:
version_list = self.rpc['endpoint'](
start=(page - 1) * offset, offset=offset, filters=filters
).unwrap()
except Exception as e:
error_logger.error(u'获取版本列表失败:%s', e)
raise e
data = [
{
'version': item.get('version'),
'MD5': item.get('MD5'),
'release_time': item.get('release_time'),
} for item in version_list
]
return self.write_success(data=data)
class VersionDetailUpdate(APIView):
def get(self, request):
"""
版本详情
:param request:
:return:
"""
version_id = request.GET.get('version_id')
if not version_id:
error_logger.error(u'参数不完整')
return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整')
version_info = self.rpc['endpoint'](version_id=version_id).unwrap()
data = {
'version': version_info['version'],
'release_time': version_info['release_time'],
'md5': version_info['md5'],
'description': version_info['description'],
}
return self.write_success(data=data, message='操作成功')
def post(self, request):
"""
版本信息编辑 只允许修改描述
:param request:
:return:
"""
version_id = request.POST.get('version_id')
desc = request.POST.get('desc')
if not version_id:
error_logger.error(u'参数不完整')
return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整')
try:
self.rpc['endpoint'](version_id=version_id, description=desc)
except RPCFaultException as e:
error_logger.error(e)
return self.write_fail(code=-1, message='操作失败')
return self.write_success(data={}, message='操作成功')
class BatchPublishVersion(APIView):
def post(self, request):
"""
批量发布 并邮件通知
:param request:
:return:
"""
version_id = request.POST.get('version_id')
if not version_id:
error_logger.error(u'参数不完整')
return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整')
try:
packed_channels = self.rpc['endpoint'](version_id=version_id).unwrap()
except RPCFaultException as e:
error_logger.error(u'获取渠道失败%s', e)
return self.write_fail(code=-1, message='获取渠道失败!')
version_release_task.delay(packed_channels)
return self.write_success(data={}, message='操作成功')
......@@ -14,4 +14,5 @@ git+ssh://git@git.wanmeizhensuo.com/backend/gm-dataquery.git@v0.2.10
git+ssh://git@git.wanmeizhensuo.com/system/gm-tracer.git@v0.1.2
git+ssh://git@git.wanmeizhensuo.com/alpha/alpha-types.git@master
filetype==1.0.2
Pillow==5.4.1
\ No newline at end of file
Pillow==5.4.1
celery==4.2.1
\ No newline at end of file
from celery import shared_task
from middleware.rpc import rpc_invoker
from utils.channel_package_tools import ChannelPackage
from utils.logger import log_error
@shared_task
def version_release_task(packed_channels): # 一键发布,发布完成邮件通知
rpc = rpc_invoker
channels = []
for vtc in packed_channels:
version = vtc['version']
channel = vtc['channel']
vtc_id = vtc['id']
try:
ChannelPackage.publish_apk(channel, version)
rpc['endpoint'](version_id=vtc_id).unwrap()
channels.append(channel)
except:
log_error()
raise
# send email
rpc.origin['hera/channelbuild/version_release_notify'](
version=version,
channels=channels,
).unwrap()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment