# HG changeset patch # User Matti Hamalainen # Date 1467626141 -10800 # Node ID 01c933dba12063eafd6b138a97086bbcb7e397eb # Parent 8367463fe94db8cdc606f481b482d2bb36974087 Filter source calendars based on regexp. diff -r 8367463fe94d -r 01c933dba120 README.txt diff -r 8367463fe94d -r 01c933dba120 multimerge.py --- 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 +"'.") + +