generated from root/miduo_client
【test】上传测试
commit
3a753a4779
|
@ -0,0 +1,105 @@
|
|||
# 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()
|
|
@ -0,0 +1,65 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import oss2
|
||||
import os
|
||||
|
||||
|
||||
class jlrg():
|
||||
|
||||
# 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
||||
auth = oss2.Auth('LTAIE4jRXhLBvVLL', '74hEmfGzNEYLSFP26fO6CUZ319AY61')
|
||||
# yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
|
||||
# 填写Bucket名称。
|
||||
bucket = oss2.Bucket(auth, 'https://oss-ap-northeast-1.aliyuncs.com', 'taichuxing')
|
||||
|
||||
|
||||
basedir = "/data/public/samba/public/jieling_dl/dev/assetBundles/"
|
||||
fail_list = []
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.fileList = []
|
||||
|
||||
def get_all_file(self):
|
||||
fo = open("/data/scripts/mht_test.txt", "r")
|
||||
files = fo.readlines()
|
||||
filelist = []
|
||||
print(filelist)
|
||||
for f in files:
|
||||
file = f.strip()
|
||||
if file.startswith("http") and not file.endswith("/") and not file.endswith("version.txt") and not file.endswith("files.unity3d"):
|
||||
filelist.append(file)
|
||||
return self.fileList
|
||||
|
||||
|
||||
|
||||
def upload_file_to_aly_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)
|
||||
cos_object_key = local_file_path[len(jlrg.basedir):].replace("\\", "/").lstrip("/")
|
||||
print(cos_object_key)
|
||||
url = 'http://download.gamenew-h5.com/' + cos_object_key
|
||||
print(url)
|
||||
jlrg.bucket.put_object_from_file(cos_object_key, local_file_path)
|
||||
|
||||
|
||||
|
||||
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:
|
||||
pool.submit(self.upload_file_to_aly_cos, file)
|
||||
|
||||
self.upload_file_to_aly_cos("/data/public/samba/public/jieling_dl/dev/assetBundles/mht_china/test/Android/config.txt")
|
||||
self.upload_file_to_aly_cos("/data/public/samba/public/jieling_dl/dev/assetBundles/mht_china/test/Android/files.unity3d")
|
||||
self.upload_file_to_aly_cos("/data/public/samba/public/jieling_dl/dev/assetBundles/mht_china/test/Android/version.txt")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
z = jlrg()
|
||||
z.up()
|
|
@ -0,0 +1,82 @@
|
|||
# encoding: utf-8
|
||||
import os
|
||||
import time
|
||||
import base64
|
||||
import random
|
||||
import urllib, urllib2
|
||||
import hmac, hashlib
|
||||
|
||||
class AL_Flush():
|
||||
alurl = "https://dcdn.aliyuncs.com/?"
|
||||
url = "download.gamenew-h5.com"
|
||||
AccessKeyId = "LTAIE4jRXhLBvVLL"
|
||||
AccessKeySecret = "74hEmfGzNEYLSFP26fO6CUZ319AY61"
|
||||
|
||||
def percentEncode(self, value):
|
||||
#value = urllib.quote(value)
|
||||
#value = value.replace("%26", "&")
|
||||
value = value.replace("/", "%252F")
|
||||
value = value.replace("&", "%26")
|
||||
value = value.replace("=", "%3D")
|
||||
value = value.replace(":", "%253A")
|
||||
return value
|
||||
|
||||
|
||||
def flush(self, dic):
|
||||
t = time.time()-8*60*60
|
||||
localtime = time.localtime(t)
|
||||
date = time.strftime("%Y-%m-%dT%H:%M:%SZ", localtime)
|
||||
keydict = {
|
||||
'Action': 'RefreshDcdnObjectCaches',
|
||||
'ObjectPath': self.url + '/' + dic,
|
||||
'ObjectType': "Directory",
|
||||
'Version': '2018-01-15',
|
||||
'Timestamp': date,
|
||||
'SignatureNonce': str(int(random.random() * 100000000)),
|
||||
'AccessKeyId': self.AccessKeyId,
|
||||
'SignatureMethod': 'HMAC-SHA1',
|
||||
'SignatureVersion': '1.0'
|
||||
}
|
||||
keydict = sorted(keydict.iteritems(), key = lambda asd:asd[0] ,reverse = False)
|
||||
print keydict
|
||||
|
||||
params = ""
|
||||
for k in keydict:
|
||||
if params != "":
|
||||
params += "&"
|
||||
params += k[0]+"="+k[1]
|
||||
print params
|
||||
|
||||
StringToSign = "GET&%2F&" + self.percentEncode(params)
|
||||
#StringToSign = self.percentEncode(StringToSign)
|
||||
print StringToSign
|
||||
|
||||
h = hmac.new(bytes(self.AccessKeySecret+"&"), bytes(StringToSign), hashlib.sha1).hexdigest()
|
||||
#h = hmac.new(b'hash',b'helloworld',digestmod='sha1')
|
||||
print(h)
|
||||
sign = base64.b64encode(h)
|
||||
print sign
|
||||
sign = self.percentEncode(sign)
|
||||
print sign
|
||||
|
||||
|
||||
u = self.alurl + params + "&Signature="+sign
|
||||
print u
|
||||
#response = urllib2.urlopen(u)
|
||||
#print response.read()
|
||||
|
||||
|
||||
a = b"testsecret&"
|
||||
b = b"GET&%2F&AccessKeyId%3Dtestid&Action%3DDescribeLiveSnapshotConfig&AppName%3Dtest&DomainName%3Dtest.com&Format%3DXML&RegionId%3Dcn-shanghai&ServiceCode%3Dlive&SignatureMethod%3DHMAC-SHA1&SignatureNonce%3Dc2fe8fbb-2977-4414-8d39-348d02419c1c&SignatureVersion%3D1.0&Timestamp%3D2017-06-14T09%253A51%253A14Z&Version%3D2016-11-01"
|
||||
h = hmac.new(a, b, hashlib.sha1).hexdigest()
|
||||
#h = hmac.new(b'hash',b'helloworld',digestmod='sha1')
|
||||
print(h)
|
||||
sign = base64.b64encode(h)
|
||||
print sign
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
alf = AL_Flush()
|
||||
alf.flush("Japan/SW/")
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env python
|
||||
#coding=utf-8
|
||||
|
||||
from aliyunsdkcore.client import AcsClient
|
||||
from aliyunsdkcore.acs_exception.exceptions import ClientException
|
||||
from aliyunsdkcore.acs_exception.exceptions import ServerException
|
||||
from aliyunsdkdcdn.request.v20180115.PreloadDcdnObjectCachesRequest import PreloadDcdnObjectCachesRequest
|
||||
|
||||
client = AcsClient('LTAIE4jRXhLBvVLL', '74hEmfGzNEYLSFP26fO6CUZ319AY61', 'ap-northeast-1')
|
||||
|
||||
request = PreloadDcdnObjectCachesRequest()
|
||||
request.set_accept_format('json')
|
||||
|
||||
request.set_Area("overseas")
|
||||
request.set_ObjectPath("download.gamenew-h5.com/Japan/SW/")
|
||||
|
||||
response = client.do_action_with_exception(request)
|
||||
# python2: print(response)
|
||||
print(str(response, encoding='utf-8'))
|
|
@ -0,0 +1,64 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# This file is auto-generated, don't edit it. Thanks.
|
||||
import sys
|
||||
|
||||
from typing import List
|
||||
|
||||
from alibabacloud_dcdn20180115.client import Client as dcdn20180115Client
|
||||
from alibabacloud_tea_openapi import models as open_api_models
|
||||
from alibabacloud_dcdn20180115 import models as dcdn_20180115_models
|
||||
|
||||
|
||||
class Sample:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def create_client(
|
||||
access_key_id: str,
|
||||
access_key_secret: str,
|
||||
) -> dcdn20180115Client:
|
||||
"""
|
||||
使用AK&SK初始化账号Client
|
||||
@param access_key_id:
|
||||
@param access_key_secret:
|
||||
@return: Client
|
||||
@throws Exception
|
||||
"""
|
||||
config = open_api_models.Config(
|
||||
# 您的AccessKey ID,
|
||||
access_key_id=access_key_id,
|
||||
# 您的AccessKey Secret,
|
||||
access_key_secret=access_key_secret
|
||||
)
|
||||
# 访问的域名
|
||||
config.endpoint = 'dcdn.aliyuncs.com'
|
||||
return dcdn20180115Client(config)
|
||||
|
||||
@staticmethod
|
||||
def main(
|
||||
args: List[str],
|
||||
) -> None:
|
||||
client = Sample.create_client('LTAIE4jRXhLBvVLL', '74hEmfGzNEYLSFP26fO6CUZ319AY61')
|
||||
preload_dcdn_object_caches_request = dcdn_20180115_models.PreloadDcdnObjectCachesRequest(
|
||||
area='overseas',
|
||||
object_path='download.gamenew-h5.com/Japan/SW/'
|
||||
)
|
||||
# 复制代码运行请自行打印 API 的返回值
|
||||
client.preload_dcdn_object_caches(preload_dcdn_object_caches_request)
|
||||
|
||||
@staticmethod
|
||||
async def main_async(
|
||||
args: List[str],
|
||||
) -> None:
|
||||
client = Sample.create_client('LTAIE4jRXhLBvVLL', '74hEmfGzNEYLSFP26fO6CUZ319AY61')
|
||||
preload_dcdn_object_caches_request = dcdn_20180115_models.PreloadDcdnObjectCachesRequest(
|
||||
area='overseas',
|
||||
object_path='download.gamenew-h5.com/Japan/SW/'
|
||||
)
|
||||
# 复制代码运行请自行打印 API 的返回值
|
||||
await client.preload_dcdn_object_caches_async(preload_dcdn_object_caches_request)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
Sample.main(sys.argv[1:])
|
Loading…
Reference in New Issue