Skip to content

Commit

Permalink
修正部分内容,修改 zip 打包文件
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed Dec 31, 2018
1 parent 52750df commit c95cf7d
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 72 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: python
python:
- '3.6'
install:
- pip3 install qiniu
script:
- "python3 ./zip.py"
before_deploy:
Expand All @@ -15,7 +13,6 @@ deploy:
secure: KmeoGPGKBYjliQomtTeynl6Q42m/3k9jf/2FY6qu8fX8uqA4RhgZsdphP9PZ1WkKNds80H9p7zSAc57l8qrPkLoyYOfJGRiZZB68G6/AKKV0xTm4SV/6ItoTa7sSQkFNr1U1UBdvDiC7RRpPWMyVwxFefT5GWxg15/+O5DNkAgMwn4/Ea0l5q358Rgod3WkdKeLT3QPrEjY+8lUUlC4edYwVJhe2U/pAHcDkOGQJQX+JAVd+ss6QHK4FAk0vFm0demIT2/ByPkqmajo5M1vSLFnhoOMJdyIeNKeZGslydAgUGf3AQCn7VoPV4zBa3+q2sEEVDVMZkp2HjxgYBfzk9M00EJ78ETryIetpa6r7rVPz+rxAVyzJqdhCH4/TqCA+a6j0j/axqqyVNfPqqU2wPEgCindvU9hMjJ3y1be6gmElGdDP0uDab3/lGUWiZdwFr32G732QA7LV+ZeTABAuhCoOz9WAFMN4mDI7dwPn67D2FEfa/Q6e7aiaEG0A/M90bqlKs0bkhubNczJJgl2s2FXKsHzPLU7GXRlT6kgt1I7WzTBMuGvHrqJ5mBGNCQMsELjAoZuzskqbvsdqzgDF8VUj+n2VSMYQzksBK0+g8lJ9eH2KWr1MRPekENaQf47Xh9T1BPTsf3Hcu9xwcNhneUYyTgBol3Pg3PjqRFdrO2Y=
file:
- "Minecraft-Mod-Language-Modpack.zip"
- "Minecraft-Mod-Language-Modpack-Lite.zip"
skip_cleanup: true
on:
repo: CFPAOrg/Minecraft-Mod-Language-Package
Expand Down
16 changes: 1 addition & 15 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 爬虫工具的配置文件

# 爬虫抓取的版本
# 目前只有 1.7.10, 1.8.9, 1.9.4, 1.10.2, 1.11.2, 1.12.2 四个可选
# 目前只有 1.7.10, 1.8.9, 1.9.4, 1.10.2, 1.11.2, 1.12, 1.12.2 七个可选(然而并没什么用)
version: 1.12.2

# 爬虫的线程数
Expand Down Expand Up @@ -176,20 +176,6 @@ del_list:
- simpleautorun # 空语言文件
- equipmenttooltips # 空语言文件

# 邮件发送提醒
# 按次序写入需要发送的邮箱
email:
- [email protected]

# github 仓库信息获取
# 已经获得下面所有人的授权,允许抓取公开信息
# 遵循 github 用户协议
github_user:
- 3TUSK
- DYColdWind
- SihenZhang
- forestbat

# 某些英文键不是我们想要的,可以通过这一块书写删除它
del_key:
- 'msg.entity.rocket.seldst'
Expand Down
2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/python3

import src.file_download.mod_download
import src.info_get.mod_info_get
import src.info_get.mod_list_get
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ requests==2.21.0
javaproperties==0.5.1
wlc==0.10
PyYAML==3.13
qiniu==7.2.2
4 changes: 2 additions & 2 deletions src/baka_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@

# 代理 IP
PROXIES = {
"http": "http://127.0.0.1:1080",
"https": "http://127.0.0.1:1080"
# "http": "http://127.0.0.1:1080",
# "https": "http://127.0.0.1:1080"
}

# 读取配置文件
Expand Down
115 changes: 63 additions & 52 deletions zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,73 @@
# 给 Travis CI 用的,用来剔除重复文件
# 同时将文件上传到七牛云

