comparison multimerge.py @ 111:8b773358ad47 rel-0.9

Use "id" field in source calendar events gcm_id generation, and "iCalUID" for the target calendar.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 18 Oct 2016 12:30:19 +0300
parents c6771a596d77
children f45115bfb17a
comparison
equal deleted inserted replaced
110:c6771a596d77 111:8b773358ad47
131 status = "*" if event["status"] != u"cancelled" else "!" 131 status = "*" if event["status"] != u"cancelled" else "!"
132 gcm_print(u"[{0}] {1:25} - {2:25} : {3} [{4}] [{5}]".format(status, ev_start, ev_end, summary, event["iCalUID"], event["id"])) 132 gcm_print(u"[{0}] {1:25} - {2:25} : {3} [{4}] [{5}]".format(status, ev_start, ev_end, summary, event["iCalUID"], event["id"]))
133 133
134 134
135 ## Generate gcm IDs for given list of events 135 ## Generate gcm IDs for given list of events
136 def gcm_generate_ids(events, calendar_id, sep): 136 def gcm_generate_ids(events, calendar_id, sep, field):
137 if not events: 137 if not events:
138 return events 138 return events
139 139
140 for ev in events: 140 for event in events:
141 ev["gcm_cal_id"] = calendar_id 141 event["gcm_cal_id"] = calendar_id
142 ev["gcm_id"] = calendar_id + sep + ev["iCalUID"] 142 event["gcm_id"] = calendar_id + sep + event[field]
143 143
144 return events 144 return events
145 145
146 146
147 ## Find event by its gcm_id from given list or return None if not found 147 ## Find event by its gcm_id from given list or return None if not found
558 gcm_debug(4, u" Found nearest event color ID: {0}, {1}".format(c_found, colors["event"][c_found])) 558 gcm_debug(4, u" Found nearest event color ID: {0}, {1}".format(c_found, colors["event"][c_found]))
559 else: 559 else:
560 gcm_debug(4, u" No matching event color found!") 560 gcm_debug(4, u" No matching event color found!")
561 561
562 # Add events, if any, to main list 562 # Add events, if any, to main list
563 events = gcm_generate_ids(gcm_fetch_events(calendar["id"], False), calendar["id"], "___") 563 events = gcm_generate_ids(gcm_fetch_events(calendar["id"], False), calendar["id"], "___", "id")
564 if events: 564 if events:
565 for event in events: 565 for event in events:
566 if event["status"] != u"cancelled": 566 if event["status"] != u"cancelled":
567 if c_found != None: 567 if c_found != None:
568 event["colorId"] = c_found 568 event["colorId"] = c_found
572 gcm_dump_events(events, (lambda ev: ev["status"] != u"cancelled")) 572 gcm_dump_events(events, (lambda ev: ev["status"] != u"cancelled"))
573 573
574 574
575 ## Get current events 575 ## Get current events
576 gcm_debug(3, u"Fetching current target calendar events.") 576 gcm_debug(3, u"Fetching current target calendar events.")
577 dst_events = gcm_generate_ids(gcm_fetch_events(cfg.dst_id, True), "", "") 577 dst_events = gcm_generate_ids(gcm_fetch_events(cfg.dst_id, True), "", "", "iCalUID")
578 gcm_debug(3, u"Found {0} event(s).".format(len(dst_events))) 578 gcm_debug(3, u"Found {0} event(s).".format(len(dst_events)))
579 579
580 580
581 ## Start merging events .. 581 ## Start merging events ..
582 gcm_debug(3, u"Re-merging events to target calendar ..") 582 gcm_debug(3, u"Re-merging events to target calendar ..")