miduo_HotFix/Tools/oss/example.py

106 lines
3.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# Auther: Wang Qi
# !/usr/bin/env python
# encoding: utf-8
import os
import oss2
import sys
import base64
import hashlib
import requests
import subprocess
import urllib3
import logging
import time
import random
import argparse
from threading import Thread, current_thread
from concurrent.futures import ProcessPoolExecutor
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
class jlrg():
basedir = "/data/public/samba/public/jieling_dl/dev/assetBundles/"
dir_name = "mht_china"
fail_list = []
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
secret_id = 'AKIDRJxLRFFzwcmiNlLzqPggdplPlrpVec2A' # 替换为用户的 secretId
secret_key = 'zh8JDqJZYLq42j9NL2RYOyGI9kDOIGxN' # 替换为用户的 secretKey
region = 'ap-guangzhou' # 替换为用户的 Region
token = None # 使用临时密钥需要传入 Token默认为空可不填
scheme = 'https' # 指定使用 http/https 协议来访问 COS默认为 https可不填
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme=scheme)
# 2. 获取客户端对象
client = CosS3Client(config)
def __init__(self):
self.fileList = []
def get_all_file(self):
fo = open("/data/scripts/mht_china_test.txt", "r")
files = fo.readlines()
filelist = []
for f in files:
file = f.strip()
if not file.startswith("http") and not file.endswith("/") and not file.endswith("version.txt") and not file.endswith("files.unity3d"):
filelist.append(file)
return filelist
def flushurl(self,url):
keydict = {
'Action': 'RefreshCdnUrl',
'Timestamp': str(int(time.time())),
'Nonce': str(int(random.random() * 1000)),
'SecretId': jlrg.secret_id,
'urls.0': url
}
return keydict
def upload_file_to_txy_cos(self, local_file_path):
if local_file_path.endswith('.DS_Store') or not os.path.isfile(local_file_path):
return
if ".svn" in local_file_path:
return
print(local_file_path)
# print(11111)
cos_object_key = local_file_path[len(jlrg.basedir):].replace("\\", "/").lstrip("/")
print(cos_object_key)
url = 'http://' + "jl.tyu89.wang" + "/" + cos_object_key
print(url)
response = jlrg.client.upload_file(
Bucket='internal-jieling-1302131159',
LocalFilePath=local_file_path,
Key=cos_object_key,
PartSize=1,
MAXThread=10,
EnableMD5=False
)
self.flushurl(url)
return (response['ETag'])
def up(self):
os.system("sh /data/scripts/url_mht_china_test.sh")
filelist = self.get_all_file()
print(filelist)
pool = ProcessPoolExecutor(4)
for file in filelist:
# print(file)
pool.submit(self.upload_file_to_txy_cos, file)
self.upload_file_to_txy_cos("/data/public/samba/public/jieling_dl/dev/assetBundles/mht_china/test/Android/config.txt")
self.upload_file_to_txy_cos("/data/public/samba/public/jieling_dl/dev/assetBundles/mht_china/test/Android/config.txt")
self.upload_file_to_txy_cos("/data/public/samba/public/jieling_dl/dev/assetBundles/mht_china/test/Android/files.unity3d")
self.upload_file_to_txy_cos("/data/public/samba/public/jieling_dl/dev/assetBundles/mht_china/test/Android/version.txt")
https://dcdn.aliyuncs.com/?Action=RefreshDcdnObjectCaches&ObjectPath=download.gamenew-h5.com/Japan/SW/&ObjectType=Directory&Version=2018-01-15&Timestamp=2021-05-08T03:32:45Z&SignatureNonce=15215528852396&AccessKeyId=LTAIE4jRXhLBvVLL&SignatureMethod=HMAC-SHA1
if __name__ == '__main__':
z = jlrg()
z.up()