treehash from list to dict
This commit is contained in:
parent
2f919d14e4
commit
1ab43eb00f
@ -211,11 +211,9 @@ class AdvancedSftpClientAgent(BaseAgent):
|
|||||||
|
|
||||||
return (io.BytesIO(buf), dig)
|
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
|
@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):
|
if not root_path.endswith(os.path.sep):
|
||||||
root_path = root_path + os.path.sep
|
root_path = root_path + os.path.sep
|
||||||
@ -224,6 +222,8 @@ class AdvancedSftpClientAgent(BaseAgent):
|
|||||||
# treemap = []
|
# treemap = []
|
||||||
sftpc = self.get_sftp_client()
|
sftpc = self.get_sftp_client()
|
||||||
|
|
||||||
|
treemap = {}
|
||||||
|
|
||||||
for item in sftpc.listdir_attr(root_path):
|
for item in sftpc.listdir_attr(root_path):
|
||||||
# absolute_item_path = root_path + item.filename
|
# 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)))
|
# 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
|
continue
|
||||||
absolute_item_path = root_path + item.filename
|
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)))
|
# 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):
|
||||||
if not stat.S_ISDIR(item.st_mode): continue
|
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
|
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)
|
root_path = _path_utils.normalize_path(root_path)
|
||||||
tree = self.generate_tree_oversftp(root_path)
|
tree = self.generate_tree_oversftp(root_path)
|
||||||
pickled = pickle.dumps(tree)
|
pickled = pickle.dumps(tree)
|
||||||
|
@ -4,7 +4,7 @@ import hashlib
|
|||||||
|
|
||||||
from lib.utils import path_utils as _path_utils
|
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
|
@param root_path string
|
||||||
generate an ordered list of entries, similar to `find ~/sharednotes_dev/ -print`
|
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)
|
root_path = _path_utils.normalize_path(root_path)
|
||||||
|
|
||||||
items = os.listdir(root_path)
|
items = os.listdir(root_path)
|
||||||
|
|
||||||
|
treemap = {}
|
||||||
|
|
||||||
for item in sorted(items):
|
for item in sorted(items):
|
||||||
## exclude folder for the tree
|
## exclude folder for the tree
|
||||||
if item in ['.masy']:
|
if item in ['.masy']:
|
||||||
continue
|
continue
|
||||||
absolute_item_path = root_path + item
|
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)))
|
print('absolute_item_path: %s, item %s, isdir: %s' % (absolute_item_path, item, os.path.isdir(absolute_item_path)))
|
||||||
treemap.append(absolute_item_path)
|
# treemap.append(absolute_item_path)
|
||||||
if not os.path.isdir(absolute_item_path): continue
|
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
|
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.check_isdir(root_path)
|
||||||
root_path = _path_utils.normalize_path(root_path)
|
root_path = _path_utils.normalize_path(root_path)
|
||||||
base_path = root_path
|
base_path = root_path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user