key names, conventions

This commit is contained in:
Amber 2024-09-29 22:18:10 +02:00
parent 01a1b1a258
commit d244cf190e
2 changed files with 17 additions and 16 deletions

View File

@ -25,6 +25,7 @@ def decode_snap():
def recursive_diff_snap(last_tree, current_tree, path='./', bres={}): def recursive_diff_snap(last_tree, current_tree, path='./', bres={}):
''' '''
XXX: use key names convention specified in lib/repr/node.py
snapshot is a tree represented by dictionary {k, val} when k can be folder or file name snapshot is a tree represented by dictionary {k, val} when k can be folder or file name
and val can be a dictionary or an hash and val can be a dictionary or an hash
@ -42,9 +43,9 @@ def recursive_diff_snap(last_tree, current_tree, path='./', bres={}):
print(f'file {path}{key_added} subtree added in current snapshot') print(f'file {path}{key_added} subtree added in current snapshot')
item = { item = {
'name' : key_added, 'name' : key_added,
'path' : '%s' % (path,), 'rel_path' : '%s' % (path,),
'type' : 'd' if isinstance(current_tree[key_added], dict) else 'f', 'cur_type' : 'd' if isinstance(current_tree[key_added], dict) else 'f',
'hash' : current_tree[key_added], 'cur_hash' : current_tree[key_added],
} }
added.append(item) added.append(item)
@ -55,7 +56,7 @@ def recursive_diff_snap(last_tree, current_tree, path='./', bres={}):
item = { item = {
'name' : name_last, 'name' : name_last,
'path' : path, 'rel_path' : path,
# 'last_hash' : hsh_last, # 'last_hash' : hsh_last,
} }
@ -63,8 +64,8 @@ def recursive_diff_snap(last_tree, current_tree, path='./', bres={}):
## 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')
item.update({ item.update({
'type' : last_type, 'last_type' : last_type,
'hash' : hsh_last, 'last_hash' : hsh_last,
}) })
removed.append(item) removed.append(item)
continue continue
@ -75,7 +76,7 @@ def recursive_diff_snap(last_tree, current_tree, path='./', bres={}):
print(f'{path}{name_last} changed his type in {current_type}') print(f'{path}{name_last} changed his type in {current_type}')
item.update({ item.update({
'last_type' : last_type, 'last_type' : last_type,
'current_type' : current_type, 'cur_type' : current_type,
}) })
changed.append(item) changed.append(item)
continue continue
@ -86,7 +87,7 @@ def recursive_diff_snap(last_tree, current_tree, path='./', bres={}):
print(f'file {path}{name_last} changed his hash') print(f'file {path}{name_last} changed his hash')
item.update({ item.update({
'last_type' : last_type, 'last_type' : last_type,
'current_type' : current_type, 'cur_type' : current_type,
'cur_hash' : hsh_current, 'cur_hash' : hsh_current,
'last_hash' : hsh_last, 'last_hash' : hsh_last,
}) })

View File

@ -112,7 +112,7 @@ class Manager():
# node_path = node['path'] # node_path = node['path']
# node_name = node['name'] # node_name = node['name']
# return tree_diff_path # return tree_diff_path
return node['path'].replace('.%s' % (os.sep), tree_diff_path) return node['rel_path'].replace('.%s' % (os.sep), tree_diff_path)
def dump_local_hash(self, hsh=None): def dump_local_hash(self, hsh=None):
# local_path = self.local_path # local_path = self.local_path
@ -134,21 +134,21 @@ class Manager():
return snapshot return snapshot
def get_unmerged_local_path(self, node): def get_unmerged_local_path(self, node):
node_path = node['path'] node_path = node['rel_path']
node_name = node['name'] node_name = node['name']
unmerged_local_file_path = '%s%s' % (node_path, node_name) unmerged_local_file_path = '%s%s' % (node_path, node_name)
unmerged_file_path = unmerged_local_file_path.replace('.%s' % (os.sep), self.get_unmerged_path()) unmerged_file_path = unmerged_local_file_path.replace('.%s' % (os.sep), self.get_unmerged_path())
return unmerged_file_path return unmerged_file_path
def get_absolute_local_path(self, node): def get_absolute_local_path(self, node):
node_path = node['path'] node_path = node['rel_path']
node_name = node['name'] node_name = node['name']
local_file_path = '%s%s' % (node_path, node_name) local_file_path = '%s%s' % (node_path, node_name)
local_file_path = local_file_path.replace('.%s' % (os.sep), self.local_path) local_file_path = local_file_path.replace('.%s' % (os.sep), self.local_path)
return local_file_path return local_file_path
def get_absolute_remote_path(self, node): def get_absolute_remote_path(self, node):
node_path = node['path'] node_path = node['rel_path']
node_name = node['name'] node_name = node['name']
remote_file_path = '%s%s' % (node_path, node_name) remote_file_path = '%s%s' % (node_path, node_name)
remote_file_path = remote_file_path.replace('.%s' % (os.sep), self.remote_path) remote_file_path = remote_file_path.replace('.%s' % (os.sep), self.remote_path)
@ -264,7 +264,7 @@ class Manager():
pass pass
# node_type = node['type'] # node_type = node['type']
# node_name = node['name'] # node_name = node['name']
# node_path = node['path'] # node_path = node['rel_path']
# #
# agent = self.get_agent() # agent = self.get_agent()
# #
@ -275,7 +275,7 @@ class Manager():
unmerged = self.load_unmerged_diff() unmerged = self.load_unmerged_diff()
for n, unode in enumerate(unmerged): for n, unode in enumerate(unmerged):
i = n+1 i = n+1
path = unode['path'] path = unode['rel_path']
name = unode['name'] name = unode['name']
remote_hash = unode['remote_hash'] remote_hash = unode['remote_hash']
last_type = unode['last_type'] last_type = unode['last_type']
@ -283,13 +283,13 @@ class Manager():
def mark_conflicting_node_as_solved(self, node): def mark_conflicting_node_as_solved(self, node):
name = node['name'] name = node['name']
path = node['path'] path = node['rel_path']
unmerged = self.load_unmerged_diff() unmerged = self.load_unmerged_diff()
found = {} found = {}
for n, unode in enumerate(unmerged): for n, unode in enumerate(unmerged):
if unode['name'] == name and unode['path'] == path: if unode['name'] == name and unode['rel_path'] == path:
found = unode found = unode
break break
else: else: