From d8b1bee98aa4251476a7b1db29265e1b515c7b8c Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Wed, 1 Aug 2012 03:49:31 -0400 Subject: [PATCH] Support purging old cases, proper handling of STATUS_UNKNOWN. --- earwigbot/tasks/drn_clerkbot.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/earwigbot/tasks/drn_clerkbot.py b/earwigbot/tasks/drn_clerkbot.py index 2426524..b0361ac 100644 --- a/earwigbot/tasks/drn_clerkbot.py +++ b/earwigbot/tasks/drn_clerkbot.py @@ -126,6 +126,8 @@ class DRNClerkBot(Task): if self.shutoff_enabled(): return self.update_chart(conn, site) + if action in ["all", "purge"]: + self.purge_old_data(conn) finally: self.db_access_lock.release() @@ -203,7 +205,8 @@ class DRNClerkBot(Task): re_id2 += r"(.*?)\}\})()?" repl = ur"\1 " body = re.sub(re_id2, repl.format(id_), body) - re_f = r"\{\{drn filing editor\|(.*?)\|(\d{2}:\d{2},\s\d{1,2}\s\w+\s\d{4}\s\(UTC\))\}\}" + re_f = r"\{\{drn filing editor\|(.*?)\|" + re_f += r"(\d{2}:\d{2},\s\d{1,2}\s\w+\s\d{4}\s\(UTC\))\}\}" match = re.search(re_f, body, re.U) if match: f_user = match.group(1).split("/", 1)[0].replace("_", " ") @@ -246,7 +249,7 @@ class DRNClerkBot(Task): for option, names in self.ALIASES.iteritems(): if status.group(1).lower() in names: return option - return self.STATUS_UNKNOWN + return self.STATUS_NEW def update_case_title(self, conn, id_, title): """Update a case title in the database.""" @@ -262,7 +265,9 @@ class DRNClerkBot(Task): volunteers = [name for (name,) in cursor.fetchall()] notices = [] for case in cases: - if case.status != self.STATUS_UNKNOWN: + if case.status == self.STATUS_UNKNOWN: + self.clerk_unknown_case(conn, case) + else: notices += self.clerk_case(conn, case, volunteers) return notices @@ -358,6 +363,12 @@ class DRNClerkBot(Task): case.body += "\n{{" + arch_bottom + "}}" case.status = self.STATUS_UNKNOWN + def clerk_unknown_case(self, conn, case): + if case.new: + self.save_new_case(conn, case) + else: + self.save_existing_case(conn, case) + def check_for_review(self, case): age = (datetime.utcnow() - case.file_time).total_seconds() if age > 60 * 60 * 24 * 4: @@ -606,6 +617,16 @@ class DRNClerkBot(Task): msg.append(chunk) return ", ".join(msg) + " ago" if msg else "0 hours ago" + def purge_old_data(self, conn): + query = """DELETE cases, signatures + FROM cases JOIN signatures ON case_id = signature_case + WHERE case_status = ? + AND case_file_time < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 30 DAY) + AND case_modify_time < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 30 DAY) + """ + with conn.cursor() as cursor: + cursor.execute(query, (self.STATUS_UNKNOWN,)) + class _Case(object): """A object representing a dispute resolution case."""