# -*- coding: utf-8 -*- # Auther Wang Qi # !usrbinenv 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 import json from threading import Thread, current_thread from concurrent.futures import ProcessPoolExecutor from qcloud_cos import CosConfig from qcloud_cos import CosS3Client # url = "http://jl.tyu89.wang/" + cos_object_key # print(url) #self.flushurl(url) # 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, path, file): file = file.replace("\\", "/").lstrip("/") path = path.replace("\\", "/").lstrip("/") local_file_path = path + file print(local_file_path) cos_object_key = self.cdn_sub_dir + "/" + self.platform +"/" + file print(cos_object_key) response = self.client.upload_file( Bucket=self.bucket, LocalFilePath=local_file_path, Key=cos_object_key, PartSize=1, MAXThread=10, EnableMD5=False ) class Cos_Upload(): logging.basicConfig(level=logging.INFO, stream=sys.stdout) def __init__(self, abDir, settingDir, changeVersion): self.settingFile = "Setting.txt" self.configFile = "config.txt" self.versionFile = "version.txt" self.fileList = [] self.ab_dir = abDir self.setting_dir = self.ab_dir + "/" + settingDir self.change_version = changeVersion self.change_file = self.setting_dir + "/__HotFixLog/" + changeVersion + ".log" self.loadSetting() # cdn config self.bucket = 'internal-jieling-1302131159' self.secret_id = "AKIDRJxLRFFzwcmiNlLzqPggdplPlrpVec2A" self.secret_key = "zh8JDqJZYLq42j9NL2RYOyGI9kDOIGxN" self.region = "ap-guangzhou" self.config = CosConfig(Region=self.region, SecretId=self.secret_id, SecretKey=self.secret_key, Token=None, Scheme='https') self.client = CosS3Client(self.config) def loadSetting(self): settingContent = open(self.setting_dir +"/"+ self.settingFile, "rb") settingJson = json.load(settingContent) self.cdn_sub_dir = settingJson["dir"] self.platform = settingJson["platform"] def get_all_file(self): fo = open(self.change_file, "r") files = fo.readlines() for f in files: file = f.strip() self.fileList.append(file) return self.fileList def up(self): filelist = self.get_all_file() pool = ProcessPoolExecutor(4) for file in filelist: pool.submit(upload_file_to_txy_cos, self, self.ab_dir + "/" + self.platform + "/", file) pool.submit(upload_file_to_txy_cos, self, self.setting_dir +"/", self.configFile) pool.submit(upload_file_to_txy_cos, self, self.setting_dir +"/", self.versionFile) if __name__ == '__main__': if sys.argv.__len__() == 4: print(sys.argv[1]) t = Cos_Upload(sys.argv[1], sys.argv[2], sys.argv[3]) t.up() else: print("params error!") # if __name__ == '__main__': # z = Cos_Upload("D:/HotFix/Root/mht_china/local", "cdn_v3", 'version_1') # z.up()