jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/461118 )
Change subject: [IMPR] Write ignoring pages as a whole
......................................................................
[IMPR] Write ignoring pages as a whole
- PrimaryIgnoreManager.ignore accepts iterables
and writes all it's content to the file
- a new attribute DisambiguationRobot.ignores holds all pages to be ignored
- use teardown() to call PrimaryIgnoreManager.ignore and write
ignoring list finally
Change-Id: Idc4b0e541ed09f98352f217d913d734c641d7692
---
M scripts/solve_disambiguation.py
1 file changed, 14 insertions(+), 7 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py
index 4cdc94a..18bb871 100755
--- a/scripts/solve_disambiguation.py
+++ b/scripts/solve_disambiguation.py
@@ -485,13 +485,15 @@
"""
return self.enabled and refPage.title(as_url=True) in self.ignorelist
- def ignore(self, refPage):
- """Write page to ignorelist.
+ def ignore(self, page_titles):
+ """Write pages to ignorelist.
- @type refPage: pywikibot.Page
- @rtype: None
-
+ @param page_titles: page titles to be ignored
+ @type page_titles: iterable
"""
+ # backward compatibility
+ if isinstance(page_titles, pywikibot.Page):
+ page_titles = [page_titles.title(as_url=True)]
if self.enabled:
# Skip this occurrence next time.
filename = config.datafilepath(
@@ -500,7 +502,7 @@
with suppress(IOError):
# Open file for appending. If none exists, create a new one.
with codecs.open(filename, 'a', 'utf-8') as f:
- f.write(refPage.title(as_url=True) + '\n')
+ f.write('\n'.join(page_titles) + '\n')
class AddAlternativeOption(OutputProxyOption):
@@ -617,6 +619,7 @@
if generator:
self.generator = generator
self.primary = primary
+ self.ignores = set()
self.main_only = main_only
self.first_only = first_only
self.minimum = minimum
@@ -917,7 +920,7 @@
if self.primary:
# If run with the -primary argument, skip this
# occurrence next time.
- self.primaryIgnoreManager.ignore(refPage)
+ self.ignores.add(refPage.title(as_url=True))
return 'nextpage'
if answer == 'g':
@@ -1189,6 +1192,10 @@
'to': targets,
'count': len(new_targets)})
+ def teardown(self):
+ """Write ignoring pages to a file."""
+ self.primaryIgnoreManager.ignore(self.ignores)
+
def treat(self, page) -> None:
"""Work on a single disambiguation page."""
self.primaryIgnoreManager = PrimaryIgnoreManager(
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/461118
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Idc4b0e541ed09f98352f217d913d734c641d7692
Gerrit-Change-Number: 461118
Gerrit-PatchSet: 7
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-MessageType: merged