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:
Markus Unterwaditzer 2014-04-15 19:38:30 +02:00
parent 2ea7799288
commit 0684f784ea

View file

@ -77,7 +77,7 @@ def sync(storage_a, storage_b, status, conflict_resolution=None):
'b': (storage_b, list_b, b_uid_to_href) 'b': (storage_b, list_b, b_uid_to_href)
} }
actions = get_actions(storages, status) actions = list(get_actions(storages, status))
for action in actions: for action in actions:
action(storages, status, conflict_resolution) action(storages, status, conflict_resolution)
@ -172,8 +172,6 @@ def action_conflict_resolve(uid):
def get_actions(storages, status): def get_actions(storages, status):
actions = []
storage_a, list_a, a_uid_to_href = storages['a'] storage_a, list_a, a_uid_to_href = storages['a']
storage_b, list_b, b_uid_to_href = storages['b'] 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) b = list_b.get(href_b, None)
if uid not in status: if uid not in status:
if a and b: # missing 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 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 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: else:
_, status_etag_a, _, status_etag_b = status[uid] _, status_etag_a, _, status_etag_b = status[uid]
if a and b: if a and b:
if a['etag'] != status_etag_a and b['etag'] != status_etag_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 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 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 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 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 elif not a and not b: # was deleted from a and b
actions.append(action_delete(uid, None)) yield action_delete(uid, None)
return actions