Commit 8edffe7c authored by 张永's avatar 张永

和并提交

parent 43b47139
...@@ -7,7 +7,7 @@ from helios.rpc.exceptions import RPCFaultException ...@@ -7,7 +7,7 @@ from helios.rpc.exceptions import RPCFaultException
from utils.base import APIView from utils.base import APIView
from utils.channel_package_tools import ChannelPackage from utils.channel_package_tools import ChannelPackage
from utils.logger import error_logger from utils.logger import error_logger
from utils.channel_task import version_release_task, channel_build from utils.channel_task import version_release_task, channel_build, channel_build_one
def get_md5_value(src): def get_md5_value(src):
...@@ -45,35 +45,58 @@ class ChannelList(APIView): ...@@ -45,35 +45,58 @@ class ChannelList(APIView):
limit = int(request.GET.get('limit', 10)) limit = int(request.GET.get('limit', 10))
filters = self.handle_filter(request.GET.get('filter', "")) filters = self.handle_filter(request.GET.get('filter', ""))
try: try:
channel_list = self.rpc['sun/channel_build/channel/list']( channel_list = self.rpc['venus/sun/channel_build/channel/list'](
offset=page, limit=limit, filters=filters offset=(page-1)*limit, limit=limit, filters=filters
).unwrap() ).unwrap()
except Exception as e: except Exception as e:
error_logger.error(u'获取渠道列表失败:%s', e) error_logger.error(u'获取渠道列表失败:%s', e)
raise e raise e
data = {'total': channel_list.get('total', 0)} data = {'total': channel_list.get('total', 0)}
if filters.get('channel_id', ''): url = settings.APK_DOMAIN + settings.APK_RELEASE_DIR + "/{name}/gm_alpha_{name}.apk"
url = settings.APK_DOMAIN + settings.APK_BUILD_DIR + "/{version}/{name}/alpha_{name}.apk'"
channels = [ channels = [
{ {
'version': data.get('version'), 'id': data.get('id'),
'name': data.get('name'), 'name': data.get('name'),
'packed_time': data.get('packed_time'), 'url_name': data.get('url_name'),
'release_time': data.get('release_time'), 'pack': data.get('pack'),
'is_released': data.get('is_released'), 'released_version': data.get('released_version'),
'download_url': url.format(version=data.get('version'), name=data.get('name')), 'download_url': url.format(name=data.get('url_name')),
} }
for data in channel_list.get('data', [])] for data in channel_list.get('data', [])]
else: data.update({'channel': channels})
url = settings.APK_DOMAIN + settings.APK_RELEASE_DIR + "/{name}/alpha_{name}.apk'" return self.write_success(message='获取渠道列表成功', data=data)
class ChannelVersionList(APIView):
def get(self, request):
"""
:param request:
:return:
"""
channel_id = request.GET.get('channel_id')
page = int(request.GET.get('page', 1))
limit = int(request.GET.get('limit', 10))
try:
channel_list = self.rpc['venus/sun/channel_build/channel_version/list'](
offset=(page-1)*limit, limit=limit, channel_id=channel_id
).unwrap()
except Exception as e:
error_logger.error(u'获取渠道列表失败:%s', e)
raise e
data = {'total': channel_list.get('total', 0)}
url = settings.APK_DOMAIN + settings.APK_BUILD_DIR + "/{version}/{name}/gm_alpha_{name}.apk"
channels = [ channels = [
{ {
'id': data.get('id'), 'version_id': data.get('version_id'),
'channel_id': data.get('channel_id'),
'version': data.get('version'),
'name': data.get('name'), 'name': data.get('name'),
'url_name': data.get('url_name'), 'url_name': data.get('url_name'),
'pack': data.get('pack'), 'packed_time': data.get('packed_time'),
'released_version': data.get('released_version'), 'packed': data.get('packed'),
'download_url': url.format(name=data.get('name')), 'release_time': data.get('release_time'),
'is_released': data.get('is_released'),
'download_url': url.format(version=data.get('version'), name=data.get('url_name')),
} }
for data in channel_list.get('data', [])] for data in channel_list.get('data', [])]
data.update({'channel': channels}) data.update({'channel': channels})
...@@ -92,19 +115,18 @@ class Channel(APIView): ...@@ -92,19 +115,18 @@ class Channel(APIView):
error_logger.error(u'参数不完整') error_logger.error(u'参数不完整')
return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整') return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整')
try: try:
channel_data = self.rpc['sun/channel_build/channel/get']( channel_data = self.rpc['venus/sun/channel_build/channel/get'](
id=channel_id id=channel_id
).unwrap() ).unwrap()
except Exception as e: except Exception as e:
error_logger.error(u'获取渠道详情失败:%s', e) error_logger.error(u'获取渠道详情失败:%s', e)
raise e raise e
channel = { channel = {
'channel_id': channel_data.get('id'), 'id': channel_data.get('id'),
'channel_name': channel_data.get('name'), 'name': channel_data.get('name'),
'url_name': channel_data.get('url_name'), 'url_name': channel_data.get('url_name'),
'auto_pack': channel_data.get('pack'), 'pack': channel_data.get('pack'),
'channel_vendor': channel_data.get('vendor'), 'type': channel_data.get('type'),
'channel_type': channel_data.get('type'),
'released_version': channel_data.get('released_version'), 'released_version': channel_data.get('released_version'),
} }
return self.write_success(message='获取渠道详情成功', data=channel) return self.write_success(message='获取渠道详情成功', data=channel)
...@@ -115,13 +137,12 @@ class Channel(APIView): ...@@ -115,13 +137,12 @@ class Channel(APIView):
:param request: :param request:
:return: :return:
""" """
channel_id = request.POST.get('channel_id', '') channel_id = request.POST.get('id', None)
channel_name = request.POST.get('name', '') channel_name = request.POST.get('name', '')
url_name = request.POST.get('url_name', '') url_name = request.POST.get('url_name', '')
auto_pack = request.POST.get('pack', True) auto_pack = request.POST.get('pack', True)
channel_vendor = request.POST.get('vendor', 0)
channel_type = request.POST.get('type', 2) channel_type = request.POST.get('type', 2)
if not all([channel_id, channel_name, url_name, channel_vendor]): if not all([channel_name, url_name, auto_pack, channel_type]):
error_logger.error(u'参数不完整') error_logger.error(u'参数不完整')
return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整') return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整')
data = dict() data = dict()
...@@ -131,50 +152,22 @@ class Channel(APIView): ...@@ -131,50 +152,22 @@ class Channel(APIView):
data.update({'url_name': url_name}) data.update({'url_name': url_name})
if auto_pack: if auto_pack:
data.update({'pack': auto_pack}) data.update({'pack': auto_pack})
if channel_vendor:
data.update({'vendor': channel_vendor})
if channel_type: if channel_type:
data.update({'type': channel_type}) data.update({'type': channel_type})
try: try:
self.rpc['sun/channel_build/channel/edit']( resp = self.rpc['venus/sun/channel_build/channel/edit'](
id=channel_id, data=data id=channel_id, data=data
).unwrap() ).unwrap()
except RPCFaultException as e: except RPCFaultException as e:
raise e error_logger.error('操作失败%s', e)
return self.write_fail(message='操作失败', code=-1)
version = resp.get('version', '')
if version:
channel_build_one.delay(version, url_name)
return self.write_success(message='操作成功', data={}) return self.write_success(message='操作成功', data={})
class ChannelPacked(APIView): class ChannelPacked(APIView):
# def get(self, request):
# """
# 当前渠道已经打包的所有版本
# :param request:
# :return:
# """
# channel_id = request.GET.get('channel_id')
# if not channel_id:
# error_logger.error(u'参数不完整')
# return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整')
# try:
# channel_data = self.rpc['endpoint'](
# channel_id=channel_id
# ).unwrap()
# except Exception as e:
# error_logger.error(u'获取渠道打包列表失败:%s', e)
# raise e
# url = settings.APK_DOMAIN + settings.APK_BUILD_DIR + "/{version}/{name}/alpha_{name}.apk'"
# channel = [
# {
# 'version': data.get('version'),
# 'channel_name': data.get('name'),
# 'packed_time': data.get('packed_time'),
# 'release_time': data.get('release_time'),
# 'is_released': data.get('is_released'),
# 'download_url': url.format(version=data.get('version'), name=data.get('name')),
# }
# for data in channel_data]
# return self.write_success(message='获取渠道打包列表成功', data=channel)
def post(self, request): def post(self, request):
""" """
当前版本的渠道包发布 当前版本的渠道包发布
...@@ -187,16 +180,16 @@ class ChannelPacked(APIView): ...@@ -187,16 +180,16 @@ class ChannelPacked(APIView):
error_logger.error(u'参数不完整') error_logger.error(u'参数不完整')
return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整') return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整')
channel = self.rpc['sun/channel_build/channel/get']( channel = self.rpc['venus/sun/channel_build/channel/get'](
id=channel_id id=channel_id
).unwrap() ).unwrap()
version = self.rpc['sun/channel_build/version/get']( version = self.rpc['venus/sun/channel_build/version/get'](
id=version_id id=version_id
).unwrap() ).unwrap()
ChannelPackage.publish_apk(channel.get('url_name'), version.get('version')) ChannelPackage.publish_apk(channel.get('url_name'), version.get('version'))
try: try:
self.rpc['sun/channel_build/version/release']( self.rpc['venus/sun/channel_build/version/release'](
version_id=version_id, channel_ids=channel_id version_id=version_id, channel_ids=[channel_id]
).unwrap() #发布 ).unwrap() #发布
except RPCFaultException as e: except RPCFaultException as e:
error_logger.error(u'发布失败:%s', e) error_logger.error(u'发布失败:%s', e)
...@@ -204,42 +197,6 @@ class ChannelPacked(APIView): ...@@ -204,42 +197,6 @@ class ChannelPacked(APIView):
return self.write_success(data={}, 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['sun/channel_build/version/get'](
# id=version_id
# ).unwrap()
# # 母包地址 由七牛上传返回
# base_apk_url = ChannelPackage.apk_url(channel='', version=version.get('version'))
# else:
# base_apk_url = ''
# version = {}
# version2channels = self.rpc['endpoint'](
# version_id=version, start=(page - 1) * offset, offset=offset).unwrap()
# url = settings.APK_DOMAIN + settings.APK_BUILD_DIR + "/{version}/{name}/alpha_{name}.apk'"
# data = {
# 'version': [{
# 'version': item.get('version'),
# 'name': item.get('name'),
# 'packed_time': item.get('packed_time'),
# 'download_url': url.format(version=item.get(version), name=item.get('name')),
# '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): class VersionList(APIView):
def get(self, request): def get(self, request):
""" """
...@@ -249,40 +206,54 @@ class VersionList(APIView): ...@@ -249,40 +206,54 @@ class VersionList(APIView):
""" """
page = int(request.GET.get('page', 1)) page = int(request.GET.get('page', 1))
offset = int(request.GET.get('offset', 10)) offset = int(request.GET.get('offset', 10))
filters = self.handle_filter(request.GET.get('filter', ""))
try: try:
version_list = self.rpc['sun/channel_build/version/list']( version_list = self.rpc['venus/sun/channel_build/version/list'](
offset=page, limit=offset, filters=filters offset=(page-1)*offset, limit=offset
).unwrap() ).unwrap()
except Exception as e: except Exception as e:
error_logger.error(u'获取版本列表失败:%s', e) error_logger.error(u'获取版本列表失败:%s', e)
raise e raise e
data = {'total': version_list.get('total', 0)} data = {'total': version_list.get('total', 0)}
if filters.get('version_id', ''): versions = [
version = self.rpc['sun/channel_build/version/get']( {
id=filters.get('version_id') 'version_id': item.get('id'),
'version': item.get('version'),
'md5': item.get('md5'),
'release_time': item.get('release_time'),
} for item in version_list.get('data', [])
]
data.update({'data': versions})
return self.write_success(data=data)
class VersionChannelList(APIView):
def get(self, request):
page = int(request.GET.get('page', 1))
offset = int(request.GET.get('offset', 10))
version_id = request.GET.get('version_id', 10)
try:
version_list = self.rpc['venus/sun/channel_build/version_channel/list'](
offset=(page-1)*offset, limit=offset, version_id=version_id
).unwrap() ).unwrap()
base_apk_url = ChannelPackage.apk_url(channel='', version=version.get('version')) except Exception as e:
url = settings.APK_DOMAIN + settings.APK_BUILD_DIR + "/{version}/{name}/alpha_{name}.apk'" error_logger.error(u'获取版本列表失败:%s', e)
raise e
data = {'total': version_list.get('total', 0)}
url = settings.APK_DOMAIN + settings.APK_BUILD_DIR + "/{version}/{name}/gm_alpha_{name}.apk"
versions = { versions = {
'version': [{ 'version': [{
'channel_id': item.get('channel_id'),
'version_id': item.get('version_id'),
'version': item.get('version'), 'version': item.get('version'),
'name': item.get('name'), 'name': item.get('name'),
'packed_time': item.get('packed_time'), 'packed_time': item.get('packed_time'),
'download_url': url.format(version=item.get(version), name=item.get('name')), 'packed': item.get('packed'),
'download_url': url.format(version=item.get('version'), name=item.get('url_name')),
'release_time': item.get('release_time'), 'release_time': item.get('release_time'),
'is_released': item.get('is_released'), 'is_released': item.get('is_released'),
} for item in version_list.get('data', [])], } for item in version_list.get('data', [])],
'base_apk_url': base_apk_url, 'base_apk_url': ChannelPackage.apk_url(channel='', version=version_list.get('version')),
} }
else:
versions = [
{
'version': item.get('version'),
'MD5': item.get('md5'),
'release_time': item.get('release_time'),
} for item in version_list.get('data', [])
]
data.update({'data': versions}) data.update({'data': versions})
return self.write_success(data=data) return self.write_success(data=data)
...@@ -298,10 +269,11 @@ class VersionDetailUpdate(APIView): ...@@ -298,10 +269,11 @@ class VersionDetailUpdate(APIView):
if not version_id: if not version_id:
error_logger.error(u'参数不完整') error_logger.error(u'参数不完整')
return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整') return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整')
version_info = self.rpc['sun/channel_build/version/get']( version_info = self.rpc['venus/sun/channel_build/version/get'](
id=version_id id=version_id
).unwrap() ).unwrap()
data = { data = {
'id': version_info.get('id'),
'version': version_info.get('version'), 'version': version_info.get('version'),
'release_time': version_info.get('release_time'), 'release_time': version_info.get('release_time'),
'md5': version_info.get('md5'), 'md5': version_info.get('md5'),
...@@ -315,11 +287,11 @@ class VersionDetailUpdate(APIView): ...@@ -315,11 +287,11 @@ class VersionDetailUpdate(APIView):
:param request: :param request:
:return: :return:
""" """
version_id = request.POST.get('version_id') version_id = request.POST.get('id')
version = request.POST.get('version') version = request.POST.get('version')
md5 = request.POST.get('md5') md5 = request.POST.get('md5')
release_time = request.POST.get('release_time') release_time = request.POST.get('release_time')
desc = request.POST.get('desc') desc = request.POST.get('description')
if not version_id: if not version_id:
error_logger.error(u'参数不完整') error_logger.error(u'参数不完整')
return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整') return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整')
...@@ -333,10 +305,10 @@ class VersionDetailUpdate(APIView): ...@@ -333,10 +305,10 @@ class VersionDetailUpdate(APIView):
if md5: if md5:
data.update({'md5': md5}) data.update({'md5': md5})
try: try:
self.rpc['sun/channel_build/version/edit']( self.rpc['venus/sun/channel_build/version/edit'](
id=version_id, data=data id=version_id, data=data
) ).unwrap()
except RPCFaultException as e: except Exception as e:
error_logger.error(e) error_logger.error(e)
return self.write_fail(code=-1, message='操作失败') return self.write_fail(code=-1, message='操作失败')
return self.write_success(data={}, message='操作成功') return self.write_success(data={}, message='操作成功')
...@@ -355,7 +327,7 @@ class BatchPublishVersion(APIView): ...@@ -355,7 +327,7 @@ class BatchPublishVersion(APIView):
return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整') return self.write_fail(code=ERROR.ARG_MISS, message='参数不完整')
try: try:
# 获取当前版本所有已打包渠道 # 获取当前版本所有已打包渠道
channel_info = self.rpc['sun/channel_build/version/get_channel_info']( channel_info = self.rpc['venus/sun/channel_build/version/get_channel_info'](
version_id=version_id version_id=version_id
).unwrap() ).unwrap()
except RPCFaultException as e: except RPCFaultException as e:
...@@ -389,15 +361,14 @@ class VersionCreate(APIView): ...@@ -389,15 +361,14 @@ class VersionCreate(APIView):
data.update({'version': version}) data.update({'version': version})
if md5: if md5:
data.update({'md5': md5}) data.update({'md5': md5})
try: try:
version_id = self.rpc['sun/channel_build/version/edit']( version_id = self.rpc['venus/sun/channel_build/version/edit'](
data=data data=data
).unwrap() ).unwrap()
except RPCFaultException as e: except RPCFaultException as e:
error_logger.error('创建版本失败:%s', e) error_logger.error('创建版本失败:%s', e)
raise Exception('创建版本失败!') raise Exception('创建版本失败!')
channel_info = self.rpc['sun/channel_build/version/get_channel_info']( channel_info = self.rpc['venus/sun/channel_build/version/get_channel_info'](
version_id=version_id version_id=version_id
).unwrap() # 所有渠道的url_name: list() ).unwrap() # 所有渠道的url_name: list()
url_names = [] url_names = []
......
...@@ -108,12 +108,17 @@ urlpatterns = [ ...@@ -108,12 +108,17 @@ urlpatterns = [
url(r'^advertise/create$', AdvertiseCreateView.as_view()), url(r'^advertise/create$', AdvertiseCreateView.as_view()),
# 渠道打包相关API # 渠道打包相关API
url(r'^channel/get', Channel.as_view()), url(r'^channel_build/channel/get', ChannelList.as_view()),
url(r'^channel/create', Channel.as_view()), url(r'^channel_build/channel_version/get', ChannelVersionList.as_view()),
url(r'^channel/detail', Channel.as_view()), url(r'^channel_build/channel/detail', Channel.as_view()),
url(r'^channel/vendor/edit', Vendor.as_view()), url(r'^channel_build/channel/edit', Channel.as_view()),
url(r'^channel/packed/get', ChannelPacked.as_view()), url(r'^channel_build/build', ChannelPacked.as_view()),
url(r'^channel/packed/create', ChannelPacked.as_view()), url(r'^channel_build/version/get', VersionList.as_view()),
url(r'^channel_build/version_channel/get', VersionChannelList.as_view()),
url(r'^channel_build/version/detail', VersionDetailUpdate.as_view()),
url(r'^channel_build/version/update', VersionDetailUpdate.as_view()),
url(r'^channel_build/batch/release', BatchPublishVersion.as_view()),
url(r'^channel_build/version/create', VersionCreate.as_view()),
] ]
search_urlpatterns = [ search_urlpatterns = [
......
...@@ -162,5 +162,5 @@ DOWNLOAD_IMAGE_PATH = u'/data/header-images/' ...@@ -162,5 +162,5 @@ DOWNLOAD_IMAGE_PATH = u'/data/header-images/'
APK_SCOPE = 'download' APK_SCOPE = 'download'
APK_DOMAIN = 'http://dl.igengmei.com/' APK_DOMAIN = 'http://dl.igengmei.com/'
DEFAULT_CHANNEL = 'benzhan' DEFAULT_CHANNEL = 'benzhan'
APK_RELEASE_DIR = 'sun' APK_RELEASE_DIR = 'test'
APK_BUILD_DIR = 'sun_build' APK_BUILD_DIR = 'testbuild'
...@@ -4,52 +4,90 @@ import re ...@@ -4,52 +4,90 @@ import re
from django.conf import settings from django.conf import settings
from gm_upload.utils.qiniu_tool import QiniuTool from gm_upload.utils.qiniu_tool import QiniuTool
from .logger import log_error from qiniu import put_file
from utils.logger import log_error
class QiniuFileTool(QiniuTool):
@classmethod
def upload_file(cls, file_path, save_name, bucket_name):
"""
上传文件到七牛
:param file_path: 文本路径
:param save_name: 上传的名字
:param bucket_name: 空间名
:return:
"""
token = cls.q.upload_token(bucket_name)
for _ in range(5): # 多次尝试
ret, response_info = put_file(token, save_name, file_path)
if ret and "key" in ret and response_info.status_code == 200:
# assert ret["key"] == save_name
# assert ret["hash"] == etag(file_path)
return {
"file": ret["key"]
}
raise Exception('upload filed')
class ChannelPackage(object): class ChannelPackage(object):
# 渠道识别前缀 # 渠道识别前缀
channel_prefix = 'gmchannel' channel_prefix = 'gm_alpha'
def __init__(self, api_data, version): def __init__(self, api_data, version):
self.apk_data = api_data self.apk_data = api_data
self.version = version self.version = version
self.apk = None self.apk = None
@classmethod
def get_parent_path(cls, data):
path = os.getcwd() + '/' + cls.channel_prefix + '_parent.apk'
with open(path, 'wb')as fw:
fw.write(data)
return path
def build_channel_apk(self, channel_name): def build_channel_apk(self, channel_name):
cp = re.compile(r'[^{}]+') cp = re.compile(r'[^{}]+')
self.apk = self.channel_prefix + '.apk' self.apk = self.channel_prefix + '.apk'
walle_cli_path = os.getcwd() + '/walle-cli-all.jar' walle_cli_path = os.getcwd() + '/walle-cli-all.jar'
with open(self.apk, 'wb') as fw: with open(self.apk, 'wb') as fw:
fw.write(self.apk_data) fw.write(self.apk_data) # 母包
os.system('java -jar {0} batch -c {1} {2}'.format(walle_cli_path, channel_name, self.apk)) os.system('java -jar {0} batch -c {1} {2}'.format(walle_cli_path, channel_name, self.apk))
with open(self.channel_prefix + '_' + channel_name + '.apk', 'rb') as fr: # with open(self.channel_prefix + '_' + channel_name + '.apk', 'rb') as fr:
data = fr.read() # data = fr.read()
targe_apk = self.channel_prefix + '_' + channel_name + '.apk' targe_apk = self.channel_prefix + '_' + channel_name + '.apk'
cmd_res = os.popen('java -jar walle-cli-all.jar show %s' % targe_apk) cmd_res = os.popen('java -jar walle-cli-all.jar show %s' % targe_apk)
ret_res = cmd_res.readlines()[0] ret_res = cmd_res.readlines()[0]
target_channel_info = cp.findall(ret_res)[1] target_channel_info = cp.findall(ret_res)[1]
if target_channel_info and channel_name == target_channel_info.split('=')[1]: if target_channel_info and channel_name == target_channel_info.split('=')[1]:
return data target_path = self.channel_prefix + '_' + channel_name + '.apk'
os.remove(self.apk)
return target_path
else: else:
log_error() log_error()
os.remove(self.apk) os.remove(self.apk)
os.remove(self.channel_prefix + '_' + channel_name + '.apk') os.remove(self.channel_prefix + '_' + channel_name + '.apk')
def upload_apk(self, channel_name): def upload_apk(self, channel_name):
chn_apk_data = self.build_channel_apk(channel_name) chn_apk_path = self.build_channel_apk(channel_name)
apk_uri = self.apk_key(channel_name, self.version) apk_uri = self.apk_key(channel_name, self.version)
QiniuTool.delete(apk_uri, settings.APK_SCOPE) QiniuTool.delete(apk_uri, settings.APK_SCOPE)
ret = QiniuTool.upload(chn_apk_data, apk_uri, settings.APK_SCOPE) ret = QiniuFileTool.upload_file(chn_apk_path, apk_uri, settings.APK_SCOPE)
os.remove(chn_apk_path)
return ret return ret
@classmethod @classmethod
def apk_key(cls, channel, version): def apk_key(cls, channel, version):
build_dir = getattr(settings, 'APK_BUILD_DIR', '') build_dir = getattr(settings, 'APK_BUILD_DIR', '')
if channel: if channel:
uri = '{version}/{channel}/gengmei_{channel}.apk'.format(version=version, channel=channel) uri = '{version}/{channel}/gm_alpha_{channel}.apk'.format(version=version, channel=channel)
else: else:
uri = '{version}/gengmei.apk'.format(version=version) uri = '{version}/gm_alpha.apk'.format(version=version)
if build_dir: if build_dir:
uri = '{build_dir}/{uri}'.format(build_dir=build_dir, uri=uri) uri = '{build_dir}/{uri}'.format(build_dir=build_dir, uri=uri)
return uri return uri
...@@ -65,8 +103,10 @@ class ChannelPackage(object): ...@@ -65,8 +103,10 @@ class ChannelPackage(object):
apk_scope = settings.APK_SCOPE apk_scope = settings.APK_SCOPE
version_key = cls.apk_key(channel, version) version_key = cls.apk_key(channel, version)
current_key = cls.apk_key(channel, settings.APK_RELEASE_DIR) current_key = cls.apk_key(channel, settings.APK_RELEASE_DIR)
print('current_key:', current_key)
ret, info = QiniuTool.bucket.stat(apk_scope, current_key) ret, info = QiniuTool.bucket.stat(apk_scope, current_key)
if ret: if ret:
print('delete')
QiniuTool.delete(current_key, apk_scope) QiniuTool.delete(current_key, apk_scope)
QiniuTool.copy(version_key, current_key, apk_scope, apk_scope) QiniuTool.copy(version_key, current_key, apk_scope, apk_scope)
if need_refresh: if need_refresh:
......
import os
from celery import shared_task from celery import shared_task
from django.conf import settings from django.conf import settings
import requests import requests
...@@ -5,7 +6,7 @@ import requests ...@@ -5,7 +6,7 @@ import requests
from gm_upload.utils.qiniu_tool import QiniuTool from gm_upload.utils.qiniu_tool import QiniuTool
from middleware.rpc import rpc_invoker from middleware.rpc import rpc_invoker
from utils.channel_package_tools import ChannelPackage from utils.channel_package_tools import ChannelPackage, QiniuFileTool
from utils.logger import log_error, info_logger from utils.logger import log_error, info_logger
...@@ -23,7 +24,7 @@ def version_release_task(packed_channels, version_id=None, version=None): # 一 ...@@ -23,7 +24,7 @@ def version_release_task(packed_channels, version_id=None, version=None): # 一
log_error() log_error()
raise Exception('发布失败') raise Exception('发布失败')
# 发布 # 发布
rpc['sun/channel_build/version/release']( rpc['venus/sun/channel_build/version/release'](
version_id=version_id, channel_ids=channel_ids version_id=version_id, channel_ids=channel_ids
).unwrap() ).unwrap()
# email notify # email notify
...@@ -39,20 +40,21 @@ def channel_build_one(version=None, channel=None, data=None): ...@@ -39,20 +40,21 @@ def channel_build_one(version=None, channel=None, data=None):
@shared_task @shared_task
def channel_build(version=None, channels=None, data=None): def channel_build(version=None, channels=None, data=None, ):
url = ChannelPackage.apk_key('', version) url = ChannelPackage.apk_key('', version)
QiniuTool.delete(url, settings.APK_SCOPE) QiniuTool.delete(url, settings.APK_SCOPE)
QiniuTool.upload(data, url, settings.APK_SCOPE) target_path = ChannelPackage.get_parent_path(data)
if channels is None: QiniuFileTool.upload_file(target_path, url, settings.APK_SCOPE) # 上传母包
channels = [settings.DEFAULT_CHANNEL] if not channels:
elif settings.DEFAULT_CHANNEL not in channels: # channels = [settings.DEFAULT_CHANNEL]
channels.append(settings.DEFAULT_CHANNEL) return
info_logger.debug(channels) info_logger.debug(channels)
chn_pkg = ChannelPackage(data, version) chn_pkg = ChannelPackage(data, version)
# 遍历渠道号并创建对应渠道号的apk文件 # 遍历渠道号并创建对应渠道号的apk文件
for channel in channels: for channel in channels:
build_one_channel(chn_pkg, channel) build_one_channel(chn_pkg, channel)
os.remove(target_path)
def build_one_channel(pkg_obj, channel): def build_one_channel(pkg_obj, channel):
...@@ -63,7 +65,7 @@ def build_one_channel(pkg_obj, channel): ...@@ -63,7 +65,7 @@ def build_one_channel(pkg_obj, channel):
ret = pkg_obj.upload_apk(channel) ret = pkg_obj.upload_apk(channel)
info_logger.debug(ret) info_logger.debug(ret)
if 'file' in ret: if 'file' in ret:
# TODO 打包 # 打包
rpc_invoker['endpoint']( rpc_invoker['venus/sun/channel_build/channel/pack'](
version=pkg_obj.version, channel=channel version=pkg_obj.version, url_name=channel
).unwrap() ).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