From e2dcc9d50b83d3f63c68975a7fbcb5f533dc92b1 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Fri, 27 Jul 2012 23:33:25 -0400 Subject: [PATCH] Add status parsing, plus start schema for the SQL table. --- earwigbot/tasks/drn_clerkbot.py | 64 ++++++++++++++++++++++++++++++++- earwigbot/tasks/schema/drn_clerkbot.sql | 22 ++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 earwigbot/tasks/schema/drn_clerkbot.sql diff --git a/earwigbot/tasks/drn_clerkbot.py b/earwigbot/tasks/drn_clerkbot.py index 871016f..453fee7 100644 --- a/earwigbot/tasks/drn_clerkbot.py +++ b/earwigbot/tasks/drn_clerkbot.py @@ -20,6 +20,9 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +from os import expanduser +import re + import oursql from earwigbot.tasks import Task @@ -29,6 +32,17 @@ class DRNClerkBot(Task): name = "drn_clerkbot" number = 19 + # Case status: + STATUS_UNKNOWN = 0 + STATUS_NEW = 1 + STATUS_OPEN = 2 + STATUS_STALE = 3 + STATUS_NEEDASSIST = 4 + STATUS_REVIEW = 5 + STATUS_RESOLVED = 6 + STATUS_CLOSED = 7 + STATUS_ARCHIVE = 8 + def setup(self): """Hook called immediately after the task is loaded.""" cfg = self.config.tasks.get(self.name, {}) @@ -51,4 +65,52 @@ class DRNClerkBot(Task): def run(self, **kwargs): """Entry point for a task event.""" - page = self.bot.wiki.get_site().get_page(self.title) + with self.db_access_lock: + page = self.bot.wiki.get_site().get_page(self.title) + text = page.get() + current = read_page(text) + + def read_page(self, text): + split = re.split("(^==\s*[^=]+?\s*==$)", text, flags=re.M|re.U) + cases = [] + case = None + for item in split: + if item.startswith("=="): + if case: + cases.append(case) + case = _Case() + case.title = item[2:-2].strip() + else: + templ = re.escape(self.tl_status) + if case and re.match("\s*\{\{" + templ, item, re.U): + case.body = case.old_body = item + case.status = self.read_status(body) + if case: + cases.append(case) + return cases + + def read_status(self, body): + aliases = { + self.STATUS_NEW: ("",), + self.STATUS_OPEN: ("open", "active", "inprogress"), + self.STATUS_STALE: ("stale",), + self.STATUS_NEEDASSIST: ("needassist", "relist", "relisted"), + self.STATUS_REVIEW: ("review",), + self.STATUS_RESOLVED: ("resolved", "resolve"), + self.STATUS_CLOSED: ("closed", "close"), + } + templ = re.escape(self.tl_status) + status = re.search("\{\{" + templ + "\|?(.*?)\}\}", body, re.S|re.U) + if not status: + return self.STATUS_UNKNOWN + for option, names in aliases.iteritems(): + if status.group(1).lower() in names: + return option + return self.STATUS_UNKNOWN + + +class _Case(object): + def __init__(self): + self.title = None + self.body = None + self.status = None diff --git a/earwigbot/tasks/schema/drn_clerkbot.sql b/earwigbot/tasks/schema/drn_clerkbot.sql new file mode 100644 index 0000000..ab6d06e --- /dev/null +++ b/earwigbot/tasks/schema/drn_clerkbot.sql @@ -0,0 +1,22 @@ +-- MySQL dump 10.13 Distrib 5.5.12, for solaris10 (i386) +-- +-- Host: sql Database: u_earwig_drn_clerkbot +-- ------------------------------------------------------ +-- Server version 5.1.59 + +CREATE DATABASE `u_earwig_drn_clerkbot` + DEFAULT CHARACTER SET utf8 + DEFAULT COLLATE utf8_unicode_ci; + +-- +-- Table structure for table `case` +-- + +DROP TABLE IF EXISTS `case`; +CREATE TABLE `case` ( + `case_id` int(10) unsigned NOT NULL, + `case_name` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`case_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- Dump completed on 2012-07-27 00:00:00