Browse Source

Bugfixes, pyflakes compliance etc

tags/v0.1^2
Ben Kurtovic 12 years ago
parent
commit
f84747800c
4 changed files with 37 additions and 30 deletions
  1. +4
    -1
      earwigbot/bot.py
  2. +0
    -2
      earwigbot/commands/afc_report.py
  3. +11
    -13
      earwigbot/irc/rc.py
  4. +22
    -14
      earwigbot/tasks/afc_statistics.py

+ 4
- 1
earwigbot/bot.py View File

@@ -24,6 +24,7 @@ import logging
from threading import Lock, Thread, enumerate as enumerate_threads
from time import sleep, time

from earwigbot import __version__
from earwigbot.config import BotConfig
from earwigbot.irc import Frontend, Watcher
from earwigbot.managers import CommandManager, TaskManager
@@ -136,16 +137,18 @@ class Bot(object):
ensuring that all components remain online and restarting components
that get disconnected from their servers.
"""
self.logger.info("Starting bot")
self.logger.info("Starting bot (EarwigBot {0})".format(__version__))
self._start_irc_components()
self._start_wiki_scheduler()
while self._keep_looping:
with self.component_lock:
if self.frontend and self.frontend.is_stopped():
name = "irc_frontend"
self.logger.warn("IRC frontend has stopped; restarting")
self.frontend = Frontend(self)
Thread(name=name, target=self.frontend.loop).start()
if self.watcher and self.watcher.is_stopped():
name = "irc_watcher"
self.logger.warn("IRC watcher has stopped; restarting")
self.watcher = Watcher(self)
Thread(name=name, target=self.watcher.loop).start()


+ 0
- 2
earwigbot/commands/afc_report.py View File

@@ -20,8 +20,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import re

from earwigbot import wiki
from earwigbot.commands import BaseCommand



+ 11
- 13
earwigbot/irc/rc.py View File

@@ -25,11 +25,14 @@ import re
__all__ = ["RC"]

class RC(object):
"""A class to store data on an event received from our IRC watcher."""
"""A class to store data from an event received from our IRC watcher."""
re_color = re.compile("\x03([0-9]{1,2}(,[0-9]{1,2})?)?")
re_edit = re.compile("\A\[\[(.*?)\]\]\s(.*?)\s(http://.*?)\s\*\s(.*?)\s\*\s(.*?)\Z")
re_log = re.compile("\A\[\[(.*?)\]\]\s(.*?)\s\*\s(.*?)\s\*\s(.*?)\Z")

pretty_edit = "\x02New {0}\x0F: \x0314[[\x0307{1}\x0314]]\x0306 * \x0303{2}\x0306 * \x0302{3}\x0306 * \x0310{4}"
pretty_log = "\x02New {0}\x0F: \x0303{1}\x0306 * \x0302{2}\x0306 * \x0310{3}"

def __init__(self, msg):
self.msg = msg

@@ -77,19 +80,14 @@ class RC(object):
event_type = "edit" # "New edit:"
if "B" in flags:
# "New bot edit:"
event_type = "bot {}".format(event_type)
event_type = "bot " + event_type
if "M" in flags:
# "New minor edit:" OR "New minor bot edit:"
event_type = "minor {}".format(event_type)
event_type = "minor " + event_type

# Example formatting:
# New edit: [[Page title]] * User name * http://en... * edit summary
if self.is_edit:
return "".join(("\x02New ", event_type, "\x0F: \x0314[[\x0307",
self.page, "\x0314]]\x0306 *\x0303 ", self.user,
"\x0306 *\x0302 ", self.url, "\x0306 *\x0310 ",
self.comment))

return "".join(("\x02New ", event_type, "\x0F: \x0303", self.user,
"\x0306 *\x0302 ", self.url, "\x0306 *\x0310 ",
self.comment))
return self.pretty_edit.format(event_type, self.page, self.user,
self.url, self.comment)
else:
return self.pretty_log.format(event_type, self.user, self.url,
self.comment)

+ 22
- 14
earwigbot/tasks/afc_statistics.py View File

@@ -1,17 +1,17 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2009-2012 by Ben Kurtovic <ben.kurtovic@verizon.net>
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -21,7 +21,6 @@
# SOFTWARE.

from datetime import datetime
import logging
import re
from os.path import expanduser
from threading import Lock
@@ -34,6 +33,7 @@ from earwigbot.tasks import BaseTask

__all__ = ["Task"]


class Task(BaseTask):
"""A task to generate statistics for WikiProject Articles for Creation.

