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