|
@@ -0,0 +1,31 @@
|
|
|
+"""
|
|
|
+ encoding: UTF-8
|
|
|
+ @author:clx
|
|
|
+ @file:config.py.py
|
|
|
+ @time:2023/5/31 12:48
|
|
|
+"""
|
|
|
+import json
|
|
|
+from minio import Minio
|
|
|
+
|
|
|
+
|
|
|
+# 从配置文件读取设置
|
|
|
+class MinioOperate:
|
|
|
+
|
|
|
+ def __init__(self):
|
|
|
+ with open(r"config/config.json", "r") as f:
|
|
|
+ self.__config = json.load(f)
|
|
|
+ self.minio_client = None
|
|
|
+
|
|
|
+ def link_minio(self):
|
|
|
+ self.minio_client = Minio(**self.__config["minio"])
|
|
|
+ return self.minio_client
|
|
|
+
|
|
|
+ def create_bucket(self):
|
|
|
+ for bucket_name in self.__config['buckets']:
|
|
|
+ if not self.minio_client.bucket_exists(bucket_name):
|
|
|
+ try:
|
|
|
+ self.minio_client.make_bucket(bucket_name)
|
|
|
+ except Exception as e:
|
|
|
+ print(f"Bucket creation failed: {e}")
|
|
|
+ else:
|
|
|
+ print(f"Bucket {bucket_name} already exists")
|