From d764983a2cb39d3b931c5df5da21d959d4f48d33 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Thu, 21 Feb 2013 18:05:43 -0500 Subject: [PATCH] Fix a bug when handling the archiving of old cases. --- tasks/drn_clerkbot.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tasks/drn_clerkbot.py b/tasks/drn_clerkbot.py index df93cac..6a6fe0d 100644 --- a/tasks/drn_clerkbot.py +++ b/tasks/drn_clerkbot.py @@ -427,12 +427,16 @@ class DRNClerkBot(Task): if closed_age > 60 * 60 * 24 and modify_age > 60 * 60 * 24: arch_top = self.tl_archive_top arch_bottom = self.tl_archive_bottom - reg = "()?" - if re.search(reg, case.body): - case.body = re.sub("\{\{" + arch_top + "\}\}", "", case.body) - case.body = re.sub(reg, "{{" + arch_top + "}}", case.body) - if not re.search(arch_bottom + "\s*\}\}\s*\Z", case.body): - case.body += "\n{{" + arch_bottom + "}}" + reg = r"()?" + if re.search(r"\{\{\s*" + arch_top, case.body): + if re.search(reg, case.body): + case.body = re.sub(reg, "", case.body) + else: + if re.search(reg, case.body): + case.body = re.sub(r"\{\{" + arch_top + r"\}\}", "", case.body) + case.body = re.sub(reg, "{{" + arch_top + "}}", case.body) + if not re.search(arch_bottom + r"\s*\}\}\s*\Z", case.body): + case.body += "\n{{" + arch_bottom + "}}" case.archived = True self.logger.debug(u" {0}: archived case".format(case.id))