to be rationalized
This commit is contained in:
parent
7d6613b731
commit
7edb0f1441
@ -157,14 +157,14 @@ class Manager():
|
||||
return unmerged_file_path
|
||||
|
||||
def get_absolute_local_path(self, node):
|
||||
node_path = node['rel_path']
|
||||
node_path = self.normalize_path(node['rel_path'])
|
||||
node_name = node['name']
|
||||
local_file_path = '%s%s' % (node_path, node_name)
|
||||
local_file_path = local_file_path.replace('.%s' % (os.sep), self.local_path)
|
||||
return local_file_path
|
||||
|
||||
def get_absolute_remote_path(self, node):
|
||||
node_path = node['rel_path']
|
||||
node_path = self.normalize_path(node['rel_path'])
|
||||
node_name = node['name']
|
||||
remote_file_path = '%s%s' % (node_path, node_name)
|
||||
remote_file_path = remote_file_path.replace('.%s' % (os.sep), self.remote_path)
|
||||
@ -175,6 +175,11 @@ class Manager():
|
||||
remote_mount_point = node_path.replace('.%s' % (os.sep), self.remote_path)
|
||||
return remote_mount_point
|
||||
|
||||
def get_local_mount_point(self, node):
|
||||
node_path = node['rel_path']
|
||||
local_mount_point = node_path.replace('.%s' % (os.sep), self.local_path)
|
||||
return local_mount_point
|
||||
|
||||
def add_sync_to_list(self):
|
||||
home_dir = os.environ.get('HOME')
|
||||
home_dir = self.normalize_path(home_dir)
|
||||
@ -618,18 +623,44 @@ class Manager():
|
||||
|
||||
return dones
|
||||
|
||||
def compute_local_node_hash(self, n):
|
||||
## we must compute n['cur_hash']
|
||||
path = self.get_absolute_local_path(n)
|
||||
if n['last_type'] == 'd':
|
||||
cur_hash = _genlocal.generate_tree_hash(path)
|
||||
else:
|
||||
cur_hash = _genlocal.generate_file_hash(path)
|
||||
|
||||
return cur_hash
|
||||
|
||||
def copy_node_from_remote(self, n):
|
||||
a = self.get_agent()
|
||||
last_type = n['last_type']
|
||||
absolute_remote_path = self.get_absolute_remote_path(n)
|
||||
|
||||
if last_type == 'd':
|
||||
local_mount_point = self.get_local_mount_point(n)
|
||||
return a.get_dir(absolute_remote_path, local_mount_point)
|
||||
|
||||
absolute_local_path = self.get_absolute_local_path(n)
|
||||
return a.get_file(absolute_remote_path, absolute_local_path)
|
||||
|
||||
|
||||
def sync_from_remote(self, nodes, dry_run=False):
|
||||
if dry_run: return []
|
||||
dones = []
|
||||
for n in nodes:
|
||||
self.copy_node_from_remote(n)
|
||||
## we must compute n['cur_hash']
|
||||
cur_hash = self.compute_local_node_hash(n)
|
||||
n['cur_hash'] = cur_hash
|
||||
dones.append(n)
|
||||
|
||||
return dones
|
||||
|
||||
|
||||
def get_candidates_for_local_deletion_and_addition(self):
|
||||
## candidates_for_local_deletion -> nodes that there are on local but not in remote
|
||||
## candidates_for_local_addition -> nodes that there are NOT on local but only in remote
|
||||
# make a remote call to check the structure diff
|
||||
tree_structure_diff = self.get_tree_structure_diff_local_remote()
|
||||
|
||||
@ -725,7 +756,7 @@ class Manager():
|
||||
# local_added = self.sync_added(added=added, dry_run=dry_run)
|
||||
added_from_remote_done = self.sync_from_remote(nodes=remote_addition, dry_run=dry_run)
|
||||
|
||||
for node in added_done:
|
||||
for node in added_done + added_from_remote_done:
|
||||
local_tree = self.update_local_hash('add', node, tree=local_tree)
|
||||
|
||||
removed_done = self.sync_removed(removed=removed, dry_run=dry_run)
|
||||
@ -746,7 +777,7 @@ class Manager():
|
||||
rel_path_list = node_changed['rel_path'].split('/')
|
||||
rel_path_list = [r for r in rel_path_list if r]
|
||||
node_name = node_changed['name']
|
||||
cur_hash = node_changed['cur_hash']
|
||||
cur_hash = node_changed.get('cur_hash')
|
||||
subtree = tree
|
||||
for kpath in rel_path_list:
|
||||
if kpath == '.': continue
|
||||
|
Loading…
x
Reference in New Issue
Block a user