jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved Mpaa: Looks good to me, approved jenkins-bot: Verified
[IMPR]: delete.py: count deleted pages and other actions

Show how many pages are:
- deleted
- marked for deletion
- no actions taken

Bug: T212040
Change-Id: Icf2a05b0b4d743273e3e768eee0e1b714759ea45
---
M pywikibot/page/_pages.py
M scripts/delete.py
M tests/page_tests.py
3 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/pywikibot/page/_pages.py b/pywikibot/page/_pages.py
index 6d2f056..dca6379 100644
--- a/pywikibot/page/_pages.py
+++ b/pywikibot/page/_pages.py
@@ -51,8 +51,8 @@
from pywikibot.page._links import BaseLink, Link
from pywikibot.site import Namespace, NamespaceArgType
from pywikibot.tools import (
- cached,
ComparableMixin,
+ cached,
first_upper,
issue_deprecation_warning,
remove_last_args,
@@ -1795,7 +1795,7 @@
automatic_quit: bool = False,
*,
deletetalk: bool = False
- ) -> None:
+ ) -> int:
"""
Delete the page from the wiki. Requires administrator status.

@@ -1811,6 +1811,12 @@
will be asked before marking pages for deletion.
:param automatic_quit: show also the quit option, when asking
for confirmation.
+
+ :return: the function returns an integer, with values as follows:
+ value meaning
+ 0 no action was done
+ 1 page was deleted
+ -1 page was marked for deletion
"""
if reason is None:
pywikibot.output('Deleting {}.'.format(self.title(as_link=True)))
@@ -1830,7 +1836,9 @@
self.site._noDeletePrompt = True
if answer == 'y':
self.site.delete(self, reason, deletetalk=deletetalk)
- return
+ return 1
+ else:
+ return 0

# Otherwise mark it for deletion
if mark or hasattr(self.site, '_noMarkDeletePrompt'):
@@ -1854,6 +1862,9 @@
target = self
target.text = template + target.text
target.save(summary=reason)
+ return -1
+ else:
+ return 0

def has_deleted_revisions(self) -> bool:
"""Return True if the page has deleted revisions.
diff --git a/scripts/delete.py b/scripts/delete.py
index 99f4cd0..b9876e2 100755
--- a/scripts/delete.py
+++ b/scripts/delete.py
@@ -191,6 +191,7 @@
"""Process one page from the generator."""
if self.opt.undelete:
self.current_page.undelete(self.summary)
+ self.counter['undelete'] += 1
else:
if (self.opt.isorphan is not False
and not self.opt.always):
@@ -210,10 +211,16 @@

if self.current_page.site.user() is None:
self.current_page.site.login()
- self.current_page.delete(self.summary,
- not self.opt.always,
- self.opt.always,
- automatic_quit=True)
+ res = self.current_page.delete(self.summary,
+ not self.opt.always,
+ self.opt.always,
+ automatic_quit=True)
+ if res > 0:
+ self.counter['delete'] += 1
+ elif res < 0:
+ self.counter['marked-for-deletion'] += 1
+ else:
+ self.counter['no-action'] += 1


def main(*args: str) -> None:
diff --git a/tests/page_tests.py b/tests/page_tests.py
index c58d6b8..c9ace28 100755
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -1047,8 +1047,9 @@
p.save('Pywikibot unit test', botflag=True)

# Test deletion
- p.delete(reason='Pywikibot unit test', prompt=False, mark=False)
+ res = p.delete(reason='Pywikibot unit test', prompt=False, mark=False)
self.assertEqual(p._pageid, 0)
+ self.assertEqual(res, 1)
with self.assertRaisesRegex(NoPageError, NO_PAGE_RE):
p.get(force=True)


To view, visit change 791679. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Icf2a05b0b4d743273e3e768eee0e1b714759ea45
Gerrit-Change-Number: 791679
Gerrit-PatchSet: 5
Gerrit-Owner: Mpaa <mpaa.wiki@gmail.com>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged