Ver código fonte

Add status parsing, plus start schema for the SQL table.

tags/v0.1^2
Ben Kurtovic 12 anos atrás
pai
commit
e2dcc9d50b
2 arquivos alterados com 85 adições e 1 exclusões
  1. +63
    -1
      earwigbot/tasks/drn_clerkbot.py
  2. +22
    -0
      earwigbot/tasks/schema/drn_clerkbot.sql

+ 63
- 1
earwigbot/tasks/drn_clerkbot.py Ver arquivo

@@ -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

+ 22
- 0
earwigbot/tasks/schema/drn_clerkbot.sql Ver arquivo

@@ -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

Carregando…
Cancelar
Salvar