From edd6ea8dc7ca6230260cad3e21047eac9d591f00 Mon Sep 17 00:00:00 2001 From: han0 Date: Wed, 22 Mar 2023 10:00:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(core.file):=20=E6=96=B0=E5=A2=9E=20move=5F?= =?UTF-8?q?file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nc_http/core/file/func.py | 20 +++++++++++++++++++- upload.bat | 4 ++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 upload.bat diff --git a/nc_http/core/file/func.py b/nc_http/core/file/func.py index b571dcc..1246a26 100644 --- a/nc_http/core/file/func.py +++ b/nc_http/core/file/func.py @@ -1,4 +1,5 @@ import os +import shutil import time import requests @@ -12,7 +13,7 @@ def download_file(url: str, path: str) -> str: return path -def save_file(f: FileStorage, path: str, namespace: str=None, filename: str=None) -> str: +def save_file(f: FileStorage, path: str, namespace: str = None, filename: str = None) -> str: if namespace: save_path = os.path.join(path, namespace.replace('.', os.path.sep)) else: @@ -27,3 +28,20 @@ def save_file(f: FileStorage, path: str, namespace: str=None, filename: str=None tmp_f.write(f.read()) return os.path.join(save_path, filename) + + +def move_file(file_path: str, path: str, namespace: str = None, filename: str = None) -> str: + if namespace: + save_path = os.path.join(path, namespace.replace('.', os.path.sep)) + else: + save_path = path + + if not os.path.exists(save_path): + os.makedirs(save_path) + + filename = filename or '{}{}'.format(str(int(time.time() * 1000)), os.path.splitext(file_path)[-1]) + target_file_path = os.path.join(save_path, filename) + + shutil.move(file_path, target_file_path) + + return target_file_path diff --git a/upload.bat b/upload.bat new file mode 100644 index 0000000..1ac6c12 --- /dev/null +++ b/upload.bat @@ -0,0 +1,4 @@ +python36 -m pip install --upgrade setuptools wheel twine -i https://pypi.douban.com/simple +python36 setup.py sdist bdist_wheel +twine check dist/* +twine upload --repository-url http://192.168.12.2:8082/repository/pypi-hosted/ dist/* \ No newline at end of file