Commit 0b292ca0 authored by 张永's avatar 张永

七牛刷新

parent 365834a6
import hashlib
import time
from django.conf import settings
from gm_types.ascle import ERROR
......@@ -52,7 +53,8 @@ class ChannelList(APIView):
error_logger.error(u'获取渠道列表失败:%s', e)
raise e
data = {'total': channel_list.get('total', 0)}
url = settings.APK_DOMAIN + settings.APK_BUILD_DIR + '/' + settings.APK_RELEASE_DIR + "/{name}/gm_alpha_{name}.apk"
url = settings.APK_DOMAIN + settings.APK_BUILD_DIR + '/' + settings.APK_RELEASE_DIR + \
"/{name}/gm_alpha_{name}.apk?t={timestamp}"
channels = [
{
'id': data.get('id'),
......@@ -60,7 +62,7 @@ class ChannelList(APIView):
'url_name': data.get('url_name'),
'pack': data.get('pack'),
'released_version': data.get('released_version'),
'download_url': url.format(name=data.get('url_name')),
'download_url': url.format(name=data.get('url_name'), timestamp=time.time()),
}
for data in channel_list.get('data', [])]
data.update({'channel': channels})
......@@ -84,7 +86,7 @@ class ChannelVersionList(APIView):
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"
url = settings.APK_DOMAIN + settings.APK_BUILD_DIR + "/{version}/{name}/gm_alpha_{name}.apk?t={timestamp}"
channels = [
{
'version_id': data.get('version_id'),
......@@ -96,7 +98,8 @@ class ChannelVersionList(APIView):
'packed': data.get('packed'),
'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')),
'download_url': url.format(
version=data.get('version'), name=data.get('url_name'), timestamp=time.time()),
}
for data in channel_list.get('data', [])]
data.update({'channel': channels})
......@@ -245,7 +248,8 @@ class VersionChannelList(APIView):
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"
url = settings.APK_DOMAIN + settings.APK_BUILD_DIR + "/{version}/{name}/gm_alpha_{name}.apk?t={timestamp}"
sup_url = ChannelPackage.apk_url(channel='', version=version_list.get('version')) + '?t={timestamp}'
versions = {
'version': [{
'channel_id': item.get('channel_id'),
......@@ -254,11 +258,12 @@ class VersionChannelList(APIView):
'name': item.get('name'),
'packed_time': item.get('packed_time'),
'packed': item.get('packed'),
'download_url': url.format(version=item.get('version'), name=item.get('url_name')),
'download_url': url.format(
version=item.get('version'), name=item.get('url_name'), timestamp=time.time()),
'release_time': item.get('release_time'),
'is_released': item.get('is_released'),
} for item in version_list.get('data', [])],
'base_apk_url': ChannelPackage.apk_url(channel='', version=version_list.get('version')),
'base_apk_url': sup_url.format(timestamp=time.time()),
}
data.update({'data': versions})
return self.write_success(data=data)
......
......@@ -63,9 +63,8 @@ class ChannelPackage(object):
ret_res = cmd_res.readlines()[0]
target_channel_info = cp.findall(ret_res)[1]
if target_channel_info and channel_name == target_channel_info.split('=')[1]:
target_path = self.channel_prefix + '_' + channel_name + '.apk'
os.remove(self.apk)
return target_path
return targe_apk
else:
log_error()
os.remove(self.apk)
......@@ -76,6 +75,8 @@ class ChannelPackage(object):
apk_uri = self.apk_key(channel_name, self.version)
QiniuTool.delete(apk_uri, settings.APK_SCOPE)
ret = QiniuFileTool.upload_file(chn_apk_path, apk_uri, settings.APK_SCOPE)
res_resp = QiniuTool.refresh(['http://alpha-s.iyanzhi.com/' + apk_uri])
info_logger.debug(res_resp)
os.remove(chn_apk_path)
return ret
......@@ -115,5 +116,5 @@ class ChannelPackage(object):
QiniuTool.delete(current_key, apk_scope)
QiniuTool.copy(version_key, current_key, apk_scope, apk_scope)
if need_refresh:
QiniuTool.refresh(['http://qiniu.dl.igengmei.com/' + current_key])
QiniuTool.refresh(['http://alpha-s.iyanzhi.com/' + current_key])
return True
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