jenkins-bot merged this change.

View Change

Approvals: Dvorapa: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified
scripts/revertbot.py: Remove RevertBot class

`RevertBot` has been intented as a sample code. Using it as the main bot
class does not work as expected (T194909). Move `RevertBot` to module's
docstring. Use `BaseRevertBot` instead of `RevertBot`.

Bug: T194909
Change-Id: Ie094c2c524ae2aaf1390aa63ef207f067d3a0f7c
---
M scripts/revertbot.py
1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/scripts/revertbot.py b/scripts/revertbot.py
index 89d8d4b..db32d74 100755
--- a/scripts/revertbot.py
+++ b/scripts/revertbot.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-"""
+r"""
This script can be used for reverting certain edits.

The following command line parameters are supported:
@@ -9,10 +9,34 @@

-rollback Rollback edits instead of reverting them.
Note that in rollback, no diff would be shown.
+
+Users who want to customize the behaviour should subclass the `BaseRevertBot`
+and override its `callback` method. Here is a sample:
+
+.. code-block::
+
+ class myRevertBot(BaseRevertBot):
+
+ '''Example revert bot.'''
+
+ def callback(self, item):
+ '''Sample callback function for 'private' revert bot.
+
+ @param item: an item from user contributions
+ @type item: dict
+ @rtype: bool
+ '''
+ if 'top' in item:
+ page = pywikibot.Page(self.site, item['title'])
+ text = page.get(get_redirect=True)
+ pattern = re.compile(r'\[\[.+?:.+?\..+?\]\]', re.UNICODE)
+ return bool(pattern.search(text))
+ return False
+
"""
#
# (C) Bryan Tong Minh, 2008
-# (C) Pywikibot team, 2008-2017
+# (C) Pywikibot team, 2008-2018
#
# Ported by Geoffrey "GEOFBOT" Mon - User:Sn1per
# for Google Code-In 2013
@@ -20,8 +44,6 @@
# Distributed under the terms of the MIT license.
#
from __future__ import absolute_import, unicode_literals
-
-import re

import pywikibot
from pywikibot import i18n
@@ -33,7 +55,6 @@
"""Base revert bot.

Subclass this bot and override callback to get it to do something useful.
-
"""

def __init__(self, site, user=None, comment=None, rollback=False):
@@ -114,27 +135,7 @@
pywikibot.output(msg)


-class RevertBot(BaseRevertBot):
-
- """Example revert bot."""
-
- def callback(self, item):
- """Callback function for 'private' revert bot.
-
- @param item: an item from user contributions
- @type item: dict
- @rtype: bool
-
- """
- if 'top' in item:
- page = pywikibot.Page(self.site, item['title'])
- text = page.get(get_redirect=True)
- pattern = re.compile(r'\[\[.+?:.+?\..+?\]\]', re.UNICODE)
- return bool(pattern.search(text))
- return False
-
-
-myRevertBot = RevertBot # for compatibility only
+myRevertBot = BaseRevertBot # for compatibility only


def main(*args):

To view, visit change 433701. To unsubscribe, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie094c2c524ae2aaf1390aa63ef207f067d3a0f7c
Gerrit-Change-Number: 433701
Gerrit-PatchSet: 5
Gerrit-Owner: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444@gmail.com>
Gerrit-Reviewer: jenkins-bot <>