Files
ThousandHands/core/objects/tree_object.py
2024-11-12 20:30:19 +08:00

34 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
********************************************
* @Date: 2024 09 27
* @Description: BackObject树对象,标记多个存储存储对象和树对象,为备份对象提供目标
********************************************
"""
from typing import Dict, List
from .blob_object import BlobObject
import os
import asyncio
class TreeObject:
__children: List[BlobObject] = [] # 备份树节点列表节点为BlobObject备份存储对象
__file_map: Dict[str, str] = {} # 备份文件路径到blob对象的映射
def __init__(self, tree_path: str):
self.tree_path = tree_path
self.__loadChildren()
def __loadChildren(self):
for root, dirs, files in os.walk(self.tree_path):
for name in files:
blob_path = os.path.join(root, name)
blob = BlobObject(blob_path)
self.__children.append(blob)
self.__file_map[blob_path] = blob.object_id
async def writeBlobs(self, base_path: str):
tasks = []
for child in self.__children:
tasks.append(asyncio.create_task(child.writeBlob(base_path)))
asyncio.gather(*tasks)