Skip to content

Commit

Permalink
增加七牛云上传相关代码
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed May 24, 2018
1 parent 8b357c8 commit 1bb1cff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
language: python
python:
- '3.6'
- '3.6'
install:
- pip3 install qiniu
script:
- "python3 ./zip.py"
- "python3 ./zip.py"
before_deploy:
- git config --local user.name "TartaricAcid"
- git config --local user.email "[email protected]"
- git tag "汉化资源包-Snapshot-$(date +'%Y%m%d%H%M%S')"
- git config --local user.name "TartaricAcid"
- git config --local user.email "[email protected]"
- git tag "汉化资源包-Snapshot-$(date +'%Y%m%d%H%M%S')"
deploy:
provider: releases
api_key:
Expand Down
24 changes: 23 additions & 1 deletion zip.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#!/usr/bin/python3
# 这一块属于独立的模块,并不记入主程序
# 给 Travis CI 用的,用来剔除重复文件
# 同时将文件上传到七牛云

import os
import src.redundancy.redundancy
import qiniu

# 这里打包的是剔除冗余的版本
os.system('mv ./project-tmp/assets ./')
os.system('mv ./project-tmp/pack.mcmeta ./')
os.system('mv ./project-tmp/pack.png ./')
os.system('zip -r -9 "Minecraft-Mod-Language-Modpack-Lite.zip" "assets" "pack.mcmeta" "pack.png" "README.md" "LICENSE"')
os.system(
'zip -r -9 "Minecraft-Mod-Language-Modpack-Lite.zip" "assets" "pack.mcmeta" "pack.png" "README.md" "LICENSE"')
# 只需要剔除 assets 文件夹即可
os.system('rm -rf ./assets')

Expand All @@ -30,3 +33,22 @@
# 最后打包
os.system('mv ./project/assets ./')
os.system('zip -r -9 "Minecraft-Mod-Language-Modpack.zip" "assets" "pack.mcmeta" "pack.png" "README.md" "LICENSE"')

# 多加一步,上传到七牛云
# 从环境变量获取 Access Key 和 Secret Key
access_key = os.environ('Access_Key')
secret_key = os.environ('Secret_Key')
# 构建鉴权对象
q = qiniu.Auth(access_key, secret_key)
# 要上传的空间
bucket_name = 'langpack'
# 上传到七牛后保存的文件名
key = 'Minecraft-Mod-Language-Modpack.zip';
# 生成上传 Token,可以指定过期时间等
token = q.upload_token(bucket_name, key, 600)
# 要上传文件的本地路径
localfile = './Minecraft-Mod-Language-Modpack.zip'
ret, info = qiniu.put_file(token, key, localfile)
print(info)
assert ret['key'] == key
assert ret['hash'] == qiniu.etag(localfile)

0 comments on commit 1bb1cff

Please sign in to comment.