agent generate_hash_tree_oversftp
This commit is contained in:
parent
7428316621
commit
2f919d14e4
@ -7,6 +7,7 @@ import errno
|
||||
import asyncio
|
||||
import hashlib
|
||||
import io
|
||||
import pickle
|
||||
|
||||
import functools
|
||||
|
||||
@ -210,6 +211,45 @@ class AdvancedSftpClientAgent(BaseAgent):
|
||||
|
||||
return (io.BytesIO(buf), dig)
|
||||
|
||||
def generate_tree_oversftp(self, root_path :str, treemap :list=[]):
|
||||
'''
|
||||
@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
|
||||
|
||||
# a = self.agent
|
||||
# treemap = []
|
||||
sftpc = self.get_sftp_client()
|
||||
|
||||
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)))
|
||||
# if stat.S_ISDIR(item.st_mode):
|
||||
# rtreemap[item.filename] = self.generate_tree_hash_oversftp(absolute_item_path)
|
||||
# else:
|
||||
# rtreemap[item.filename] = self.generate_rfile_hash(absolute_item_path)
|
||||
## exclude folder for the tree
|
||||
if item in ['.masy']:
|
||||
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
|
||||
|
||||
self.generate_tree_oversftp(absolute_item_path, treemap)
|
||||
|
||||
return treemap
|
||||
|
||||
def generate_hash_tree_oversftp(self, root_path: str):
|
||||
root_path = _path_utils.normalize_path(root_path)
|
||||
tree = self.generate_tree_oversftp(root_path)
|
||||
pickled = pickle.dumps(tree)
|
||||
return hashlib.sha256(pickled).hexdigest()
|
||||
|
||||
|
||||
def generate_tree_hash_oversftp(self, root_path :str):
|
||||
'''
|
||||
@param root_path string, root_path in remote server
|
||||
|
Loading…
Reference in New Issue
Block a user