丁云鹏 пре 5 месеци
родитељ
комит
2fe023e41f

+ 36 - 0
recommend-model-produce/src/main/python/tools/utils/compress.py

@@ -0,0 +1,36 @@
+# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import tarfile
+
+def compress_tar(folder_path, output_filename):
+    # 确保输出文件名以 .tar.gz 结尾
+    if not output_filename.endswith('.tar.gz'):
+        output_filename += '.tar.gz'
+
+    # 创建一个 tarfile 对象,使用 'w:gz' 模式表示写入 gzip 压缩的 tar 包
+    with tarfile.open(output_filename, "w:gz") as tar:
+        # os.walk() 遍历目录
+        for root, dirs, files in os.walk(folder_path):
+            for file in files:
+                # 构建完整的文件路径
+                file_path = os.path.join(root, file)
+                # 将文件添加到 tar 包中,arcname 指定在 tar 包中的相对路径
+                tar.add(file_path, arcname=os.path.relpath(file_path, start=folder_path))
+
+if __name__ == "__main__":
+    folder_path="/Users/dingyunpeng/tardemo"
+    output_filename="/Users/dingyunpeng/tardemo"
+    compress_tar(folder_path, output_filename)

+ 30 - 0
recommend-model-produce/src/main/python/tools/utils/oss_client.py

@@ -0,0 +1,30 @@
+import oss2
+import logging
+
+logging.basicConfig(
+    format='%(asctime)s - %(levelname)s - %(message)s', level=logging.INFO)
+logger = logging.getLogger(__name__)
+
+access_key_id="LTAI5tHMkNaRhpiDB1yWMZPn"
+access_key_secret="XLi5YUJusVwbbQOaGeGsaRJ1Qyzbui"
+auth = oss2.AuthV4(access_key_id, access_key_secret)
+
+hangzhou_config = {
+    "endpoint" : "https://oss-cn-hangzhou.aliyuncs.com",
+    "inner_endpoint" : "https://oss-cn-hangzhou-internal.aliyuncs.com",
+    "region" : "cn-hangzhou"
+}
+
+class HangZhouOSSClient:
+    def __init__(self, bucket_name):
+        self.bucket_name = bucket_name
+        self.bucket = oss2.Bucket(auth, hangzhou_config["endpoint"], bucket_name, region=hangzhou_config["region"])
+
+    def put_object_from_file(self, object_name, local_file):
+        result = self.bucket.put_object_from_file(object_name, local_file)
+        logger.info("\n status: {} \n request_id: {} \n ETag: {} \n date: {}".format(result.status, result.request_id,
+        result.etag, result.headers['date']))
+
+if __name__ == "__main__":
+    client = HangZhouOSSClient("art-recommend")
+    client.put_object_from_file("dyp/stuuudy.pem", "/Users/dingyunpeng/stuuudy.pem")