Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
sun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alpha
sun
Commits
19754200
Commit
19754200
authored
Feb 16, 2019
by
张永
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新建分支打包管理
parent
e2dc1971
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
244 additions
and
0 deletions
+244
-0
channel_build.py
api/channel_build.py
+159
-0
urls.py
api/urls.py
+9
-0
settings.py
sun/settings.py
+2
-0
channel_package_tools.py
utils/channel_package_tools.py
+74
-0
No files found.
api/channel_build.py
0 → 100644
View file @
19754200
from
gm_types.ascle
import
ERROR
from
helios.rpc.exceptions
import
RPCFaultException
from
utils.base
import
APIView
from
utils.channel_package_tools
import
ChannelPackage
from
utils.logger
import
error_logger
class
Vendor
(
APIView
):
def
get
(
self
,
request
):
"""
获取渠道商列表
:param request:
:return:
"""
query
=
request
.
GET
.
get
(
'q'
,
''
)
page
=
int
(
request
.
GET
.
get
(
'page'
,
1
))
limit
=
int
(
request
.
GET
.
get
(
'limit'
,
30
))
data
=
request
.
rpc
.
origin
[
'endpoint'
](
query
=
query
,
page
=
page
,
limit
=
limit
,
)
.
unwrap
()
return
data
class
ChannelList
(
APIView
):
def
get
(
self
,
request
):
"""
渠道列表
:param request:
:return:
"""
page
=
int
(
request
.
GET
.
get
(
'page'
,
1
))
limit
=
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
()
except
Exception
as
e
:
error_logger
.
error
(
u'获取渠道列表失败:
%
s'
,
e
)
raise
e
data
=
[
{
'name'
:
data
.
get
(
'name'
),
'url_name'
:
data
.
get
(
'url_name'
),
'pack'
:
data
.
get
(
'pack'
),
'download_url'
:
data
.
get
(),
# TODO 拼接下载链接 最近的一次发布
}
for
data
in
channel_list
]
return
self
.
write_success
(
message
=
'获取渠道列表成功'
,
data
=
data
)
class
Channel
(
APIView
):
def
get
(
self
,
request
):
"""
渠道详情
:param request:
:return:
"""
channel_id
=
request
.
GET
.
get
(
'channel_id'
,
0
)
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
channel
=
{
'channel_id'
:
channel_data
.
get
(
'channel_id'
,
0
),
'channel_name'
:
channel_data
.
get
(
'name'
),
'url_name'
:
channel_data
.
get
(
'url_name'
),
'auto_pack'
:
channel_data
.
get
(
'pack'
),
'channel_vendor'
:
channel_data
.
get
(
'vendor'
),
'channel_type'
:
channel_data
.
get
(
'type'
),
}
return
self
.
write_success
(
message
=
'获取渠道详情成功'
,
data
=
channel
)
def
post
(
self
,
request
):
"""
渠道创建 / 编辑
:param request:
:return:
"""
channel_id
=
request
.
POST
.
get
(
'channel_id'
,
''
)
channel_name
=
request
.
POST
.
get
(
'name'
,
''
)
url_name
=
request
.
POST
.
get
(
'url_name'
,
''
)
auto_pack
=
request
.
POST
.
get
(
'pack'
,
True
)
channel_vendor
=
request
.
POST
.
get
(
'vendor'
,
0
)
channel_type
=
request
.
POST
.
get
(
'type'
,
2
)
if
not
all
([
channel_name
,
url_name
,
channel_vendor
]):
error_logger
.
error
(
u'参数不完整'
)
return
self
.
write_fail
(
code
=
ERROR
.
ARG_MISS
,
message
=
'参数不完整'
)
if
channel_id
:
# 编辑渠道信息
try
:
self
.
rpc
[
'endpoint'
](
channel_id
=
channel_id
,
name
=
channel_name
,
pack
=
auto_pack
,
vendor
=
channel_vendor
,
type
=
channel_type
)
.
unwrap
()
except
RPCFaultException
as
e
:
raise
e
else
:
# 创建渠道信息
try
:
self
.
rpc
[
'endpoint'
](
name
=
channel_name
,
pack
=
auto_pack
,
vendor
=
channel_vendor
,
type
=
channel_type
)
.
unwrap
()
except
RPCFaultException
as
e
:
raise
e
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
channel
=
[
{
'version'
:
data
.
get
(
'version'
,
0
),
'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'
:
''
,
# TODO 拼接下载链接
}
for
data
in
channel_data
]
return
self
.
write_success
(
message
=
'获取渠道打包列表成功'
,
data
=
channel
)
def
post
(
self
,
request
):
"""
当前版本的渠道包发布
:param request:
:return:
"""
version2channel_id
=
request
.
POST
.
get
(
'id'
)
if
not
version2channel_id
:
error_logger
.
error
(
u'参数不完整'
)
return
self
.
write_fail
(
code
=
ERROR
.
ARG_MISS
,
message
=
'参数不完整'
)
version2channel
=
self
.
rpc
[
'endpoint'
](
id
=
version2channel_id
)
.
unwrap
()
# get
version
=
version2channel
[
'version'
]
channel
=
version2channel
[
'channel'
]
ChannelPackage
.
publish_apk
(
channel
,
version
)
try
:
self
.
rpc
[
'endpoint'
](
id
=
version2channel_id
)
.
unwrap
()
# edit
except
RPCFaultException
as
e
:
error_logger
.
error
(
u'获取渠道打包列表失败:
%
s'
,
e
)
return
self
.
write_fail
(
code
=-
1
,
message
=
'发布失败!'
)
return
self
.
write_success
(
data
=
{},
message
=
'发布成功!'
)
api/urls.py
View file @
19754200
...
...
@@ -19,6 +19,7 @@ from .upload import *
from
.token
import
*
from
.face_star
import
*
from
.advertise
import
*
from
.channel_build
import
*
urlpatterns
=
[
# 登陆,注销相关
...
...
@@ -105,6 +106,14 @@ urlpatterns = [
url
(
r'^advertise/edit'
,
AdvertiseCreateView
.
as_view
()),
url
(
r'^advertise/list$'
,
AdvertiseListView
.
as_view
()),
url
(
r'^advertise/create$'
,
AdvertiseCreateView
.
as_view
()),
# 渠道打包相关API
url
(
r'^channel/get'
,
Channel
.
as_view
()),
url
(
r'^channel/create'
,
Channel
.
as_view
()),
url
(
r'^channel/detail'
,
Channel
.
as_view
()),
url
(
r'^channel/vendor/edit'
,
Vendor
.
as_view
()),
url
(
r'^channel/packed/get'
,
ChannelPacked
.
as_view
()),
url
(
r'^channel/packed/create'
,
ChannelPacked
.
as_view
()),
]
search_urlpatterns
=
[
...
...
sun/settings.py
View file @
19754200
...
...
@@ -157,3 +157,5 @@ OPERATOR_PASSWORD = 123456
# 图片下载的存储路径
DOWNLOAD_IMAGE_PATH
=
u'/data/header-images/'
#
utils/channel_package_tools.py
0 → 100644
View file @
19754200
# -*- coding: UTF-8 -*-
import
os
import
re
from
django.conf
import
settings
from
gm_upload.utils.qiniu_tool
import
QiniuTool
from
.logger
import
log_error
class
ChannelPackage
(
object
):
# 渠道识别前缀
channel_prefix
=
'gmchannel'
def
__init__
(
self
,
api_data
,
version
):
self
.
apk_data
=
api_data
self
.
version
=
version
self
.
apk
=
None
def
build_channel_apk
(
self
,
channel_name
):
cp
=
re
.
compile
(
r'[^{}]+'
)
self
.
apk
=
self
.
channel_prefix
+
'.apk'
walle_cli_path
=
os
.
getcwd
()
+
'/walle-cli-all.jar'
with
open
(
self
.
apk
,
'wb'
)
as
fw
:
fw
.
write
(
self
.
apk_data
)
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
:
data
=
fr
.
read
()
targe_apk
=
self
.
channel_prefix
+
'_'
+
channel_name
+
'.apk'
cmd_res
=
os
.
popen
(
'java -jar walle-cli-all.jar show
%
s'
%
targe_apk
)
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
]:
return
data
else
:
log_error
()
os
.
remove
(
self
.
apk
)
os
.
remove
(
self
.
channel_prefix
+
'_'
+
channel_name
+
'.apk'
)
def
upload_apk
(
self
,
channel_name
):
chn_apk_data
=
self
.
build_channel_apk
(
channel_name
)
apk_uri
=
self
.
apk_key
(
channel_name
,
self
.
version
)
QiniuTool
.
delete
(
apk_uri
,
settings
.
APK_SCOPE
)
ret
=
QiniuTool
.
upload
(
chn_apk_data
,
apk_uri
,
settings
.
APK_SCOPE
)
return
ret
@classmethod
def
apk_key
(
cls
,
channel
,
version
):
build_dir
=
getattr
(
settings
,
'APK_BUILD_DIR'
,
''
)
if
channel
:
uri
=
'{version}/{channel}/gengmei_{channel}.apk'
.
format
(
version
=
version
,
channel
=
channel
)
else
:
uri
=
'{version}/gengmei.apk'
.
format
(
version
=
version
)
if
build_dir
:
uri
=
'{build_dir}/{uri}'
.
format
(
build_dir
=
build_dir
,
uri
=
uri
)
return
uri
@classmethod
def
apk_url
(
cls
,
channel
,
version
):
key
=
cls
.
apk_key
(
channel
,
version
)
url
=
settings
.
APK_DOMAIN
+
key
return
url
@classmethod
def
publish_apk
(
cls
,
channel
,
version
,
need_refresh
=
True
):
apk_scope
=
settings
.
APK_SCOPE
version_key
=
cls
.
apk_key
(
channel
,
version
)
current_key
=
cls
.
apk_key
(
channel
,
settings
.
APK_RELEASE_DIR
)
ret
,
info
=
QiniuTool
.
bucket
.
stat
(
apk_scope
,
current_key
)
if
ret
:
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
])
return
True
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment