mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-26 09:05:50 +00:00
Use yield instead of a list.
I don't want to rewrite the sync function to be one monolithic thing, although it now would be more sensible than it was ever before. The reason for this is that i want vdirsyncer to precompute all necessary actions before it actually does anything, which probably helps in the future with a dry-run mode.
This commit is contained in:
parent
2ea7799288
commit
0684f784ea
1 changed files with 10 additions and 14 deletions
|
|
@ -77,7 +77,7 @@ def sync(storage_a, storage_b, status, conflict_resolution=None):
|
|||
'b': (storage_b, list_b, b_uid_to_href)
|
||||
}
|
||||
|
||||
actions = get_actions(storages, status)
|
||||
actions = list(get_actions(storages, status))
|
||||
|
||||
for action in actions:
|
||||
action(storages, status, conflict_resolution)
|
||||
|
|
@ -172,8 +172,6 @@ def action_conflict_resolve(uid):
|
|||
|
||||
|
||||
def get_actions(storages, status):
|
||||
actions = []
|
||||
|
||||
storage_a, list_a, a_uid_to_href = storages['a']
|
||||
storage_b, list_b, b_uid_to_href = storages['b']
|
||||
|
||||
|
|
@ -191,25 +189,23 @@ def get_actions(storages, status):
|
|||
b = list_b.get(href_b, None)
|
||||
if uid not in status:
|
||||
if a and b: # missing status
|
||||
actions.append(action_conflict_resolve(uid))
|
||||
yield action_conflict_resolve(uid)
|
||||
elif a and not b: # new item was created in a
|
||||
actions.append(action_upload(uid, 'a', 'b'))
|
||||
yield action_upload(uid, 'a', 'b')
|
||||
elif not a and b: # new item was created in b
|
||||
actions.append(action_upload(uid, 'b', 'a'))
|
||||
yield action_upload(uid, 'b', 'a')
|
||||
else:
|
||||
_, status_etag_a, _, status_etag_b = status[uid]
|
||||
if a and b:
|
||||
if a['etag'] != status_etag_a and b['etag'] != status_etag_b:
|
||||
actions.append(action_conflict_resolve(uid))
|
||||
yield action_conflict_resolve(uid)
|
||||
elif a['etag'] != status_etag_a: # item was updated in a
|
||||
actions.append(action_update(uid, 'a', 'b'))
|
||||
yield action_update(uid, 'a', 'b')
|
||||
elif b['etag'] != status_etag_b: # item was updated in b
|
||||
actions.append(action_update(uid, 'b', 'a'))
|
||||
yield action_update(uid, 'b', 'a')
|
||||
elif a and not b: # was deleted from b
|
||||
actions.append(action_delete(uid, 'a'))
|
||||
yield action_delete(uid, 'a')
|
||||
elif not a and b: # was deleted from a
|
||||
actions.append(action_delete(uid, 'b'))
|
||||
yield action_delete(uid, 'b')
|
||||
elif not a and not b: # was deleted from a and b
|
||||
actions.append(action_delete(uid, None))
|
||||
|
||||
return actions
|
||||
yield action_delete(uid, None)
|
||||
|
|
|
|||
Loading…
Reference in a new issue