changeset 134:afdef805e9b7

Merge Python 3 branch.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 15 Sep 2020 23:39:49 +0300
parents 3a3958edc813 (diff) 84ff2570b1fc (current diff)
children aa3478847735
files README.txt multimerge.py
diffstat 4 files changed, 29 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Tue Sep 15 23:39:49 2020 +0300
@@ -0,0 +1,6 @@
+syntax: glob
+ChangeLog
+*~
+*.orig
+*.diff
+.git/
--- a/COPYING	Mon Nov 07 09:21:29 2016 +0200
+++ b/COPYING	Tue Sep 15 23:39:49 2020 +0300
@@ -1,7 +1,7 @@
 Google Calendar MultiMerge
 ==========================
 Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
-(C) Copyright 2016 Tecnic Software productions (TNSP)
+(C) Copyright 2016-2017 Tecnic Software productions (TNSP)
 
 
 Redistribution and use in source and binary forms, with or without
--- a/README.txt	Mon Nov 07 09:21:29 2016 +0200
+++ b/README.txt	Tue Sep 15 23:39:49 2020 +0300
@@ -1,7 +1,7 @@
 Google Calendar MultiMerge
 ==========================
 Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
-(C) Copyright 2016 Tecnic Software productions (TNSP)
+(C) Copyright 2016-2017 Tecnic Software productions (TNSP)
 
 For license information, see file "COPYING".
 
--- a/multimerge.py	Mon Nov 07 09:21:29 2016 +0200
+++ b/multimerge.py	Tue Sep 15 23:39:49 2020 +0300
@@ -3,11 +3,11 @@
 ###
 ### Google Calendar MultiMerge
 ### Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
-### (C) Copyright 2016 Tecnic Software productions (TNSP)
+### (C) Copyright 2016-2020 Tecnic Software productions (TNSP)
 ###
 ### For license information, see file "COPYING".
 ###
-### Python 2.7 <= x < 3 required! Please refer to
+### Python 3.7 required! Please refer to
 ### README.txt for information on other depencies.
 ###
 import os
@@ -32,6 +32,9 @@
 from googleapiclient import discovery
 
 
+assert sys.version_info >= (3, 7)
+
+
 ###
 ### Misc. helper functions, etc
 ###
@@ -40,6 +43,7 @@
 gcm_no_compare_fields = [
     "id", "iCalUID", "etag", "sequence", "gcm_cal_id",
     "created", "updated", "htmlLink", "organizer", "creator",
+    "extendedProperties",
 ]
 
 ## List of logging levels from lowest to highest
@@ -50,12 +54,18 @@
     return gcm_log_levels.index(cfg.logging_level)
 
 
+## Return a formatted timestamp string
+def gcm_timestamp(stamp):
+    return time.strftime("%Y-%m-%d %H:%M:%S", stamp)
+    #.decode(locale.getlocale()[1])
+
+
 ## Wrapper for print() that does not break when redirecting stdin/out
 ## because of piped output not having a defined encoding. We default
 ## to UTF-8 encoding in output here.
 def gcm_print(smsg):
     gcm_msgbuf.append(smsg)
-    print(smsg)
+    print("{0} | {1}".format(gcm_timestamp(time.localtime()), smsg))
 
 
 ## Fatal error handler
@@ -72,6 +82,7 @@
         try:
             # Act based on email mode
             if cfg.email == "smtp":
+                # Connect via SMTP
                 gcm_print("Using SMTP server {0}, login {1}".format(cfg.email_smtp_server, cfg.email_smtp_user))
                 server = smtplib.SMTP(cfg.email_smtp_server)
                 if gcm_check_debug(4):
@@ -84,6 +95,7 @@
                 server.sendmail(cfg.email_sender, cfg.email_to, msg.as_string())
                 server.quit()
             elif cfg.email == "sendmail":
+                # Use local sendmail
                 gcm_print("Using sendmail {0}".format(cfg.email_sendmail))
                 p = Popen([cfg.email_sendmail, "-t", "-oi"], stdin=PIPE)
                 p.communicate(msg.as_string())
@@ -481,7 +493,7 @@
 if len(cfg.src_regmap) != cfg.src_regmap_len:
     gcm_fatal(u"Setting src_regmap list must be {0} items.".format(cfg.src_regmap_len))
 else:
-    # Force to integers
+    # Force convert values to integers
     try:
         cfg.src_regmap = [int(x) for x in cfg.src_regmap]
     except Exception as e:
@@ -590,7 +602,10 @@
             if event["status"] != u"cancelled":
                 if c_found != None:
                     event["colorId"] = c_found
-                event["summary"] = u"[{1}] {0}".format(event["summary"], calendar["gcm_id"])
+                if "summary" in event:
+                    event["summary"] = u"[{1}] {0}".format(event["summary"], calendar["gcm_id"])
+                else:
+                    event["summary"] = u"[?] {0}".format(calendar["gcm_id"])
 
         # Add to list of source events
         src_events.extend(events)
@@ -632,7 +647,7 @@
         else:
             evn_unchanged += 1
             gcm_debug(4, u"No need to update event {0} [{1}]".format(event["id"], event["gcm_id"]))
-    elif event["status"] != u"cancelled":
+    elif event["status"] not in [u"cancelled", u"confirmed"]:
         # Event does not seem to exist. Insert new event.
         gcm_debug(4, u"Inserting new event {0} [{1}]".format(event["id"], event["gcm_id"]))
         # Remove original id field, otherwise it will clash