treehash from list to dict

This commit is contained in:
Amber 2024-11-27 09:38:02 +01:00
parent 2f919d14e4
commit 1ab43eb00f
2 changed files with 18 additions and 12 deletions

View File

@ -211,11 +211,9 @@ class AdvancedSftpClientAgent(BaseAgent):
return (io.BytesIO(buf), dig)
def generate_tree_oversftp(self, root_path :str, treemap :list=[]):
def generate_tree_structure_oversftp(self, root_path :str):
'''
@param root_path string
generate an ordered list of entries, similar to `find ~/sharednotes_dev/ -print`
command
'''
if not root_path.endswith(os.path.sep):
root_path = root_path + os.path.sep
@ -224,6 +222,8 @@ class AdvancedSftpClientAgent(BaseAgent):
# treemap = []
sftpc = self.get_sftp_client()
treemap = {}
for item in sftpc.listdir_attr(root_path):
# absolute_item_path = root_path + item.filename
# print('absolute_item_path: %s, item %s, isdir: %s' % (absolute_item_path, item.filename, stat.S_ISDIR(item.st_mode)))
@ -236,14 +236,15 @@ class AdvancedSftpClientAgent(BaseAgent):
continue
absolute_item_path = root_path + item.filename
# print('absolute_item_path: %s, item %s, isdir: %s' % (absolute_item_path, item, os.path.isdir(absolute_item_path)))
treemap.append(absolute_item_path)
if not stat.S_ISDIR(item.st_mode): continue
if not stat.S_ISDIR(item.st_mode):
treemap[absolute_item_path] = ""
continue
self.generate_tree_oversftp(absolute_item_path, treemap)
treemap[absolute_item_path] = self.generate_tree_structure_oversftp(absolute_item_path)
return treemap
def generate_hash_tree_oversftp(self, root_path: str):
def generate_tree_structure_hash_oversftp(self, root_path: str):
root_path = _path_utils.normalize_path(root_path)
tree = self.generate_tree_oversftp(root_path)
pickled = pickle.dumps(tree)

View File

@ -4,7 +4,7 @@ import hashlib
from lib.utils import path_utils as _path_utils
def generate_tree(root_path :str, treemap :list=[]):
def generate_tree_structure(root_path :str):
'''
@param root_path string
generate an ordered list of entries, similar to `find ~/sharednotes_dev/ -print`
@ -13,20 +13,25 @@ def generate_tree(root_path :str, treemap :list=[]):
root_path = _path_utils.normalize_path(root_path)
items = os.listdir(root_path)
treemap = {}
for item in sorted(items):
## exclude folder for the tree
if item in ['.masy']:
continue
absolute_item_path = root_path + item
print('absolute_item_path: %s, item %s, isdir: %s' % (absolute_item_path, item, os.path.isdir(absolute_item_path)))
treemap.append(absolute_item_path)
if not os.path.isdir(absolute_item_path): continue
# treemap.append(absolute_item_path)
if not os.path.isdir(absolute_item_path):
treemap[absolute_item_path] = ''
continue
generate_tree(absolute_item_path, treemap)
treemap[absolute_item_path] = generate_tree(absolute_item_path)
return treemap
def generate_hash_tree(root_path: str):
def generate_tree_structure_hash(root_path: str):
root_path = _path_utils.check_isdir(root_path)
root_path = _path_utils.normalize_path(root_path)
base_path = root_path