changeset 54:86d3a8eddbd7

Unicodeify.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Jul 2016 21:15:54 +0300
parents ea62e0ed05ae
children 5b78f62b7de7
files multimerge.py
diffstat 1 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/multimerge.py	Tue Jul 05 20:55:18 2016 +0300
+++ b/multimerge.py	Tue Jul 05 21:15:54 2016 +0300
@@ -58,7 +58,7 @@
             smtpH.sendmail(cfg.email_sender, cfg.email_to, msg.as_string())
             smtpH.quit()
         except:
-            gcm_print("FATAL: Oh crap, e-mail sending failed.")
+            gcm_print(u"FATAL: Oh crap, e-mail sending failed.")
     sys.exit(1)
 
 
@@ -72,7 +72,7 @@
 
 ## Handler for SIGINT signals
 def gcm_signal_handler(signal, frame):
-    gcm_print("\nQuitting due to SIGINT / Ctrl+C!")
+    gcm_print(u"\nQuitting due to SIGINT / Ctrl+C!")
     sys.exit(0)
 
 
@@ -297,7 +297,7 @@
 
 ## Read, parse and validate configuration file
 if len(sys.argv) > 1:
-    gcm_debug("Reading configuration from '{0}'.".format(sys.argv[1]))
+    gcm_debug(u"Reading configuration from '{0}'.".format(sys.argv[1]))
     try:
         cfgparser = ConfigParser.RawConfigParser()
         cfgparser.readfp(codecs.open(sys.argv[1], "r", "UTF-8"))
@@ -355,7 +355,7 @@
 
 
 ## Fetch complete calendar list
-gcm_debug("Fetching available calendars ..")
+gcm_debug(u"Fetching available calendars ..")
 calendars = []
 cal_token = None
 while True:
@@ -410,7 +410,7 @@
 color_id = 0
 for calendar in src_calendars:
     color_id = color_id + 1
-    gcm_debug("- "+calendar["id"])
+    gcm_debug(u"- "+calendar["id"])
     result = service.events().list(
         timeZone="EEST",
         calendarId=calendar["id"],
@@ -446,10 +446,10 @@
 
 
 ## Start merging events ..
-gcm_debug("Re-merging events to target calendar ..")
 dst_gcm_ids = frozenset(map(lambda x: x["gcm_id"], dst_events))
 src_ids = frozenset(map(lambda x: x["id"], src_events))
 dst_ids = frozenset(map(lambda x: x["id"], dst_events))
+gcm_debug(u"Re-merging events to target calendar ..")
 
 for event in src_events:
     # Does the event exist already in the target?
@@ -457,6 +457,7 @@
         ## Yes. Thus, we just update the event.
         #print "IS in dst_gcm_ids: "+ event["id"] +" : "+ event["gcm_id"]
         # Check if event NEEDS updating .. aka compare data
+        gcm_debug(u"Updating event {0}".format(event["gcm_id"]))
         d_event = gcm_get_event_by_gcm_id(dst_events, event["gcm_id"])
         if d_event and gcm_compare_events(event, d_event):
             try:
@@ -464,9 +465,10 @@
             except Exception as e:
                 gcm_fatal("Failed to update event:\n{0}\n\nERROR: {1}\n".format(event, str(e)))
         else:
-            gcm_debug("No need to update event {0}.".format(event["gcm_id"]))
+            gcm_debug(u"No need to update event {0}.".format(event["gcm_id"]))
     else:
         ## Event does not seem to exist. Insert new event.
+        gcm_debug(u"Inserting new event {0}".format(event["gcm_id"]))
         event.pop("iCalUID", None)        # Remove the iCalUID, having it conflicts with event ID
         event["id"] = event["gcm_id"]     # Replace Google generated ID with our own
         try:
@@ -475,6 +477,7 @@
             gcm_fatal("Failed to insert new event:\n{0}\n\nERROR: {1}\n".format(event, str(e)))
 
 ## Remove "stale" events
+gcm_debug(u"Purging stale events ..")
 for event in dst_events:
     if not event["id"] in src_ids:
         try:
@@ -483,4 +486,4 @@
             gcm_fatal("Failed to delete stale event:\n{0}\n\nERROR: {1}\n".format(event, str(e)))
 
 
-gcm_debug("Finished.")
+gcm_debug(u"Finished.")