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
8edffe7c
Commit
8edffe7c
authored
Feb 19, 2019
by
张永
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
和并提交
parent
43b47139
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
76 additions
and
29 deletions
+76
-29
channel_build.py
api/channel_build.py
+0
-0
urls.py
api/urls.py
+11
-6
settings.py
sun/settings.py
+2
-2
channel_package_tools.py
utils/channel_package_tools.py
+50
-10
channel_task.py
utils/channel_task.py
+13
-11
walle-cli-all.jar
walle-cli-all.jar
+0
-0
No files found.
api/channel_build.py
View file @
8edffe7c
This diff is collapsed.
Click to expand it.
api/urls.py
View file @
8edffe7c
...
@@ -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
=
[
...
...
sun/settings.py
View file @
8edffe7c
...
@@ -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
=
'
test
build'
utils/channel_package_tools.py
View file @
8edffe7c
...
@@ -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
=
'gm
channel
'
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}/g
engmei
_{channel}.apk'
.
format
(
version
=
version
,
channel
=
channel
)
uri
=
'{version}/{channel}/g
m_alpha
_{channel}.apk'
.
format
(
version
=
version
,
channel
=
channel
)
else
:
else
:
uri
=
'{version}/g
engmei
.apk'
.
format
(
version
=
version
)
uri
=
'{version}/g
m_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
:
...
...
utils/channel_task.py
View file @
8edffe7c
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
()
walle-cli-all.jar
0 → 100644
View file @
8edffe7c
File added
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