Ricordisamoa has uploaded a new change for review.
https://gerrit.wikimedia.org/r/151822
Change subject: WIP - new pywikibot.working_on() method to show the current
working page
......................................................................
WIP - new pywikibot.working_on() method to show the current working page
Nearly every script that 'treats' a page used to print its title
in purple on the screen, now this method uses the standard output
for the colorized message and the logging.VERBOSE level
for the %r-formatted string.
Further enhancements could include setting a framework property
to get the current working page at any time.
DO NOT MERGE
Change-Id: I886c48c7bf7b66917be814df3833f70caa22bd4a
---
M pywikibot/bot.py
M scripts/add_text.py
M scripts/basic.py
M scripts/blockpageschecker.py
M scripts/capitalize_redirects.py
M scripts/cosmetic_changes.py
M scripts/disambredir.py
M scripts/fixing_redirects.py
M scripts/pagefromfile.py
M scripts/redirect.py
M scripts/selflink.py
M scripts/spamremove.py
M scripts/unusedfiles.py
13 files changed, 20 insertions(+), 40 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/22/151822/1
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 46cd023..0913e64 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -429,6 +429,14 @@
logoutput(text, decoder, newline, DEBUG, layer, **kwargs)
+def working_on(page, decoder=None, newline=True, **kwargs):
+ """Output and log a record of the current working page."""
+ log(u'Working on %r' % page, decoder, newline, **kwargs)
+ # Highlight the title in purple.
+ stdout(u'\n\n>>> \03{lightpurple}%s\03{default} <<<' % page.title(),
+ decoder, newline, **kwargs)
+
+
def exception(msg=None, decoder=None, newline=True, tb=False, **kwargs):
"""Output an error traceback to the user via the userinterface.
diff --git a/scripts/add_text.py b/scripts/add_text.py
index a8aca2f..94ee535 100644
--- a/scripts/add_text.py
+++ b/scripts/add_text.py
@@ -216,8 +216,7 @@
else:
newtext = addText + config.line_separator + text
if putText and text != newtext:
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ pywikibot.working_on(page)
pywikibot.showDiff(text, newtext)
# Let's put the changes.
while True:
diff --git a/scripts/basic.py b/scripts/basic.py
index 7a8c6c5..3028385 100755
--- a/scripts/basic.py
+++ b/scripts/basic.py
@@ -103,10 +103,7 @@
""" Update the given page with new text. """
# only save if something was changed
if text != page.get():
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ pywikibot.working_on(page)
# show what was changed
pywikibot.showDiff(page.get(), text)
pywikibot.output(u'Comment: %s' % comment)
diff --git a/scripts/blockpageschecker.py b/scripts/blockpageschecker.py
index 770d906..13dcfc8 100755
--- a/scripts/blockpageschecker.py
+++ b/scripts/blockpageschecker.py
@@ -440,8 +440,7 @@
if oldtext != text:
# Ok, asking if the change has to be performed and do it if yes.
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ pywikibot.working_on(page)
pywikibot.showDiff(oldtext, text)
if not always:
choice = pywikibot.inputChoice(u'Do you want to accept these '
diff --git a/scripts/capitalize_redirects.py b/scripts/capitalize_redirects.py
index 814d771..f6c2243 100644
--- a/scripts/capitalize_redirects.py
+++ b/scripts/capitalize_redirects.py
@@ -57,10 +57,7 @@
if page.isRedirectPage():
page = page.getRedirectTarget()
page_t = page.title()
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u"\n>>> \03{lightpurple}%s\03{default} <<<"
- % page_t)
+ pywikibot.working_on(page)
if self.getOption('titlecase'):
page_cap = pywikibot.Page(page.site, page_t.title())
else:
diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py
index 90edde5..2c01157 100755
--- a/scripts/cosmetic_changes.py
+++ b/scripts/cosmetic_changes.py
@@ -851,10 +851,7 @@
def treat(self, page):
try:
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ pywikibot.working_on(page)
ccToolkit = CosmeticChangesToolkit(page.site, debug=True,
namespace=page.namespace(),
pageTitle=page.title())
diff --git a/scripts/disambredir.py b/scripts/disambredir.py
index a402a44..9655632 100644
--- a/scripts/disambredir.py
+++ b/scripts/disambredir.py
@@ -128,10 +128,7 @@
def workon(page, links):
text = page.get()
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ pywikibot.working_on(page)
for page2 in links:
try:
target = page2.getRedirectTarget()
diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py
index e257da8..72b17d7 100644
--- a/scripts/fixing_redirects.py
+++ b/scripts/fixing_redirects.py
@@ -156,8 +156,7 @@
except pywikibot.NoPage:
pywikibot.output(u'%s does not exist. Skipping' % page)
return
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ pywikibot.working_on(page)
links = page.linkedPages()
if links is not None:
links = pagegenerators.PreloadingGenerator(links)
diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py
index 221065e..ba32411 100644
--- a/scripts/pagefromfile.py
+++ b/scripts/pagefromfile.py
@@ -88,10 +88,7 @@
mysite = pywikibot.Site()
page = pywikibot.Page(mysite, title)
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u">>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ pywikibot.working_on(page)
if self.getOption('summary'):
comment = self.getOption('summary')
diff --git a/scripts/redirect.py b/scripts/redirect.py
index 7d681fc..a2c617a 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -433,10 +433,7 @@
def delete_1_broken_redirect(self, redir_name):
redir_page = pywikibot.Page(self.site, redir_name)
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % redir_page.title())
+ pywikibot.working_on(redir_page)
try:
targetPage = redir_page.getRedirectTarget()
except pywikibot.IsNotRedirectPage:
diff --git a/scripts/selflink.py b/scripts/selflink.py
index f618aaa..675d008 100644
--- a/scripts/selflink.py
+++ b/scripts/selflink.py
@@ -138,10 +138,7 @@
return False
def treat(self, page):
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
+ pywikibot.working_on(page)
try:
oldText = page.text
# Inside image maps, don't touch selflinks, as they're used
diff --git a/scripts/spamremove.py b/scripts/spamremove.py
index 60906f1..812397c 100755
--- a/scripts/spamremove.py
+++ b/scripts/spamremove.py
@@ -69,10 +69,7 @@
text = p.text
if spamSite not in text:
continue
- # Show the title of the page we're working on.
- # Highlight the title in purple.
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % p.title())
+ pywikibot.working_on(p)
lines = text.split('\n')
newpage = []
lastok = ""
diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py
index 75ae002..7eff4a3 100644
--- a/scripts/unusedfiles.py
+++ b/scripts/unusedfiles.py
@@ -103,8 +103,7 @@
if (except_text_translated.encode('utf-8')
not in image.getImagePageHtml() and
u'http://' not in image.text):
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % image.title())
+ pywikibot.working_on(image)
if template_image in image.text:
pywikibot.output(u"%s done already"
% image.title(asLink=True))
--
To view, visit https://gerrit.wikimedia.org/r/151822
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I886c48c7bf7b66917be814df3833f70caa22bd4a
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits