jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/436028 )
Change subject: cosmetic_changes.py: Do not convert text to byte string
......................................................................
cosmetic_changes.py: Do not convert text to byte string
This may cause UnicodeEncodeError on Python 2. See
https://lists.wikimedia.org/pipermail/pywikibot/2018-May/009829.html.
Change-Id: I50bde45c7288b3e400bfd2d5c333206811527de6
---
M pywikibot/cosmetic_changes.py
1 file changed, 2 insertions(+), 1 deletion(-)
Approvals:
Dvorapa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index 3975096..a01d7f2 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -659,7 +659,8 @@
for template in skip_templates[self.site.code]:
skip_regexes.append(
re.compile(r'\{\{\s*%s\s*\}\}' % template, re.I))
- stripped_text = str(text)
+
+ stripped_text = text
for reg in skip_regexes:
stripped_text = reg.sub(r'', stripped_text)
--
To view, visit https://gerrit.wikimedia.org/r/436028
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I50bde45c7288b3e400bfd2d5c333206811527de6
Gerrit-Change-Number: 436028
Gerrit-PatchSet: 2
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/434997 )
Change subject: [IMPR] Move main categories to top in cc
......................................................................
[IMPR] Move main categories to top in cc
+ re-enable Personendaten on dewiki
+ fix nnwiki interwiki comments (there is a comment, but no code, weird)
+ minor improvements to standardizePageFooter
Bug: T76298
Change-Id: Ie9457953701f98e8c952f289b5a5d91934f2a99b
---
M pywikibot/cosmetic_changes.py
M pywikibot/textlib.py
M tests/cosmetic_changes_tests.py
3 files changed, 81 insertions(+), 36 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index 7752809..6194ae2 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -328,26 +328,22 @@
"""
Standardize page footer.
- Makes sure that interwiki links and categories are put to the correct
- position and into the right order. This combines the old instances
- standardizeInterwiki and standardizeCategories.
- The page footer has the following section in that sequence:
+ Makes sure that interwiki links and categories are put
+ into the correct position and into the right order. This
+ combines the old instances of standardizeInterwiki
+ and standardizeCategories.
+
+ The page footer consists of the following parts
+ in that sequence:
1. categories
- 2. ## TODO: template beyond categories ##
- 3. additional information depending on local site policy
- 4. interwiki links
-
+ 2. additional information depending on the local site policy
+ 3. interwiki
"""
- categories = None
- interwikiLinks = None
+ categories = []
+ interwiki_links = []
- # Pywikibot is no longer allowed to touch categories on the
- # German Wikipedia. See
- # https://de.wikipedia.org/wiki/Hilfe_Diskussion:Personendaten/Archiv/1#Posit…
- # ignoring nn-wiki of cause of the comment line above iw section
- if not self.template and '{{Personendaten' not in text and \
- '{{SORTIERUNG' not in text and '{{DEFAULTSORT' not in text and \
- self.site.code not in ('et', 'it', 'bg', 'ru'):
+ # get categories
+ if not self.template:
categories = textlib.getCategoryLinks(text, site=self.site)
if not self.talkpage:
@@ -360,26 +356,34 @@
loc = None
if loc is not None and loc in self.title:
subpage = True
- interwikiLinks = textlib.getLanguageLinks(
+
+ # get interwiki
+ interwiki_links = textlib.getLanguageLinks(
text, insite=self.site, template_subpage=subpage)
- # Removing the interwiki
+ # remove interwiki
text = textlib.removeLanguageLinks(text, site=self.site)
- # Adding categories
+ # add categories, main to top
if categories:
- # TODO: Sorting categories in alphabetic order.
- # e.g. using categories.sort()
-
- # TODO: Taking main cats to top
+ # TODO: Sort categories in alphabetic order, e.g. using
+ # categories.sort()? (T100265)
+ # TODO: Get main categories from Wikidata?
+ main = pywikibot.Category(self.site, 'Category:' + self.title,
+ sortKey=' ')
+ if main in categories:
+ categories.pop(categories.index(main))
+ categories.insert(0, main)
text = textlib.replaceCategoryLinks(text, categories,
site=self.site)
- # Adding the interwiki
- if interwikiLinks:
- text = textlib.replaceLanguageLinks(text, interwikiLinks,
+
+ # add interwiki
+ if interwiki_links:
+ text = textlib.replaceLanguageLinks(text, interwiki_links,
site=self.site,
template=self.template,
template_subpage=subpage)
+
return text
def translateAndCapitalizeNamespaces(self, text):
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 9180a35..a688f59 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -1066,7 +1066,29 @@
newtext = s2.replace(marker, '').strip() + separator + s
else:
newtext = s2.replace(marker, '')
- return newtext
+
+ # special parts above interwiki
+ above_interwiki = []
+
+ if site.sitename == 'wikipedia:nn':
+ comment = re.compile(
+ r'<!--interwiki \(no(\/nb)?, *sv, *da first; then other languages '
+ r'alphabetically by name\)-->')
+ above_interwiki.append(comment)
+
+ if above_interwiki:
+ interwiki = _get_regexes(['interwiki'], site)[0]
+ first_interwiki = interwiki.search(newtext)
+ for reg in above_interwiki:
+ special = reg.search(newtext)
+ if special and not isDisabled(newtext, special.start()):
+ newtext = (newtext[:special.start()].strip()
+ + newtext[special.end():])
+ newtext = (newtext[:first_interwiki.start()].strip()
+ + special.group() + '\n'
+ + newtext[first_interwiki.start():])
+
+ return newtext.strip()
def interwikiFormat(links, insite=None):
@@ -1299,14 +1321,6 @@
marker = findmarker(oldtext)
if site is None:
site = pywikibot.Site()
- if site.sitename == 'wikipedia:de' and '{{Personendaten' in oldtext:
- pywikibot.error(
- 'The Pywikibot is no longer allowed to touch categories on the '
- 'German\nWikipedia on pages that contain the Personendaten '
- 'template because of the\nnon-standard placement of that template.'
- '\nSee https://de.wikipedia.org/wiki/Hilfe:Personendaten'
- '#Kopiervorlage')
- return oldtext
if re.search(r'\{\{ *(' + r'|'.join(site.getmagicwords('defaultsort'))
+ r')', oldtext, flags=re.I):
separator = config.line_separator
@@ -1350,6 +1364,27 @@
langs_removed_text, interwiki, site, addOnly=True)
else:
newtext = cats_removed_text.replace(marker, '')
+
+ # special parts under categories
+ under_categories = []
+
+ if site.sitename == 'wikipedia:de':
+ personendaten = re.compile(r'\{\{ *Personendaten.*?\}\}',
+ re.I | re.DOTALL)
+ under_categories.append(personendaten)
+
+ if under_categories:
+ category = _get_regexes(['category'], site)[0]
+ for last_category in category.finditer(newtext):
+ pass
+ for reg in under_categories:
+ special = reg.search(newtext)
+ if special and not isDisabled(newtext, special.start()):
+ newtext = (newtext[:special.start()].strip()
+ + newtext[special.end():])
+ newtext = (newtext[:last_category.end()].strip() + '\n' * 2
+ + special.group() + newtext[last_category.end():])
+
return newtext.strip()
diff --git a/tests/cosmetic_changes_tests.py b/tests/cosmetic_changes_tests.py
index 59779a6..36b41db 100644
--- a/tests/cosmetic_changes_tests.py
+++ b/tests/cosmetic_changes_tests.py
@@ -49,6 +49,12 @@
self.assertEqual('Foo\n{{any template}}\n\n[[Category:Foo]]',
self.cct.standardizePageFooter(
'Foo\n[[category:foo]]\n{{any template}}'))
+ self.assertEqual('Foo\n\n[[Category:Test| ]]\n[[Category:Baz]]',
+ self.cct.standardizePageFooter(
+ 'Foo\n\n[[category:baz]]\n[[category:test]]'))
+ self.assertEqual('Foo\n\n[[Category:Foo]]\n\n{{Personendaten}}',
+ self.cct.standardizePageFooter(
+ 'Foo\n[[category:foo]]\n{{Personendaten}}'))
def test_resolveHtmlEntities(self):
"""Test resolveHtmlEntities method."""
--
To view, visit https://gerrit.wikimedia.org/r/434997
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie9457953701f98e8c952f289b5a5d91934f2a99b
Gerrit-Change-Number: 434997
Gerrit-PatchSet: 1
Gerrit-Owner: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: JAn Dudík <jan.dudik(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <Ladsgroup(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/435695 )
Change subject: [IMPR] Resolve noqa without rules specified
......................................................................
[IMPR] Resolve noqa without rules specified
- fix D400 and fill noqa id where missing
+ also remove unnecessary noqa (either specified in tox.ini
or checks were removed completely from framework)
Change-Id: Ie0e56170e5a48c7ad83035273bc35c8ceab0f717
---
M pwb.py
M pywikibot/exceptions.py
M pywikibot/logging.py
M pywikibot/page.py
M pywikibot/tools/djvu.py
M scripts/interwiki.py
M tests/utils.py
M tests/weblinkchecker_tests.py
8 files changed, 47 insertions(+), 47 deletions(-)
Approvals:
Zhuyifei1999: Looks good to me, but someone else must approve
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py
index 4299842..325ba4b 100755
--- a/pwb.py
+++ b/pwb.py
@@ -72,7 +72,7 @@
except RuntimeError:
remove_modules()
os.environ['PYWIKIBOT2_NO_USER_CONFIG'] = '2'
- import pywikibot # noqa: E402
+ import pywikibot
pwb = pywikibot
@@ -199,7 +199,7 @@
'scripts.maintenance',
'scripts.archive',
'scripts.userscripts']
- from pywikibot import config # noqa: E402
+ from pywikibot import config
if config.user_script_paths:
if isinstance(config.user_script_paths, (tuple, list)):
script_paths = config.user_script_paths + script_paths
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index 9d93dbd..f8cb2fd 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -118,9 +118,9 @@
pass
-class Error(UnicodeMixin, Exception): # noqa
+class Error(UnicodeMixin, Exception):
- """Pywikibot error"""
+ """Pywikibot error."""
# NOTE: UnicodeMixin must be the first object Error class is derived from.
def __init__(self, arg):
@@ -174,9 +174,9 @@
return self.page
-class PageSaveRelatedError(PageRelatedError): # noqa
+class PageSaveRelatedError(PageRelatedError):
- """Saving the page has failed"""
+ """Saving the page has failed."""
message = u"Page %s was not saved."
@@ -218,9 +218,9 @@
pass
-class NoPage(PageRelatedError): # noqa
+class NoPage(PageRelatedError):
- """Page does not exist"""
+ """Page does not exist."""
message = u"Page %s doesn't exist."
@@ -270,9 +270,9 @@
super(InconsistentTitleReceived, self).__init__(page)
-class SiteDefinitionError(Error): # noqa
+class SiteDefinitionError(Error):
- """Site does not exist"""
+ """Site does not exist."""
pass
@@ -283,16 +283,16 @@
NoSuchSite = SiteDefinitionError
-class UnknownSite(SiteDefinitionError): # noqa
+class UnknownSite(SiteDefinitionError):
- """Site does not exist in Family"""
+ """Site does not exist in Family."""
pass
-class UnknownFamily(SiteDefinitionError): # noqa
+class UnknownFamily(SiteDefinitionError):
- """Family is not registered"""
+ """Family is not registered."""
pass
@@ -304,18 +304,18 @@
pass
-class IsRedirectPage(PageRelatedError): # noqa
+class IsRedirectPage(PageRelatedError):
- """Page is a redirect page"""
+ """Page is a redirect page."""
message = u"Page %s is a redirect page."
pass
-class IsNotRedirectPage(PageRelatedError): # noqa
+class IsNotRedirectPage(PageRelatedError):
- """Page is not a redirect page"""
+ """Page is not a redirect page."""
message = u"Page %s is not a redirect page."
@@ -359,43 +359,43 @@
super(InterwikiRedirectPage, self).__init__(page)
-class InvalidTitle(Error): # noqa
+class InvalidTitle(Error):
- """Invalid page title"""
+ """Invalid page title."""
pass
-class LockedPage(PageSaveRelatedError): # noqa
+class LockedPage(PageSaveRelatedError):
- """Page is locked"""
+ """Page is locked."""
message = u"Page %s is locked."
pass
-class LockedNoPage(LockedPage): # noqa
+class LockedNoPage(LockedPage):
- """Title is locked against creation"""
+ """Title is locked against creation."""
message = u"Page %s does not exist and is locked preventing creation."
pass
-class CascadeLockedPage(LockedPage): # noqa
+class CascadeLockedPage(LockedPage):
- """Page is locked due to cascading protection"""
+ """Page is locked due to cascading protection."""
message = u"Page %s is locked due to cascading protection."
pass
-class SectionError(Error): # noqa
+class SectionError(Error):
- """The section specified by # does not exist"""
+ """The section specified by # does not exist."""
pass
@@ -412,27 +412,27 @@
pass
-class EditConflict(PageSaveRelatedError): # noqa
+class EditConflict(PageSaveRelatedError):
- """There has been an edit conflict while uploading the page"""
+ """There has been an edit conflict while uploading the page."""
message = u"Page %s could not be saved due to an edit conflict"
pass
-class PageDeletedConflict(EditConflict): # noqa
+class PageDeletedConflict(EditConflict):
- """Page was deleted since being retrieved"""
+ """Page was deleted since being retrieved."""
message = u"Page %s has been deleted since last retrieved."
pass
-class PageCreatedConflict(EditConflict): # noqa
+class PageCreatedConflict(EditConflict):
- """Page was created by another user"""
+ """Page was created by another user."""
message = u"Page %s has been created since last retrieved."
@@ -471,9 +471,9 @@
pass
-class ServerError(Error): # noqa
+class ServerError(Error):
- """Got unexpected server response"""
+ """Got unexpected server response."""
pass
@@ -485,9 +485,9 @@
pass
-class Server504Error(ServerError): # noqa
+class Server504Error(ServerError):
- """Server timed out with HTTP 504 code"""
+ """Server timed out with HTTP 504 code."""
pass
@@ -509,9 +509,9 @@
# UserBlocked exceptions should in general not be caught. If the bot has
# been blocked, the bot operator should address the reason for the block
# before continuing.
-class UserBlocked(Error): # noqa
+class UserBlocked(Error):
- """Your username or IP has been blocked"""
+ """Your username or IP has been blocked."""
pass
diff --git a/pywikibot/logging.py b/pywikibot/logging.py
index fe66905..776bb4e 100644
--- a/pywikibot/logging.py
+++ b/pywikibot/logging.py
@@ -135,7 +135,7 @@
log message to include an exception traceback.
"""
if toStdout: # maintained for backwards-compatibity only
- from pywikibot.tools import issue_deprecation_warning # noqa
+ from pywikibot.tools import issue_deprecation_warning
issue_deprecation_warning('"toStdout" parameter',
'pywikibot.stdout()', 2)
logoutput(text, decoder, newline, STDOUT, **kwargs)
diff --git a/pywikibot/page.py b/pywikibot/page.py
index a132194..f379381 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1317,7 +1317,7 @@
% (family, self.site.lang))
# cc depends on page directly and via several other imports
from pywikibot.cosmetic_changes import (
- CANCEL_MATCH, CosmeticChangesToolkit) # noqa
+ CANCEL_MATCH, CosmeticChangesToolkit)
ccToolkit = CosmeticChangesToolkit(self.site,
namespace=self.namespace(),
pageTitle=self.title(),
diff --git a/pywikibot/tools/djvu.py b/pywikibot/tools/djvu.py
index 7f88894..b75a83e 100644
--- a/pywikibot/tools/djvu.py
+++ b/pywikibot/tools/djvu.py
@@ -122,7 +122,7 @@
"""Deprecated file_djvu instance variable."""
return self.file
- def check_cache(fn): # noqa: N805
+ def check_cache(fn):
"""Decorator to check if cache shall be cleared."""
cache = ['_page_count', '_has_text', '_page_info']
@@ -135,7 +135,7 @@
return _res
return wrapper
- def check_page_number(fn): # noqa: N805
+ def check_page_number(fn):
"""Decorator to check if page number is valid.
@raises ValueError
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index 36d08fa..75a4a77 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -380,7 +380,7 @@
"""An attempt to save a page with changed interwiki has failed."""
-class LinkMustBeRemoved(SaveError): # noqa
+class LinkMustBeRemoved(SaveError): # noqa: D205,D400
"""
An interwiki link has to be removed, but this can't be done because of user
diff --git a/tests/utils.py b/tests/utils.py
index 0fa75ee..00133dd 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -36,7 +36,7 @@
if not PY2:
import six
else:
- ResourceWarning = None # flake8: F821
+ ResourceWarning = None
OSWIN32 = (sys.platform == 'win32')
diff --git a/tests/weblinkchecker_tests.py b/tests/weblinkchecker_tests.py
index d04bd6c..94c5cf6 100644
--- a/tests/weblinkchecker_tests.py
+++ b/tests/weblinkchecker_tests.py
@@ -29,7 +29,7 @@
def _get_archive_url(self, url, date_string=None):
from memento_client.memento_client import \
- MementoClientException # noqa: E402
+ MementoClientException
if date_string is None:
when = datetime.datetime.now()
--
To view, visit https://gerrit.wikimedia.org/r/435695
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie0e56170e5a48c7ad83035273bc35c8ceab0f717
Gerrit-Change-Number: 435695
Gerrit-PatchSet: 3
Gerrit-Owner: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/432766 )
Change subject: [IMPR] Always import pywikibot in shell.py by default
......................................................................
[IMPR] Always import pywikibot in shell.py by default
- Don't import pywikibot if -noimport option is given
- If additional options are given with -noimport
print a message that they are ignored
- If pywikibot is imported and arguments are given print a message
that they are unknown if they couldn't be handled by handle_args
Bug: T194456
Change-Id: I19262a9e24ce5f0e8515353b1750bae0de83de12
---
M scripts/shell.py
1 file changed, 20 insertions(+), 6 deletions(-)
Approvals:
Zhuyifei1999: Looks good to me, but someone else must approve
Framawiki: Looks good to me, but someone else must approve
Dvorapa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/shell.py b/scripts/shell.py
index 8b1ac12..b119a6c 100755
--- a/scripts/shell.py
+++ b/scripts/shell.py
@@ -1,7 +1,12 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
-Spawns an interactive Python shell.
+Spawns an interactive Python shell and imports the pywikibot library.
+
+The following local option is supported:
+
+-noimport Do not import the pywikibot library. All other arguments are
+ ignored in this case.
Usage:
@@ -13,16 +18,25 @@
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
def main(*args):
"""Script entry point."""
- env = None
- if args:
+ args = list(args)
+ if '-noimport' in args:
+ args.remove('-noimport')
+ env = None
+ warn_type = 'Ignoring'
+ else:
import pywikibot
- pywikibot.handle_args(args)
- env = locals()
+ args = pywikibot.handle_args(args)
+ env = {'pywikibot': pywikibot}
+ warn_type = 'Unknown'
+
+ if args:
+ print('{} arguments: {}\n' # noqa: T001
+ .format(warn_type, ', '.join(args)))
import code
code.interact("""Welcome to the Pywikibot interactive shell!""", local=env)
--
To view, visit https://gerrit.wikimedia.org/r/432766
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I19262a9e24ce5f0e8515353b1750bae0de83de12
Gerrit-Change-Number: 432766
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/435666 )
Change subject: [bugfix] Terminate QuitKeyboardInterrupt sucessfully
......................................................................
[bugfix] Terminate QuitKeyboardInterrupt sucessfully
Terminate a BaseBot script sucessfully even when an input answer is [q]uit
which raises QuitKeyboardInterrupt. On Python 2 Plattforms this terminates
as an exception.
Bug: T195687
Change-Id: I284e2452521fe5915d7e9d6451ee2729869cf16e
---
M pywikibot/bot.py
1 file changed, 7 insertions(+), 3 deletions(-)
Approvals:
Dvorapa: Looks good to me, but someone else must approve
Framawiki: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index e6a058b..c246d99 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1394,10 +1394,14 @@
# exc_info contains exception from self.run() while terminating
exc_info = sys.exc_info()
- if exc_info[0] is None or exc_info[0] is KeyboardInterrupt:
- pywikibot.output("Script terminated successfully.")
+ pywikibot.output('Script terminated ', newline=False)
+ # Python 2 also needs QuitKeyboardInterrupt
+ # to be compared with exc_info[0] (T195687)
+ if exc_info[0] is None or exc_info[0] in (KeyboardInterrupt,
+ QuitKeyboardInterrupt):
+ pywikibot.output('successfully.')
else:
- pywikibot.output("Script terminated by exception:\n")
+ pywikibot.output('by exception:\n')
pywikibot.exception()
def treat(self, page):
--
To view, visit https://gerrit.wikimedia.org/r/435666
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I284e2452521fe5915d7e9d6451ee2729869cf16e
Gerrit-Change-Number: 435666
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/435696 )
Change subject: [bugfix] Adjust page counter in LiveBotTestCase
......................................................................
[bugfix] Adjust page counter in LiveBotTestCase
- With Id9885f7a the page counter was adjusted and skipped pages are
no longer counted. Adjust page counter in LiveBotTestCase._missing_generator
accordingly
- Also fix message strings. str.format can handle properties or
attribute only but it fails for functions.
Bug: T195696
Change-Id: I7a7e5c55c5f1e7859078174cb89110b55e4e2502
---
M pywikibot/bot.py
M tests/bot_tests.py
2 files changed, 6 insertions(+), 6 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 44664f5..7eaae7c 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1621,7 +1621,7 @@
"""Skip page it's site is not on the defined site."""
if page.site != self.site:
pywikibot.warning(
- fill('Skipped "{page}" due to: '
+ fill('Skipped {page} due to: '
'The bot is on site "{site}" but the page on '
'site "{page.site}"'.format(site=self.site, page=page)))
return True
@@ -1760,7 +1760,7 @@
"""Treat page if it exists and handle NoPage from it."""
if not page.exists():
pywikibot.warning(
- 'Page "{page.title()}" does not exist on {page.site}.'
+ 'Page {page} does not exist on {page.site}.'
.format(page=page))
return True
return super(ExistingPageBot, self).skip_page(page)
@@ -1785,7 +1785,7 @@
"""Treat page if doesn't exist."""
if page.exists():
pywikibot.warning(
- 'Page "{page.title()}" does already exist on {page.site}.'
+ 'Page {page} does already exist on {page.site}.'
.format(page=page))
return True
return super(CreatingPageBot, self).skip_page(page)
@@ -1799,7 +1799,7 @@
"""Treat only redirect pages and handle IsNotRedirectPage from it."""
if not page.isRedirectPage():
pywikibot.warning(
- 'Page "{page.title()}" on {page.site} is skipped because it is'
+ 'Page {page} on {page.site} is skipped because it is'
'not a redirect'.format(page=page))
return True
return super(RedirectPageBot, self).skip_page(page)
@@ -1813,7 +1813,7 @@
"""Treat only non-redirect pages and handle IsRedirectPage from it."""
if page.isRedirectPage():
pywikibot.warning(
- 'Page "{page.title()}" on {page.site} is skipped because it is'
+ 'Page {page} on {page.site} is skipped because it is'
'a redirect'.format(page=page))
return True
return super(NoRedirectPageBot, self).skip_page(page)
diff --git a/tests/bot_tests.py b/tests/bot_tests.py
index 5cfade3..da9c7b3 100644
--- a/tests/bot_tests.py
+++ b/tests/bot_tests.py
@@ -314,7 +314,7 @@
def _missing_generator(self):
"""Yield pages and the last one does not exist."""
- self._count = 1
+ self._count = 0 # skip_page skips one page
self._current_page = list(self.site.allpages(total=1))[0]
yield self._current_page
while self._current_page.exists():
--
To view, visit https://gerrit.wikimedia.org/r/435696
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I7a7e5c55c5f1e7859078174cb89110b55e4e2502
Gerrit-Change-Number: 435696
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>