binary snapdiff
This commit is contained in:
parent
6d46b83fe4
commit
40bde46f8b
Binary file not shown.
@ -8,7 +8,7 @@ def dmpsnap(root_tree: str):
|
|||||||
def dcsnap(path: str, filename=None):
|
def dcsnap(path: str, filename=None):
|
||||||
return _dump.decode_snapshot(path, dump_file_name = filename)
|
return _dump.decode_snapshot(path, dump_file_name = filename)
|
||||||
|
|
||||||
def diffsnap(last_tree, current_tree, path='./', removed=[], changed=[], added=[]):
|
def diffsnap(last_tree, current_tree, path='./', bres={}):
|
||||||
'''
|
'''
|
||||||
snapshot is a tree represented by dictionary {k, val} when k can be folder or file
|
snapshot is a tree represented by dictionary {k, val} when k can be folder or file
|
||||||
and val can be a dictionary or an hash
|
and val can be a dictionary or an hash
|
||||||
@ -16,9 +16,9 @@ def diffsnap(last_tree, current_tree, path='./', removed=[], changed=[], added=[
|
|||||||
@param last_tree snapshot computed at time t0
|
@param last_tree snapshot computed at time t0
|
||||||
@param current_tree snapshot computed at time t1
|
@param current_tree snapshot computed at time t1
|
||||||
'''
|
'''
|
||||||
removed = []
|
removed = bres.setdefault('removed', [])
|
||||||
changed = []
|
changed = bres.setdefault('changed', [])
|
||||||
added = []
|
added = bres.setdefault('added', [])
|
||||||
|
|
||||||
for name_last, hsh_last in last_tree.items():
|
for name_last, hsh_last in last_tree.items():
|
||||||
hsh_current = current_tree.get(name_last)
|
hsh_current = current_tree.get(name_last)
|
||||||
@ -34,30 +34,33 @@ def diffsnap(last_tree, current_tree, path='./', removed=[], changed=[], added=[
|
|||||||
if hsh_current is None:
|
if hsh_current is None:
|
||||||
## the name in not founded in current snapshot - Subtree removed (or moved)
|
## the name in not founded in current snapshot - Subtree removed (or moved)
|
||||||
print(f'{path}{name_last} present in last_tree but removed in current_tree, subtree {name_last} removed in current_tree')
|
print(f'{path}{name_last} present in last_tree but removed in current_tree, subtree {name_last} removed in current_tree')
|
||||||
removed.append(item.update({
|
item.update({
|
||||||
'last_type' : 'dir',
|
'last_type' : 'dir',
|
||||||
}))
|
})
|
||||||
|
removed.append(item)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
current_type = 'dir' if isinstance(hsh_current, dict) else 'file'
|
current_type = 'dir' if isinstance(hsh_current, dict) else 'file'
|
||||||
|
|
||||||
if type(hsh_last) != type(hsh_current):
|
if type(hsh_last) != type(hsh_current):
|
||||||
print(f'{path}{name_last} changed his type in {current_type}')
|
print(f'{path}{name_last} changed his type in {current_type}')
|
||||||
changed.append(item.update({
|
item.update({
|
||||||
'last_type' : last_type,
|
'last_type' : last_type,
|
||||||
'current_type' : current_type,
|
'current_type' : current_type,
|
||||||
}))
|
})
|
||||||
|
changed.append(item)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if isinstance(hsh_last, str):
|
if isinstance(hsh_last, str):
|
||||||
if hsh_last != hsh_current:
|
if hsh_last != hsh_current:
|
||||||
print(f'file {path}{name_last} changed his hash')
|
print(f'file {path}{name_last} changed his hash')
|
||||||
changed.append(item.update({
|
item.update({
|
||||||
'last_type' : last_type,
|
'last_type' : last_type,
|
||||||
'current_type' : current_type,
|
'current_type' : current_type,
|
||||||
'last_hash' : hsh_last,
|
'last_hash' : hsh_last,
|
||||||
'cur_hash' : hsh_current,
|
'cur_hash' : hsh_current,
|
||||||
}))
|
})
|
||||||
|
changed.append(item)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# name is dir
|
# name is dir
|
||||||
@ -71,8 +74,18 @@ def diffsnap(last_tree, current_tree, path='./', removed=[], changed=[], added=[
|
|||||||
if keys_added:
|
if keys_added:
|
||||||
for key_added in keys_added:
|
for key_added in keys_added:
|
||||||
print(f'file {path}{name_last}/{key_added} subtree added in current snapshot')
|
print(f'file {path}{name_last}/{key_added} subtree added in current snapshot')
|
||||||
|
item.update({
|
||||||
|
'name' : key_added,
|
||||||
|
'path' : '%s%s' % (path, name_last),
|
||||||
|
'current_type' : 'dir' if isinstance(current_tree[name_last][key_added], dict) else 'file'
|
||||||
|
})
|
||||||
|
added.append(item)
|
||||||
|
|
||||||
diffsnap(hsh_last, hsh_current, path='%s%s/' % (path,name_last))
|
diffsnap(hsh_last, hsh_current, path='%s%s/' % (path,name_last), bres = {
|
||||||
|
'removed' : removed,
|
||||||
|
'added' : added,
|
||||||
|
'changed' : changed,
|
||||||
|
})
|
||||||
|
|
||||||
def findsubtree(snapshot, subtree, path='./'):
|
def findsubtree(snapshot, subtree, path='./'):
|
||||||
'''
|
'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user