changeset 9:01c933dba120

Filter source calendars based on regexp.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 04 Jul 2016 12:55:41 +0300
parents 8367463fe94d
children b237b96602ad
files README.txt multimerge.py
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/multimerge.py	Mon Jul 04 12:54:53 2016 +0300
+++ b/multimerge.py	Mon Jul 04 12:55:41 2016 +0300
@@ -260,6 +260,16 @@
 
 
 ## Validate settings
+if len(cfg.source_regmap) != cfg.source_regmap_len:
+    gcm_fatal("Setting source_regmap list must be {0} items.".format(cfg.source_regmap_len))
+else:
+    # Force to integers
+    try:
+        cfg.source_regmap = map(lambda x: int(x), cfg.source_regmap)
+    except Exception as e:
+        gcm_fatal("Invalid source_regmap: {0}".format(str(e)))
+
+
 if not cfg.dest_name and not cfg.dest_id:
     gcm_fatal("Target calendar ID or name required, but not set.")
 
@@ -295,3 +305,23 @@
     gcm_fatal("No calendars found?")
 
 
+## Filter desired SOURCE calendars based on specified regexp
+src_re = re.compile(cfg.source_regex)
+src_calendars = []
+for calendar in calendars:
+    if "summary" in calendar:
+        if not cfg.dest_id and cfg.dest_name == calendar["summary"].strip():
+            cfg.mset("dest_id", calendar["id"])
+
+        mre = src_re.match(calendar["summary"])
+        if mre:
+            calendar["gcm_title"] = mre.group(cfg.source_regmap[0])
+            calendar["gcm_id"] = mre.group(cfg.source_regmap[1])
+            src_calendars.append(calendar)
+
+
+## Check if we have target ID
+if not cfg.dest_id:
+    gcm_fatal(u"Could not find target/destination calendar ID for '"+ cfg.dest_name +"'.")
+
+