最新版
This commit is contained in:
1 parent
b8f5091514
commit
47bad0c0cb
11 files changed
+100
-31
No files matched your search
@@ -20,11 +20,15 @@ def upLoadSliceFileToOSS(data):
|
||||
print(f"错误:dataFolder 文件夹不存在 - {dataFolder}")
|
||||
exit(1)
|
||||
dataFilePath = ""
|
||||
print(f"开始上传文件: {dataFolder},{os.listdir(dataFolder)}")
|
||||
for file1 in os.listdir(dataFolder):
|
||||
if os.path.isdir(file1):
|
||||
if os.path.isdir(os.path.join(dataFolder,file1)):
|
||||
dataFilePath = os.path.join(dataFolder,file1, 'data.snslc')
|
||||
if os.path.exists(dataFilePath):
|
||||
upload_file(f"slice/complate/{data}/data.snslc", dataFilePath)
|
||||
print(f"开始上传文件: {dataFilePath},文件存在")
|
||||
return upload_file(f"slice/complate/{data}/data.snslc", dataFilePath)
|
||||
print(f"开始上传文件: {dataFilePath},文件不存在")
|
||||
return False
|
||||
|
||||
|
||||
#"C:/test/10192_small_No4/data"
|
||||
@@ -87,12 +91,19 @@ def main(work_dir=None):
|
||||
time.sleep(10)
|
||||
continue
|
||||
data = data.decode('utf-8')
|
||||
# data = "10192_small_No4"
|
||||
# 判断是否是字符串
|
||||
if not isinstance(data, str):
|
||||
log("取出的数据不是字符串")
|
||||
time.sleep(10)
|
||||
continue
|
||||
folderPath = os.path.join(work_dir,"batchPrint", data,"data")
|
||||
# 判断目录是否存在
|
||||
if not os.path.exists(folderPath):
|
||||
log(f"目录不存在: {folderPath}")
|
||||
time.sleep(10)
|
||||
continue
|
||||
|
||||
# data 格式为 batchId_machineType_No machineId
|
||||
batchId = data.split('_')[0] #批次ID
|
||||
# machineType = data.split('_')[1] #机型类型
|
||||
|
||||
@@ -33,24 +33,23 @@ def getCurrentMachineId():
|
||||
return machineId
|
||||
|
||||
def main(work_dir=None):
|
||||
# if work_dir is None:
|
||||
# log("工作目录不能为空")
|
||||
# exit(0)
|
||||
# redis 获取队列中的数据
|
||||
|
||||
downloadPath = cfg('machine.download_path', None)
|
||||
if downloadPath is None:
|
||||
log("工作目录不能为空")
|
||||
exit(0)
|
||||
if not os.path.exists(downloadPath):
|
||||
os.makedirs(downloadPath)
|
||||
|
||||
|
||||
r = redisClient()
|
||||
machineId = getCurrentMachineId()
|
||||
if machineId is None:
|
||||
log("获取当前电脑id失败")
|
||||
exit(0)
|
||||
|
||||
downloadPath = cfg('machine.download_path', None)
|
||||
if downloadPath is None:
|
||||
log("数据存放路径失败没有设置")
|
||||
exit(0)
|
||||
|
||||
|
||||
while True:
|
||||
data = r.lpop('pb:begin_print_machine_'+machineId)
|
||||
data = r.spop('pb:begin_print_machine_'+machineId)
|
||||
if data is None:
|
||||
log("队列为空")
|
||||
time.sleep(10)
|
||||
@@ -63,17 +62,17 @@ def main(work_dir=None):
|
||||
continue
|
||||
# batchId = str(data)
|
||||
ossZipPath = f'slice/complate/{data}/data.snslc'
|
||||
localPath = os.path.join(downloadPath, f'data.snslc')
|
||||
localPath = os.path.join(downloadPath,data, f'data.snslc')
|
||||
# 判断目录是否存在,不存在就创建
|
||||
if not os.path.exists(os.path.join(downloadPath)):
|
||||
os.makedirs(os.path.join(downloadPath))
|
||||
else:
|
||||
# 删除目录下的所有文件
|
||||
for file in os.listdir(os.path.join(downloadPath)):
|
||||
os.remove(os.path.join(downloadPath, file))
|
||||
|
||||
# 删除目录下指定文件,如果存在
|
||||
if os.path.exists(os.path.join(downloadPath,data, f'data.snslc')):
|
||||
os.remove(os.path.join(downloadPath,data, f'data.snslc'))
|
||||
# 下载 zip 文件
|
||||
downloadZip(ossZipPath, localPath)
|
||||
th, localPath)
|
||||
# # 解压 zip 文件
|
||||
# localUnzipPath = os.path.join(work_dir,batchId)
|
||||
# unzip(localZipPath, localUnzipPath)
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
from .utils.miniIo import upload_file
|
||||
|
||||
|
||||
# 测试上传文件
|
||||
def test_upload_file():
|
||||
upload_file("test.txt", "test.txt")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_upload_file()
|
||||
@@ -0,0 +1 @@
|
||||
AAAAAAAAAAA
|
||||
@@ -15,7 +15,7 @@ def get_bucket_name():
|
||||
global _bucket_name
|
||||
if _bucket_name is None:
|
||||
# 优先从配置文件读取,如果没有则从环境变量读取,最后使用默认值
|
||||
_bucket_name = cfg('minio.bucket', None) or os.getenv('MINIO_BUCKET', 'default-bucket')
|
||||
_bucket_name = cfg('minio.bucket', None)
|
||||
log(f"MiniIO 存储桶名称: {_bucket_name}")
|
||||
return _bucket_name
|
||||
|
||||
@@ -33,10 +33,17 @@ class MiniIOClientSingleton:
|
||||
if self._client is None:
|
||||
# MiniIO 连接配置
|
||||
# 可以从环境变量或配置文件中读取
|
||||
endpoint = os.getenv('MINIO_ENDPOINT', 'localhost:9000')
|
||||
access_key = os.getenv('MINIO_ACCESS_KEY', 'minioadmin')
|
||||
secret_key = os.getenv('MINIO_SECRET_KEY', 'minioadmin')
|
||||
secure = os.getenv('MINIO_SECURE', 'False').lower() == 'true'
|
||||
endpoint = cfg('minio.endpoint', 'localhost:9000')
|
||||
access_key = cfg('minio.access_key', 'minioadmin')
|
||||
secret_key = cfg('minio.secret_key', 'minioadmin')
|
||||
# secure 参数:True 使用 HTTPS,False 使用 HTTP
|
||||
# 从配置文件读取,如果没有配置则默认为 False(HTTP)
|
||||
secure_config = cfg('minio.secure', False)
|
||||
# 确保是布尔值(处理字符串 'true'/'false' 的情况)
|
||||
if isinstance(secure_config, str):
|
||||
secure = secure_config.lower() in ('true', '1', 'yes')
|
||||
else:
|
||||
secure = bool(secure_config)
|
||||
|
||||
try:
|
||||
self._client = Minio(
|
||||
@@ -45,9 +52,16 @@ class MiniIOClientSingleton:
|
||||
secret_key=secret_key,
|
||||
secure=secure
|
||||
)
|
||||
log(f"MiniIO 客户端初始化成功: {endpoint}")
|
||||
log(f"MiniIO 客户端初始化成功: {endpoint} (secure={secure})")
|
||||
except Exception as e:
|
||||
log(f"MiniIO 客户端初始化失败: {str(e)}")
|
||||
error_msg = str(e)
|
||||
# 检查是否是端口错误
|
||||
if "API port" in error_msg or "InvalidArgument" in error_msg:
|
||||
log(f"MiniIO 连接失败: 请确保使用的是 API 端口(通常是 9000),而不是 Console 端口(通常是 9001)")
|
||||
log(f"当前配置的 endpoint: {endpoint}")
|
||||
log(f"错误详情: {error_msg}")
|
||||
else:
|
||||
log(f"MiniIO 客户端初始化失败: {error_msg}")
|
||||
raise
|
||||
return self._client
|
||||
|
||||
|
||||
Reference in new issue
Block a user