From 37b252ba309026fc9a763e6374d16c668dab9f95 Mon Sep 17 00:00:00 2001 From: aslinwang Date: Tue, 6 Aug 2019 21:14:14 +0800 Subject: [PATCH 1/9] feat: skip upload when local file name is same as cos file --- .gitignore | 3 +- coscmd/cos_client.py | 45 ++++++++++++++----- coscmd/cos_cmd.py | 2 + coscmd/cos_color.py | 105 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+), 11 deletions(-) create mode 100644 coscmd/cos_color.py diff --git a/.gitignore b/.gitignore index 9c16294..ca979e4 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ coscmd/*.swn coscmd/*.swo *.project *.pydevproject -.settings/ \ No newline at end of file +.settings/ +.vscode/ diff --git a/coscmd/cos_client.py b/coscmd/cos_client.py index 3b200b1..8e313d4 100644 --- a/coscmd/cos_client.py +++ b/coscmd/cos_client.py @@ -27,10 +27,12 @@ from coscmd.cos_auth import CosS3Auth from coscmd.cos_threadpool import SimpleThreadPool from coscmd.cos_comm import * + from coscmd.cos_color import * else: from cos_auth import CosS3Auth from cos_threadpool import SimpleThreadPool from cos_comm import * + from cos_color import * logger = logging.getLogger("coscmd") @@ -154,6 +156,15 @@ def check_file_md5(self, _local_path, _cos_path, _md5): return False else: return True + + def check_file_name(self, _local_path, _cos_path): + url = self._conf.uri(path=quote(to_printable_str(_cos_path))) + rt = self._session.head( + url=url, auth=CosS3Auth(self._conf), stream=True) + if rt.status_code != 200: #资源不存在 + return False + else: + return True def sign_url(self, cos_path, timeout=10000): cos_path = to_printable_str(cos_path) @@ -298,10 +309,6 @@ def upload_file_list(upload_filelist): return -1 def single_upload(self, local_path, cos_path, _http_headers='{}', **kwargs): - logger.info(u"Upload {local_path} => cos://{bucket}/{cos_path}".format( - bucket=self._conf._bucket, - local_path=local_path, - cos_path=cos_path)) _md5 = "" try: _http_header = yaml.safe_load(_http_headers) @@ -327,6 +334,13 @@ def single_upload(self, local_path, cos_path, _http_headers='{}', **kwargs): logger.info( u"The file on cos is the same as the local file, skip upload") return -2 + if kwargs['mutex'] is True: + if self.check_file_name(local_path, cos_path): + logger.error( + u"The file {cos_path} on cos has same name as the local file, skip upload".format( + cos_path=cos_path + )) + return -2 try: if len(local_path) == 0: data = "" @@ -340,7 +354,7 @@ def single_upload(self, local_path, cos_path, _http_headers='{}', **kwargs): for j in range(self._retry): try: if j > 0: - logger.info(u"Retry to upload {local_path} => cos://{bucket}/{cos_path}".format( + logger.warn(u"Retry to upload {local_path} => cos://{bucket}/{cos_path}".format( bucket=self._conf._bucket, local_path=local_path, cos_path=cos_path)) @@ -349,6 +363,10 @@ def single_upload(self, local_path, cos_path, _http_headers='{}', **kwargs): rt = self._session.put(url=url, auth=CosS3Auth(self._conf), data=data, headers=http_header) if rt.status_code == 200: + logger.info(u"Upload {local_path} => cos://{bucket}/{cos_path} success".format( + bucket=self._conf._bucket, + local_path=local_path, + cos_path=cos_path)) return 0 else: time.sleep(2**j) @@ -502,10 +520,6 @@ def complete_multiupload(): logger.warn(e) return -1 - logger.info(u"Upload {local_path} => cos://{bucket}/{cos_path}".format( - bucket=self._conf._bucket, - local_path=local_path, - cos_path=cos_path)) _md5 = "" try: _http_header = yaml.safe_load(_http_headers) @@ -531,6 +545,13 @@ def complete_multiupload(): logger.info( u"The file on cos is the same as the local file, skip upload") return -2 + if kwargs['mutex'] is True: + if self.check_file_name(local_path, cos_path): + logger.error( + u"The file {cos_path} on cos has same name as the local file, skip upload".format( + cos_path=cos_path + )) + return -2 rt = init_multiupload() if 0 == rt: logger.debug(u"Init multipart upload ok") @@ -546,7 +567,10 @@ def complete_multiupload(): return -1 rt = complete_multiupload() if 0 == rt: - logger.debug(u"Complete multipart upload ok") + logger.info(u"Upload {local_path}(multipart) => cos://{bucket}/{cos_path} success".format( + bucket=self._conf._bucket, + local_path=local_path, + cos_path=cos_path)) else: logger.warn(u"Complete multipart upload failed") return -1 @@ -2040,6 +2064,7 @@ def probe(self, **kwargs): kw = { "skipmd5": True, "sync": False, + "mutex": False, "force": True, "ignore": ""} time_start = time.time() diff --git a/coscmd/cos_cmd.py b/coscmd/cos_cmd.py index 2662cf2..568c4f0 100644 --- a/coscmd/cos_cmd.py +++ b/coscmd/cos_cmd.py @@ -218,6 +218,7 @@ def upload(args): args.cos_path = args.cos_path[1:] kwargs = {} kwargs['sync'] = args.sync + kwargs['mutex'] = args.mutex kwargs['skipmd5'] = args.skipmd5 kwargs['ignore'] = args.ignore.split(',') kwargs['force'] = args.force @@ -690,6 +691,7 @@ def command_thread(): parser_upload.add_argument('-r', '--recursive', help="Upload recursively when upload directory", action="store_true", default=False) parser_upload.add_argument('-H', '--headers', help="Specify HTTP headers", type=str, default='{}') parser_upload.add_argument('-s', '--sync', help="Upload and skip the same file", action="store_true", default=False) + parser_upload.add_argument('-m', '--mutex', help="Upload and skip the file has same name", action="store_true", default=False) parser_upload.add_argument('-f', '--force', help="upload without history breakpoint", action="store_true", default=False) parser_upload.add_argument('--ignore', help='Specify ignored rules, separated by commas; Example: *.txt,*.docx,*.ppt', type=str, default="") parser_upload.add_argument('--skipmd5', help='Upload without x-cos-meta-md5', action="store_true", default=False) diff --git a/coscmd/cos_color.py b/coscmd/cos_color.py new file mode 100644 index 0000000..bab0a8a --- /dev/null +++ b/coscmd/cos_color.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python +# encoding: utf-8 +import logging +# now we patch Python code to add color support to logging.StreamHandler +def add_coloring_to_emit_windows(fn): + # add methods we need to the class + def _out_handle(self): + import ctypes + return ctypes.windll.kernel32.GetStdHandle(self.STD_OUTPUT_HANDLE) + out_handle = property(_out_handle) + + def _set_color(self, code): + import ctypes + # Constants from the Windows API + self.STD_OUTPUT_HANDLE = -11 + hdl = ctypes.windll.kernel32.GetStdHandle(self.STD_OUTPUT_HANDLE) + ctypes.windll.kernel32.SetConsoleTextAttribute(hdl, code) + + setattr(logging.StreamHandler, '_set_color', _set_color) + + def new(*args): + FOREGROUND_BLUE = 0x0001 # text color contains blue. + FOREGROUND_GREEN = 0x0002 # text color contains green. + FOREGROUND_RED = 0x0004 # text color contains red. + FOREGROUND_INTENSITY = 0x0008 # text color is intensified. + FOREGROUND_WHITE = FOREGROUND_BLUE|FOREGROUND_GREEN |FOREGROUND_RED + # winbase.h + STD_INPUT_HANDLE = -10 + STD_OUTPUT_HANDLE = -11 + STD_ERROR_HANDLE = -12 + + # wincon.h + FOREGROUND_BLACK = 0x0000 + FOREGROUND_BLUE = 0x0001 + FOREGROUND_GREEN = 0x0002 + FOREGROUND_CYAN = 0x0003 + FOREGROUND_RED = 0x0004 + FOREGROUND_MAGENTA = 0x0005 + FOREGROUND_YELLOW = 0x0006 + FOREGROUND_GREY = 0x0007 + FOREGROUND_INTENSITY = 0x0008 # foreground color is intensified. + + BACKGROUND_BLACK = 0x0000 + BACKGROUND_BLUE = 0x0010 + BACKGROUND_GREEN = 0x0020 + BACKGROUND_CYAN = 0x0030 + BACKGROUND_RED = 0x0040 + BACKGROUND_MAGENTA = 0x0050 + BACKGROUND_YELLOW = 0x0060 + BACKGROUND_GREY = 0x0070 + BACKGROUND_INTENSITY = 0x0080 # background color is intensified. + + levelno = args[1].levelno + if(levelno>=50): + color = BACKGROUND_YELLOW | FOREGROUND_RED | FOREGROUND_INTENSITY | BACKGROUND_INTENSITY + elif(levelno>=40): + color = FOREGROUND_RED | FOREGROUND_INTENSITY + elif(levelno>=30): + color = FOREGROUND_YELLOW | FOREGROUND_INTENSITY + elif(levelno>=20): + color = FOREGROUND_GREEN + elif(levelno>=10): + color = FOREGROUND_MAGENTA + else: + color = FOREGROUND_WHITE + args[0]._set_color(color) + + ret = fn(*args) + args[0]._set_color( FOREGROUND_WHITE ) + #print "after" + return ret + return new + +def add_coloring_to_emit_ansi(fn): + # add methods we need to the class + def new(*args): + levelno = args[1].levelno + if(levelno>=50): # fatal,critical + color = '\x1b[31m' # red + elif(levelno>=40): # error + color = '\x1b[31m' # red + elif(levelno>=30): # warn,warning + color = '\x1b[33m' # yellow + elif(levelno>=20): # info + color = '\x1b[32m' # green + elif(levelno>=10): # debug + color = '\x1b[35m' # pink + else: + color = '\x1b[0m' # normal + args[1].msg = color + args[1].msg + '\x1b[0m' # normal + #print "after" + return fn(*args) + return new + +import platform +if platform.system()=='Windows': + # Windows does not support ANSI escapes and we are using API calls to set the console color + logging.StreamHandler.emit = add_coloring_to_emit_windows(logging.StreamHandler.emit) +else: + # all non-Windows platforms are supporting ANSI escapes so we use them + logging.StreamHandler.emit = add_coloring_to_emit_ansi(logging.StreamHandler.emit) + #log = logging.getLogger() + #log.addFilter(log_filter()) + #//hdlr = logging.StreamHandler() + #//hdlr.setFormatter(formatter()) \ No newline at end of file From acbb36b228ee2b64361d882a3798438e83967f1d Mon Sep 17 00:00:00 2001 From: aslinwang Date: Tue, 6 Aug 2019 23:17:16 +0800 Subject: [PATCH 2/9] docs: update readme --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index 27a6368..2238538 100644 --- a/README.rst +++ b/README.rst @@ -23,6 +23,9 @@ __________ 手动安装:: python setup.py install + cd dist + sudo easy_install coscmd-1.8.6.3-py3.6.egg # 提前安装easy_install + ln -s {{PYTHON_DIR}}/bin/coscmd xcoscmd # [可选]为避免和官方coscmd冲突,通过软链使用此版本 使用方法 __________ From 338907ae29bb7d98367578fe878f4246101f3d83 Mon Sep 17 00:00:00 2001 From: aslinwang Date: Tue, 6 Aug 2019 23:24:01 +0800 Subject: [PATCH 3/9] docs: update readme --- README.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.rst b/README.rst index 2238538..539b689 100644 --- a/README.rst +++ b/README.rst @@ -27,6 +27,16 @@ __________ sudo easy_install coscmd-1.8.6.3-py3.6.egg # 提前安装easy_install ln -s {{PYTHON_DIR}}/bin/coscmd xcoscmd # [可选]为避免和官方coscmd冲突,通过软链使用此版本 +改造 +__________ +上传命令,支持上传同名文件不覆盖,直接跳过 + +命令:: + + coscmd -rm ./app /app + +上传结果输出优化:上传失败的log红色显示,上传成功的log绿色显示,更加直观的显示上传结果 + 使用方法 __________ From eb23332d7886a2919f2e726f122c98011c86835c Mon Sep 17 00:00:00 2001 From: aslinwang Date: Mon, 17 Feb 2020 19:47:17 +0800 Subject: [PATCH 4/9] update readme --- README.rst | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 539b689..5fc3a97 100644 --- a/README.rst +++ b/README.rst @@ -16,11 +16,7 @@ _______ 安装指南 __________ -使用pip安装 :: - - pip install -U coscmd - -手动安装:: +:: python setup.py install cd dist From d62a5e135f6d18633e550626fb1ef2bdd0f5cbf1 Mon Sep 17 00:00:00 2001 From: aslinwang Date: Mon, 14 Sep 2020 20:48:42 +0800 Subject: [PATCH 5/9] =?UTF-8?q?feat:=20=E5=8F=91=E5=B8=83=E5=88=B0pip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + README.rst | 11 +++++-- RELEASE.rst | 12 ++++++++ coscmd/cos_global.py | 1 - setup.py | 12 ++++---- {coscmd => xcoscmd}/__init__.py | 0 {coscmd => xcoscmd}/cos_auth.py | 8 ++--- {coscmd => xcoscmd}/cos_client.py | 10 +++--- {coscmd => xcoscmd}/cos_cmd.py | 24 +++++++-------- {coscmd => xcoscmd}/cos_color.py | 0 {coscmd => xcoscmd}/cos_comm.py | 0 xcoscmd/cos_global.py | 1 + {coscmd => xcoscmd}/cos_threadpool.py | 2 +- {coscmd => xcoscmd}/test.py | 44 +++++++++++++-------------- 14 files changed, 73 insertions(+), 53 deletions(-) create mode 100644 RELEASE.rst delete mode 100644 coscmd/cos_global.py rename {coscmd => xcoscmd}/__init__.py (100%) rename {coscmd => xcoscmd}/cos_auth.py (92%) rename {coscmd => xcoscmd}/cos_client.py (97%) rename {coscmd => xcoscmd}/cos_cmd.py (95%) rename {coscmd => xcoscmd}/cos_color.py (100%) rename {coscmd => xcoscmd}/cos_comm.py (100%) create mode 100644 xcoscmd/cos_global.py rename {coscmd => xcoscmd}/cos_threadpool.py (95%) rename {coscmd => xcoscmd}/test.py (65%) diff --git a/.gitignore b/.gitignore index ca979e4..58d39de 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ coscmd/*.swo *.pydevproject .settings/ .vscode/ +xcoscmd.egg-info diff --git a/README.rst b/README.rst index 5fc3a97..a723b94 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -COSCMD +XCOSCMD ####################### .. image:: https://img.shields.io/pypi/v/coscmd.svg @@ -23,13 +23,20 @@ __________ sudo easy_install coscmd-1.8.6.3-py3.6.egg # 提前安装easy_install ln -s {{PYTHON_DIR}}/bin/coscmd xcoscmd # [可选]为避免和官方coscmd冲突,通过软链使用此版本 +或 +:: + pip install xcoscmd -i https://pypi.tuna.tsinghua.edu.cn/simple + 或 pip install xcoscmd -i https://pypi.doubanio.com/simple + 或 pip install xcoscmd -i http://mirrors.tencent.com/pypi/simple + + 改造 __________ 上传命令,支持上传同名文件不覆盖,直接跳过 命令:: - coscmd -rm ./app /app + xcoscmd -rm ./app /app 上传结果输出优化:上传失败的log红色显示,上传成功的log绿色显示,更加直观的显示上传结果 diff --git a/RELEASE.rst b/RELEASE.rst new file mode 100644 index 0000000..8176406 --- /dev/null +++ b/RELEASE.rst @@ -0,0 +1,12 @@ +XCOSCMD + +发布指南 +__________ + +:: + + python setup.py sdist bdist_wheel + pip install twine + twine check dist/* + twine upload dist/* + diff --git a/coscmd/cos_global.py b/coscmd/cos_global.py deleted file mode 100644 index 0537fde..0000000 --- a/coscmd/cos_global.py +++ /dev/null @@ -1 +0,0 @@ -Version = "1.8.6.3" diff --git a/setup.py b/setup.py index 552ae8e..0e8045f 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages from platform import python_version_tuple -from coscmd import cos_global +from xcoscmd import cos_global def requirements(): @@ -22,19 +22,19 @@ def long_description(): setup( - name='coscmd', + name='xcoscmd', version=cos_global.Version, url='https://www.qcloud.com/', license='MIT', - author='lewzylu', - author_email='327874225@qq.com', - description='simple command for cos', + author='aslinwang', + author_email='dream_jet@qq.com', + description='simple command for cos, forked from https://github.com/tencentyun/coscmd', long_description=long_description(), packages=find_packages(), install_requires=requirements(), entry_points={ 'console_scripts': [ - 'coscmd=coscmd.cos_cmd:_main', + 'xcoscmd=xcoscmd.cos_cmd:_main', ], } ) diff --git a/coscmd/__init__.py b/xcoscmd/__init__.py similarity index 100% rename from coscmd/__init__.py rename to xcoscmd/__init__.py diff --git a/coscmd/cos_auth.py b/xcoscmd/cos_auth.py similarity index 92% rename from coscmd/cos_auth.py rename to xcoscmd/cos_auth.py index a5d0fec..2491196 100644 --- a/coscmd/cos_auth.py +++ b/xcoscmd/cos_auth.py @@ -10,13 +10,13 @@ from requests.auth import AuthBase if sys.version > '3': - from coscmd.cos_global import Version - from coscmd.cos_comm import to_bytes + from xcoscmd.cos_global import Version + from xcoscmd.cos_comm import to_bytes else: from cos_global import Version from cos_comm import to_bytes -logger = logging.getLogger("coscmd") +logger = logging.getLogger("xcoscmd") class CosS3Auth(AuthBase): @@ -80,7 +80,7 @@ def __call__(self, r): r.headers['Authorization'] = "" if self._token is not None: r.headers['x-cos-security-token'] = self._token - r.headers['User-agent'] = 'coscmd-v' + Version + r.headers['User-agent'] = 'xcoscmd-v' + Version logger.debug("sign_key" + str(sign_key)) logger.debug(r.headers['Authorization']) diff --git a/coscmd/cos_client.py b/xcoscmd/cos_client.py similarity index 97% rename from coscmd/cos_client.py rename to xcoscmd/cos_client.py index 8e313d4..cae81e1 100644 --- a/coscmd/cos_client.py +++ b/xcoscmd/cos_client.py @@ -24,17 +24,17 @@ import qcloud_cos if sys.version > '3': - from coscmd.cos_auth import CosS3Auth - from coscmd.cos_threadpool import SimpleThreadPool - from coscmd.cos_comm import * - from coscmd.cos_color import * + from xcoscmd.cos_auth import CosS3Auth + from xcoscmd.cos_threadpool import SimpleThreadPool + from xcoscmd.cos_comm import * + from xcoscmd.cos_color import * else: from cos_auth import CosS3Auth from cos_threadpool import SimpleThreadPool from cos_comm import * from cos_color import * -logger = logging.getLogger("coscmd") +logger = logging.getLogger("xcoscmd") class CoscmdConfig(object): diff --git a/coscmd/cos_cmd.py b/xcoscmd/cos_cmd.py similarity index 95% rename from coscmd/cos_cmd.py rename to xcoscmd/cos_cmd.py index 568c4f0..3b105a0 100644 --- a/coscmd/cos_cmd.py +++ b/xcoscmd/cos_cmd.py @@ -9,16 +9,16 @@ import json import requests from threading import Thread -from coscmd import cos_global +from xcoscmd import cos_global if sys.version > '3': - from coscmd.cos_client import CoscmdConfig, CosS3Client - from coscmd.cos_global import Version + from xcoscmd.cos_client import CoscmdConfig, CosS3Client + from xcoscmd.cos_global import Version else: from cos_client import CoscmdConfig, CosS3Client from cos_global import Version -logger = logging.getLogger("coscmd") +logger = logging.getLogger("xcoscmd") fs_coding = sys.getfilesystemencoding() @@ -95,7 +95,7 @@ def load_conf(): conf_path = os.path.expanduser(config_path) if not os.path.exists(conf_path): - logger.warn("{conf} couldn't be found, please use \'coscmd config -h\' to learn how to config coscmd!".format(conf=to_printable_str(conf_path))) + logger.warn("{conf} couldn't be found, please use \'xcoscmd config -h\' to learn how to config xcoscmd!".format(conf=to_printable_str(conf_path))) raise IOError else: logger.debug('{conf} is found'.format(conf=to_printable_str(conf_path))) @@ -640,15 +640,15 @@ def get_version(): def version_check(): try: - ret = requests.get("https://pypi.org/pypi/coscmd/json").content + ret = requests.get("https://pypi.org/pypi/xcoscmd/json").content res_json = json.loads(ret) latest_version = res_json["info"]["version"] lat_spl = latest_version.split('.') cur_spl = cos_global.Version.split('.') if cur_spl[0] < lat_spl[0] or cur_spl[1] < lat_spl[1] or cur_spl[2] < lat_spl[2]: - logger.info("The current version of coscmd is {v1} \ + logger.info("The current version of xcoscmd is {v1} \ and the latest version is {v2}. It is recommended \ -to upgrade coscmd with the command'pip install coscmd -U'.".format(v1=cos_global.Version, v2=latest_version)) +to upgrade xcoscmd with the command'pip install xcoscmd -U'.".format(v1=cos_global.Version, v2=latest_version)) except Exception as e: logger.debug(e) @@ -657,8 +657,8 @@ def command_thread(): global res res = -1 desc = """an easy-to-use but powerful command-line tool. - try \'coscmd -h\' to get more informations. - try \'coscmd sub-command -h\' to learn all command usage, likes \'coscmd upload -h\'""" + try \'xcoscmd -h\' to get more informations. + try \'xcoscmd sub-command -h\' to learn all command usage, likes \'xcoscmd upload -h\'""" parser = ArgumentParser(description=desc) parser.add_argument('-d', '--debug', help="Debug mode", action="store_true", default=False) parser.add_argument('-b', '--bucket', help="Specify bucket", type=str, default="") @@ -803,7 +803,7 @@ def command_thread(): args = parser.parse_args() - logger = logging.getLogger('coscmd') + logger = logging.getLogger('xcoscmd') logger.setLevel(logging.INFO) console = logging.StreamHandler() console.setLevel(logging.INFO) @@ -813,7 +813,7 @@ def command_thread(): handler = RotatingFileHandler(os.path.expanduser(args.log_path), maxBytes=128*1024*1024, backupCount=1) handler.setFormatter(logging.Formatter('%(asctime)s - [%(levelname)s]: %(message)s')) logger.addHandler(handler) - logging.getLogger('coscmd').addHandler(console) + logging.getLogger('xcoscmd').addHandler(console) global pre_appid, pre_bucket, pre_region, config_path config_path = args.config_path pre_bucket = args.bucket diff --git a/coscmd/cos_color.py b/xcoscmd/cos_color.py similarity index 100% rename from coscmd/cos_color.py rename to xcoscmd/cos_color.py diff --git a/coscmd/cos_comm.py b/xcoscmd/cos_comm.py similarity index 100% rename from coscmd/cos_comm.py rename to xcoscmd/cos_comm.py diff --git a/xcoscmd/cos_global.py b/xcoscmd/cos_global.py new file mode 100644 index 0000000..7b2bb25 --- /dev/null +++ b/xcoscmd/cos_global.py @@ -0,0 +1 @@ +Version = "1.8.6.4" diff --git a/coscmd/cos_threadpool.py b/xcoscmd/cos_threadpool.py similarity index 95% rename from coscmd/cos_threadpool.py rename to xcoscmd/cos_threadpool.py index 2e678e9..a5dcc4d 100644 --- a/coscmd/cos_threadpool.py +++ b/xcoscmd/cos_threadpool.py @@ -6,7 +6,7 @@ from threading import Lock import gc import time -logger = getLogger("coscmd") +logger = getLogger("xcoscmd") class WorkerThread(Thread): diff --git a/coscmd/test.py b/xcoscmd/test.py similarity index 65% rename from coscmd/test.py rename to xcoscmd/test.py index 46544f1..e47f6df 100644 --- a/coscmd/test.py +++ b/xcoscmd/test.py @@ -43,17 +43,17 @@ def gen_file(path, size): def setUp(): """create testbucket""" os.system("python setup.py install") - os.system("python coscmd/cos_cmd.py config -a %s -s %s -b %s -r %s" % (access_id, access_key, bucket_name, region)) + os.system("python xcoscmd/cos_cmd.py config -a %s -s %s -b %s -r %s" % (access_id, access_key, bucket_name, region)) print("创建bucket") - os.system("python coscmd/cos_cmd.py createbucket >/dev/null 2>&1") + os.system("python xcoscmd/cos_cmd.py createbucket >/dev/null 2>&1") time.sleep(5) def tearDown(): """delete testbucket""" print("删除bucket") - os.system("python coscmd/cos_cmd.py delete -rf / >/dev/null 2>&1") - os.system("python coscmd/cos_cmd.py deletebucket >/dev/null 2>&1") + os.system("python xcoscmd/cos_cmd.py delete -rf / >/dev/null 2>&1") + os.system("python xcoscmd/cos_cmd.py deletebucket >/dev/null 2>&1") time.sleep(5) @@ -63,7 +63,7 @@ def test_upload_object_1MB(): with open(file_name, 'rb') as f: etag = get_raw_md5(f.read()) - rt = os.system("python coscmd/cos_cmd.py upload {local_path} {cos_path} >/dev/null 2>&1".format(local_path=file_name, cos_path=file_name)) + rt = os.system("python xcoscmd/cos_cmd.py upload {local_path} {cos_path} >/dev/null 2>&1".format(local_path=file_name, cos_path=file_name)) assert rt == 0 return etag @@ -71,7 +71,7 @@ def test_upload_object_1MB(): def test_download_object_1MB(): """下载1MB小文件""" etag = test_upload_object_1MB() - rt = os.system("python coscmd/cos_cmd.py download -f {cos_path} {local_path} >/dev/null 2>&1".format(local_path=file_name, cos_path=file_name)) + rt = os.system("python xcoscmd/cos_cmd.py download -f {cos_path} {local_path} >/dev/null 2>&1".format(local_path=file_name, cos_path=file_name)) assert rt == 0 with open(file_name, 'rb') as f: @@ -88,7 +88,7 @@ def test_upload_object_30MB(): with open(file_name, 'rb') as f: etag = get_raw_md5(f.read()) - rt = os.system("python coscmd/cos_cmd.py upload {local_path} {cos_path} >/dev/null 2>&1".format(local_path=file_name, cos_path=file_name)) + rt = os.system("python xcoscmd/cos_cmd.py upload {local_path} {cos_path} >/dev/null 2>&1".format(local_path=file_name, cos_path=file_name)) assert rt == 0 return etag @@ -96,7 +96,7 @@ def test_upload_object_30MB(): def test_download_object_30MB(): """下载30MB文件""" etag = test_upload_object_30MB() - rt = os.system("python coscmd/cos_cmd.py download -f {cos_path} {local_path} >/dev/null 2>&1".format(local_path=file_name, cos_path=file_name)) + rt = os.system("python xcoscmd/cos_cmd.py download -f {cos_path} {local_path} >/dev/null 2>&1".format(local_path=file_name, cos_path=file_name)) assert rt == 0 with open(file_name, 'rb') as f: @@ -110,7 +110,7 @@ def test_download_object_30MB(): def test_delete_object_1MB(): """删除1MB小文件""" test_upload_object_1MB() - rt = os.system("python coscmd/cos_cmd.py delete -f {cos_path} >/dev/null 2>&1".format(cos_path=file_name)) + rt = os.system("python xcoscmd/cos_cmd.py delete -f {cos_path} >/dev/null 2>&1".format(cos_path=file_name)) assert rt == 0 if os.path.exists(file_name): @@ -119,15 +119,15 @@ def test_delete_object_1MB(): def test_bucketacl(): """Bucket ACL测试""" - rt = os.system("python coscmd/cos_cmd.py putbucketacl --grant-read anyone --grant-write anyone --grant-full-control anyone >/dev/null 2>&1") + rt = os.system("python xcoscmd/cos_cmd.py putbucketacl --grant-read anyone --grant-write anyone --grant-full-control anyone >/dev/null 2>&1") assert rt == 0 - rt = os.system("python coscmd/cos_cmd.py getbucketacl >/dev/null 2>&1") + rt = os.system("python xcoscmd/cos_cmd.py getbucketacl >/dev/null 2>&1") assert rt == 0 def test_probe(): """探测测试""" - rt = os.system("python coscmd/cos_cmd.py probe >/dev/null 2>&1") + rt = os.system("python xcoscmd/cos_cmd.py probe >/dev/null 2>&1") assert rt == 0 @@ -141,10 +141,10 @@ def test_upload_folder(): for i in range(file_num): gen_file("testfolder/testfile_" + str(i), 0.01) print("文件夹上传") - rt = os.system("python coscmd/cos_cmd.py upload -r testfolder testfolder >/dev/null 2>&1") + rt = os.system("python xcoscmd/cos_cmd.py upload -r testfolder testfolder >/dev/null 2>&1") assert rt == 0 print("文件夹同步上传") - rt = os.system("python coscmd/cos_cmd.py upload -rs testfolder testfolder >/dev/null 2>&1") + rt = os.system("python xcoscmd/cos_cmd.py upload -rs testfolder testfolder >/dev/null 2>&1") assert rt == 0 os.system("rm -rf testfolder/") @@ -159,14 +159,14 @@ def test_download_folder(): for i in range(file_num): gen_file("testfolder/testfile_" + str(i), 0.01) print("文件夹上传") - rt = os.system("python coscmd/cos_cmd.py upload -r testfolder testfolder >/dev/null 2>&1") + rt = os.system("python xcoscmd/cos_cmd.py upload -r testfolder testfolder >/dev/null 2>&1") assert rt == 0 time.sleep(5) print("文件夹下载") - rt = os.system("python coscmd/cos_cmd.py download -rf testfolder testfolder >/dev/null 2>&1") + rt = os.system("python xcoscmd/cos_cmd.py download -rf testfolder testfolder >/dev/null 2>&1") assert rt == 0 print("文件夹同步下载") - rt = os.system("python coscmd/cos_cmd.py download -rsf testfolder testfolder >/dev/null 2>&1") + rt = os.system("python xcoscmd/cos_cmd.py download -rsf testfolder testfolder >/dev/null 2>&1") assert rt == 0 os.system("rm -rf testfolder/") @@ -181,11 +181,11 @@ def test_copy_folder(): for i in range(file_num): gen_file("testfolder/testfile_" + str(i), 0.01) print("文件夹上传") - rt = os.system("python coscmd/cos_cmd.py upload -r testfolder testfolder >/dev/null 2>&1") + rt = os.system("python xcoscmd/cos_cmd.py upload -r testfolder testfolder >/dev/null 2>&1") assert rt == 0 time.sleep(5) print("文件夹复制") - rt = os.system("python coscmd/cos_cmd.py copy -r %s.cos.%s.myqcloud.com/testfolder testfolder2 >/dev/null 2>&1" % (bucket_name, region)) + rt = os.system("python xcoscmd/cos_cmd.py copy -r %s.cos.%s.myqcloud.com/testfolder testfolder2 >/dev/null 2>&1" % (bucket_name, region)) assert rt == 0 os.system("rm -rf testfolder/") @@ -200,13 +200,13 @@ def test_list_folder(): for i in range(file_num): gen_file("testfolder/testfile_" + str(i), 0.01) print("文件夹上传") - rt = os.system("python coscmd/cos_cmd.py upload -r testfolder testfolder >/dev/null 2>&1") + rt = os.system("python xcoscmd/cos_cmd.py upload -r testfolder testfolder >/dev/null 2>&1") assert rt == 0 time.sleep(5) print("打印对象") - rt = os.system("python coscmd/cos_cmd.py list -n 10 >/dev/null 2>&1") + rt = os.system("python xcoscmd/cos_cmd.py list -n 10 >/dev/null 2>&1") print("打印全部对象") - rt = os.system("python coscmd/cos_cmd.py list -ar >/dev/null 2>&1") + rt = os.system("python xcoscmd/cos_cmd.py list -ar >/dev/null 2>&1") assert rt == 0 os.system("rm -rf testfolder/") From 65474aee08ebd9bb08035f89b01c60a7070d2603 Mon Sep 17 00:00:00 2001 From: aslinwang Date: Mon, 14 Sep 2020 20:52:13 +0800 Subject: [PATCH 6/9] Update README.rst --- README.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index a723b94..baf7b44 100644 --- a/README.rst +++ b/README.rst @@ -22,13 +22,15 @@ __________ cd dist sudo easy_install coscmd-1.8.6.3-py3.6.egg # 提前安装easy_install ln -s {{PYTHON_DIR}}/bin/coscmd xcoscmd # [可选]为避免和官方coscmd冲突,通过软链使用此版本 - 或 :: pip install xcoscmd -i https://pypi.tuna.tsinghua.edu.cn/simple - 或 pip install xcoscmd -i https://pypi.doubanio.com/simple - 或 pip install xcoscmd -i http://mirrors.tencent.com/pypi/simple - +或 +:: + pip install xcoscmd -i https://pypi.doubanio.com/simple +或 +:: + pip install xcoscmd -i http://mirrors.tencent.com/pypi/simple 改造 __________ From 88bd3c3de94071f2efad27d7c6543cfd8cc4167e Mon Sep 17 00:00:00 2001 From: aslinwang Date: Sat, 6 Mar 2021 18:13:58 +0800 Subject: [PATCH 7/9] Update README.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit centos python环境安装说明 --- README.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.rst b/README.rst index baf7b44..26cb4d9 100644 --- a/README.rst +++ b/README.rst @@ -47,3 +47,10 @@ __________ 使用coscmd,参照 https://cloud.tencent.com/document/product/436/10976 +附录:CentOS Python环境安装 +__________ +:: + yum install python3 + wget https://bootstrap.pypa.io/3.2/get-pip.py + python3 get-pip.py + From 928c101d0afb1e48e02e9c0f9515d38dc6e5de6e Mon Sep 17 00:00:00 2001 From: aslinwang Date: Sat, 6 Mar 2021 18:14:30 +0800 Subject: [PATCH 8/9] Update README.rst update readme --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 26cb4d9..d106b4c 100644 --- a/README.rst +++ b/README.rst @@ -49,6 +49,7 @@ __________ 附录:CentOS Python环境安装 __________ + :: yum install python3 wget https://bootstrap.pypa.io/3.2/get-pip.py From 63eeb7f2a57c56f9ecafc3b29249d936783f8fef Mon Sep 17 00:00:00 2001 From: aslinwang Date: Sat, 6 Mar 2021 18:14:58 +0800 Subject: [PATCH 9/9] Update README.rst update readme --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index d106b4c..85a7655 100644 --- a/README.rst +++ b/README.rst @@ -51,6 +51,7 @@ __________ __________ :: + yum install python3 wget https://bootstrap.pypa.io/3.2/get-pip.py python3 get-pip.py