@@ -386,18 +386,25 @@ class Task(BaseTask):

size = self.get_size(content)
m_user, m_time, m_id = self.get_modify(pageid)
notes = self.get_notes(chart, content, m_time,
result["page_special_user"].decode("utf8"))

if title != result["page_title"].decode("utf8"):
self.update_page_title(cursor, result, pageid, title)

if m_id != result["page_modify_oldid"]:
self.update_page_modify(cursor, result, pageid, size, m_user, m_time, m_id)
self.update_page_modify(cursor, result, pageid, size, m_user,
m_time, m_id)

if status != result["page_status"]:
self.update_page_status(cursor, result, pageid, status, chart)
special = self.update_page_status(cursor, result, pageid, status,
chart)
s_user = special[0]
else:
try:
s_user = result["page_special_user"].decode("utf8")
except AttributeError: # Happens if page_special_user is None
s_user = result["page_special_user"]

notes = self.get_notes(chart, content, m_time, s_user)
if notes != result["page_notes"]:
self.update_page_notes(cursor, result, pageid, notes)

@@ -438,7 +445,6 @@ class Task(BaseTask):
result["row_chart"], status, chart))

s_user, s_time, s_id = self.get_special(pageid, chart)

if s_id != result["page_special_oldid"]:
cursor.execute(query2, (s_user, s_time, s_id, pageid))
msg = u"{0}: special: {1} / {2} / {3} -> {4} / {5} / {6}"
@@ -448,6 +454,8 @@ class Task(BaseTask):
result["page_special_oldid"], s_user, s_time, s_id)
self.logger.debug(msg)

return s_user, s_time, s_id

def update_page_notes(self, cursor, result, pageid, notes):
"""Update the notes (or warnings) of a page in our database."""
query = "UPDATE page SET page_notes = ? WHERE page_id = ?"
@@ -491,7 +499,7 @@ class Task(BaseTask):
except KeyError:
if tries > 0:
sleep(5)
return self.get_revision_content(revid, tries=tries-1)
return self.get_revision_content(revid, tries=tries - 1)

def get_status_and_chart(self, content, namespace):
"""Determine the status and chart number of an AFC submission.
@@ -705,8 +713,8 @@ class Task(BaseTask):
if len(content) < 500:
notes += "|ns=1" # Submission is short

if not re.search("\<ref\s*(.*?)\>(.*?)\</ref\>", content, re.I|re.S):
if re.search("https?:\/\/(.*?)\.", content, re.I|re.S):
if not re.search("\<ref\s*(.*?)\>(.*?)\</ref\>", content, re.I | re.S):
if re.search("https?:\/\/(.*?)\.", content, re.I | re.S):
notes += "|ni=1" # Submission has no inline citations
else:
notes += "|nu=1" # Submission is completely unsourced
@@ -716,7 +724,7 @@ class Task(BaseTask):
if time_since_modify > max_time:
notes += "|no=1" # Submission hasn't been touched in over 4 days

if chart in [self.CHART_PEND, self.CHART_DRAFT]:
if chart in [self.CHART_PEND, self.CHART_DRAFT] and s_user:
submitter = self.site.get_user(s_user)
try:
if submitter.blockinfo():


Loading…
Cancel
Save