import logging
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"')
# 只需要剔除 assets 文件夹即可
os.system('rm -rf ./assets')
if __name__ == '__main__':
# 日志初始化
logging.basicConfig(
level=logging.DEBUG,
format="[%(asctime)s] [%(threadName)s/%(levelname)s] [%(filename)s]: %(message)s",
datefmt="%H:%M:%S"
)

# 打包处理主程序
for modid in os.listdir('project/assets'):
# 各个语言文件路径构建
zh_cn_path = 'project/assets/{}/lang/zh_cn.lang'.format(modid)
zh_cn_old_path = 'project/assets/{}/lang/zh_cn_old.lang'.format(modid)
en_us_path = 'project/assets/{}/lang/en_us.lang'.format(modid)
en_us_old_path = 'project/assets/{}/lang/en_us_old.lang'.format(modid)

# 剔除 en_us
os.system('rm -rf '.format(en_us_path))
# 剔除 en_us_old
os.system('rm -rf '.format(en_us_old_path))
# 剔除 zh_cn_old
os.system('rm -rf '.format(zh_cn_old_path))

# zh_cn 存在,且文件为空
if os.path.isfile(zh_cn_path) and os.path.getsize(zh_cn_path) == 0:
os.system('rm -rf '.format(zh_cn_path))

# 最后打包
os.system('mv ./project/assets ./') # 移动到资源包文件夹到主目录下
# 打包“资源包,资源包 meta 文件,资源包图标,说明,许可证”
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.getenv('Access_Key')
secret_key = os.getenv('Secret_Key')
# 构建鉴权对象
q = qiniu.Auth(access_key, secret_key)

# 接下来是不剔除冗余保留版本的打包
# 处理主程序
for modid in os.listdir('project/assets'):
# 先判断 zh_cn 存在不存在
if not os.path.exists('project/assets/{}/lang/zh_cn.lang'.format(modid)):
continue
# 剔除 en_us
os.system('rm -f project/assets/{}/lang/en_us.lang'.format(modid))
# 再剔除 zh_cn_old
os.system('rm -f project/assets/{}/lang/zh_cn_old.lang'.format(modid))
# 最后判断文件是否为空
if os.path.getsize('project/assets/{}/lang/zh_cn.lang'.format(modid)) == 0:
os.system('rm -rf project/assets/{}'.format(modid))
# 要上传的空间
bucket_name = 'langpack'
# 上传到七牛后保存的文件名
key = 'Minecraft-Mod-Language-Modpack.zip'
# 生成上传 Token,可以指定过期时间等
token = q.upload_token(bucket_name, key, 120)
# 要上传文件的本地路径
localfile = './Minecraft-Mod-Language-Modpack.zip'
# 将文件放入对象,进行上传
ret, info = qiniu.put_file(token, key, localfile)

# 最后打包
os.system('mv ./project/assets ./')
os.system('zip -r -9 "Minecraft-Mod-Language-Modpack.zip" "assets" "pack.mcmeta" "pack.png" "README.md" "LICENSE"')
logging.info(info)

# 多加一步,上传到七牛云
# 从环境变量获取 Access Key 和 Secret Key
access_key = os.getenv('Access_Key')
secret_key = os.getenv('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, 120)
# 要上传文件的本地路径
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)
# 断言这两个返回值,确保上传的文件名和哈希值与本地一致
assert ret['key'] == key
assert ret['hash'] == qiniu.etag(localfile)

# 刷新七牛云文件缓存
cdn_manager = qiniu.CdnManager(q)
# 需要刷新的文件链接
urls = [
'http://downloader.meitangdehulu.com/Minecraft-Mod-Language-Modpack.zip'
]
# 刷新链接
refresh_url_result = cdn_manager.refresh_urls(urls)
print(refresh_url_result)
# 刷新七牛云文件缓存
cdn_manager = qiniu.CdnManager(q)
# 需要刷新的文件链接
urls = [
'http://downloader.meitangdehulu.com/Minecraft-Mod-Language-Modpack.zip'
]
# 刷新链接
refresh_url_result = cdn_manager.refresh_urls(urls)
logging.info(refresh_url_result)

0 comments on commit c95cf7d

Please sign in to comment.