jenkins-bot has submitted this change and it was merged.
Change subject: [color] use color_format from pywikibot.tools.formatter ......................................................................
[color] use color_format from pywikibot.tools.formatter
Change-Id: I78103ec3bb2f32c41c6342929f57e28d714af150 --- M pywikibot/__init__.py M pywikibot/bot.py M pywikibot/data/api.py M pywikibot/logging.py M scripts/add_text.py M scripts/blockpageschecker.py M scripts/blockreview.py M scripts/category.py M scripts/featured.py M scripts/fixing_redirects.py M scripts/interwiki.py M scripts/nowcommons.py M scripts/protect.py M scripts/redirect.py M scripts/reflinks.py M scripts/replace.py M scripts/revertbot.py M scripts/script_wui.py M scripts/spamremove.py M scripts/upload.py M scripts/weblinkchecker.py 21 files changed, 135 insertions(+), 110 deletions(-)
Approvals: XZise: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py index 9d6c7d1..9fe20a8 100644 --- a/pywikibot/__init__.py +++ b/pywikibot/__init__.py @@ -52,6 +52,7 @@ WikiBaseError, CoordinateGlobeUnknownException, ) from pywikibot.tools import PY2, UnicodeMixin, redirect_func +from pywikibot.tools.formatter import color_format from pywikibot.i18n import translate from pywikibot.data.api import UploadWarning from pywikibot.diff import PatchManager @@ -690,11 +691,9 @@
if page_put_queue.qsize() > 1: num, sec = remaining() - format_values = dict(num=num, sec=sec) - output(u'\03{lightblue}' - u'Waiting for %(num)i pages to be put. ' - u'Estimated time remaining: %(sec)s' - u'\03{default}' % format_values) + output(color_format( + '{lightblue}Waiting for {num} pages to be put. ' + 'Estimated time remaining: {sec}{default}', num=num, sec=sec))
while(_putthread.isAlive()): try: diff --git a/pywikibot/bot.py b/pywikibot/bot.py index 25ed2b0..b9c03c9 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -739,8 +739,9 @@ # at the beginning of the link, start red color. # at the end of the link, reset the color to default pywikibot.output(text[max(0, rng[0] - self.context): rng[0]] + - '\03{lightred}' + text[rng[0]: rng[1]] + - '\03{default}' + text[rng[1]: rng[1] + self.context]) + color_format('{lightred}{0}{default}', + text[rng[0]: rng[1]]) + + text[rng[1]: rng[1] + self.context]) question = 'Should the link ' else: question = 'Should the link {lightred}{0}{default} ' @@ -1210,8 +1211,8 @@ msg = u'Working on %r' % page.title() if config.colorized_output: log(msg) - stdout(u'\n\n>>> \03{lightpurple}%s\03{default} <<<' - % page.title()) + stdout(color_format('\n\n>>> {lightpurple}{0}{default} <<<', + page.title())) else: stdout(msg)
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index e5f1752..5af0564 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -30,6 +30,7 @@ import pywikibot from pywikibot import config, login from pywikibot.tools import MediaWikiVersion, deprecated, itergroup, ip, PY2 +from pywikibot.tools.formatter import color_format from pywikibot.exceptions import ( Server504Error, Server414Error, FatalServerError, NoUsername, Error ) @@ -1775,9 +1776,9 @@ def _simulate(self, action): """Simulate action.""" if action and config.simulate and (self.write or action in config.actions_to_block): - pywikibot.output( - u'\03{lightyellow}SIMULATION: %s action blocked.\03{default}' - % action) + pywikibot.output(color_format( + '{lightyellow}SIMULATION: {0} action blocked.{default}', + action)) return {action: {'result': 'Success', 'nochange': ''}}
def _is_wikibase_error_retryable(self, error): diff --git a/pywikibot/logging.py b/pywikibot/logging.py index ed82a98..0577182 100644 --- a/pywikibot/logging.py +++ b/pywikibot/logging.py @@ -124,7 +124,9 @@
text can contain special sequences to create colored output. These consist of the escape character \03 and the color name in curly braces, - e. g. \03{lightpurple}. \03{default} resets the color. + e. g. \03{lightpurple}. \03{default} resets the color. By using the + color_format method from pywikibot.tools.formatter, the escape character + may be omitted.
Other keyword arguments are passed unchanged to the logger; so far, the only argument that is useful is "exc_info=True", which causes the diff --git a/scripts/add_text.py b/scripts/add_text.py index 7120b99..9c13048 100755 --- a/scripts/add_text.py +++ b/scripts/add_text.py @@ -79,6 +79,7 @@
import pywikibot from pywikibot import config, i18n, pagegenerators, textlib +from pywikibot.tools.formatter import color_format
docuReplacements = { '¶ms;': pagegenerators.parameterHelp, @@ -216,8 +217,8 @@ 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.output(color_format( + '\n\n>>> {lightpurple}{0}{default} <<<', page.title())) pywikibot.showDiff(text, newtext) # Let's put the changes. while True: diff --git a/scripts/blockpageschecker.py b/scripts/blockpageschecker.py index 6c7eec1..20de823 100755 --- a/scripts/blockpageschecker.py +++ b/scripts/blockpageschecker.py @@ -50,7 +50,7 @@ # (C) Monobi a.k.a. Wikihermit, 2007 # (C) Filnik, 2007-2011 # (C) Nicolas Dumazet (NicDumZ), 2008-2009 -# (C) Pywikibot team, 2007-2014 +# (C) Pywikibot team, 2007-2015 # # Distributed under the terms of the MIT license. # @@ -62,10 +62,12 @@ import time import re import webbrowser + import pywikibot from pywikibot import i18n from pywikibot import pagegenerators from pywikibot import config +from pywikibot.tools.formatter import color_format
# This is required for the text that is shown when you run this script # with the parameter -help. @@ -441,8 +443,8 @@
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.output(color_format( + '\n\n>>> {lightpurple}{0}{default} <<<', page.title())) pywikibot.showDiff(oldtext, text) if not always: choice = pywikibot.input_choice(u'Do you want to accept these ' diff --git a/scripts/blockreview.py b/scripts/blockreview.py index a656904..5e3261b 100755 --- a/scripts/blockreview.py +++ b/scripts/blockreview.py @@ -15,7 +15,7 @@ """ # # (C) xqt, 2010-2014 -# (C) Pywikibot team, 2014 +# (C) Pywikibot team, 2015 # # Distributed under the terms of the MIT license. # @@ -26,6 +26,7 @@
import pywikibot from pywikibot import i18n +from pywikibot.tools.formatter import color_format
class BlockreviewBot(object): @@ -270,8 +271,8 @@ if text != page.text: # 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.output(color_format( + '\n\n>>> {lightpurple}{0}{default} <<<', page.title())) # show what was changed pywikibot.showDiff(page.get(), text) pywikibot.output(u'Comment: %s' % comment) diff --git a/scripts/category.py b/scripts/category.py index 9b44fc9..484dd13 100755 --- a/scripts/category.py +++ b/scripts/category.py @@ -133,6 +133,7 @@ from pywikibot.tools import ( deprecated_args, deprecated, ModuleDeprecationWrapper, open_archive ) +from pywikibot.tools.formatter import color_format
if sys.version_info[0] > 2: basestring = (str, ) @@ -891,10 +892,10 @@ pywikibot.output(u'') # Show the title of the page where the link was found. # Highlight the title in purple. - pywikibot.output( - u'Treating page \03{lightpurple}%s\03{default}, ' - u'currently in \03{lightpurple}%s\03{default}' - % (article.title(), current_cat.title())) + pywikibot.output(color_format( + 'Treating page {lightpurple}{0}{default}, ' + 'currently in {lightpurple}{1}{default}', + article.title(), current_cat.title()))
# Determine a reasonable amount of context to print try: diff --git a/scripts/featured.py b/scripts/featured.py index a7458c1..6fc81ee 100755 --- a/scripts/featured.py +++ b/scripts/featured.py @@ -57,7 +57,7 @@ # (C) Maxim Razin, 2005 # (C) Leonardo Gregianin, 2005-2008 # (C) xqt, 2009-2014 -# (C) Pywikibot team, 2005-2014 +# (C) Pywikibot team, 2005-2015 # # Distributed under the terms of the MIT license. # @@ -73,6 +73,7 @@ from pywikibot import i18n, textlib, config from pywikibot.pagegenerators import PreloadingGenerator from pywikibot.config2 import LS # line separator +from pywikibot.tools.formatter import color_format
if sys.version_info[0] > 2: unichr = chr @@ -384,9 +385,9 @@ elif p.namespace() == 1 and site.code != 'el': articles.append(pywikibot.Page(p.site, p.title(withNamespace=False))) - pywikibot.output( - '\03{lightred}** %s has %i %s articles\03{default}' - % (site, len(articles), task)) + pywikibot.output(color_format( + '{lightred}** {0} has {1} {2} articles{default}', + site, len(articles), task)) while articles: p = articles.pop(0) if p.title() < self.getOption('afterpage'): diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py index f41e15c..9273772 100755 --- a/scripts/fixing_redirects.py +++ b/scripts/fixing_redirects.py @@ -25,6 +25,7 @@ from pywikibot import pagegenerators from pywikibot.bot import (SingleSiteBot, ExistingPageBot, NoRedirectPageBot, AutomaticTWSummaryBot, suggest_help) +from pywikibot.tools.formatter import color_format
# This is required for the text that is shown when you run this script # with the parameter -help. @@ -101,9 +102,9 @@
mysite = pywikibot.Site() if mysite.sitename == 'wikipedia:nl': - pywikibot.output( - '\03{lightred}There is consensus on the Dutch Wikipedia that ' - 'bots should not be used to fix redirects.\03{default}') + pywikibot.output(color_format( + '{lightred}There is consensus on the Dutch Wikipedia that ' + 'bots should not be used to fix redirects.{default}')) return
if featured: diff --git a/scripts/interwiki.py b/scripts/interwiki.py index 2791ff3..2ef7751 100755 --- a/scripts/interwiki.py +++ b/scripts/interwiki.py @@ -362,6 +362,7 @@ from pywikibot import titletranslate from pywikibot.bot import ListOption, StandardOption from pywikibot.tools import first_upper +from pywikibot.tools.formatter import color_format
if sys.version_info[0] > 2: unicode = str @@ -1931,8 +1932,8 @@ return False
# Show a message in purple. - pywikibot.output( - u"\03{lightpurple}Updating links on page %s.\03{default}" % page) + pywikibot.output(color_format( + '{lightpurple}Updating links on page {0}.{default}', page)) pywikibot.output(u"Changes to be made: %s" % mods) oldtext = page.get() template = (page.namespace() == 10) diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py index 83e5a5b..cfd9d0b 100755 --- a/scripts/nowcommons.py +++ b/scripts/nowcommons.py @@ -52,7 +52,7 @@ # (C) Wikipedian, 2006-2007 # (C) Siebrand Mazeland, 2007-2008 # (C) xqt, 2010-2014 -# (C) Pywikibot team, 2006-2014 +# (C) Pywikibot team, 2006-2015 # # Distributed under the terms of the MIT license. # @@ -69,6 +69,7 @@
from pywikibot import i18n, Bot from pywikibot import pagegenerators as pg +from pywikibot.tools.formatter import color_format
from scripts.image import ImageRobot as ImageBot
@@ -252,8 +253,9 @@ continue url_local = x.group('urllocal') url_commons = x.group('urlcommons') - pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" - % image_local) + pywikibot.output(color_format( + '\n\n>>> {lightpurple}{0}{default} <<<', + image_local)) pywikibot.output(u'Local: %s\nCommons: %s\n' % (url_local, url_commons)) webbrowser.open(url_local, 0, 1) @@ -353,16 +355,16 @@ commonsImagePage.title(withNamespace=False): usingPages = list(localImagePage.usingPages()) if usingPages and usingPages != [localImagePage]: - pywikibot.output( - u'"\03{lightred}%s\03{default}" is still used in %i pages.' - % (localImagePage.title(withNamespace=False), - len(usingPages))) + pywikibot.output(color_format( + '"{lightred}{0}{default}" is still used in {1} pages.', + localImagePage.title(withNamespace=False), + len(usingPages))) if self.getOption('replace') is True: - pywikibot.output( - u'Replacing "\03{lightred}%s\03{default}" by \ - "\03{lightgreen}%s\03{default}".' - % (localImagePage.title(withNamespace=False), - commonsImagePage.title(withNamespace=False))) + pywikibot.output(color_format( + 'Replacing "{lightred}{0}{default}" by ' + '"{lightgreen}{1}{default}".', + localImagePage.title(withNamespace=False), + commonsImagePage.title(withNamespace=False))) bot = ImageBot( pg.FileLinksGenerator(localImagePage), localImagePage.title(withNamespace=False), @@ -399,9 +401,10 @@ pywikibot.output(u'Please change them manually.') continue else: - pywikibot.output( - u'No page is using "\03{lightgreen}%s\03{default}" anymore.' - % localImagePage.title(withNamespace=False)) + pywikibot.output(color_format( + 'No page is using "{lightgreen}{0}{default}" ' + 'anymore.', + localImagePage.title(withNamespace=False))) commonsText = commonsImagePage.get() if self.getOption('replaceonly') is False: if sha1 == commonsImagePage.latest_file_info.sha1: @@ -415,13 +418,13 @@ old versions are not worth keeping.""") continue if self.getOption('always') is False: - pywikibot.output( - u'\n\n>>>> Description on \03{lightpurple}%s\03{default} <<<<\n' - % page.title()) + format_str = color_format( + '\n\n>>>> Description on {lightpurple}%s' + '{default} <<<<\n') + pywikibot.output(format_str % page.title()) pywikibot.output(localImagePage.get()) - pywikibot.output( - u'\n\n>>>> Description on \03{lightpurple}%s\03{default} <<<<\n' - % commonsImagePage.title()) + pywikibot.output(format_str % + commonsImagePage.title()) pywikibot.output(commonsText) if pywikibot.input_yn( u'Does the description on Commons contain ' diff --git a/scripts/protect.py b/scripts/protect.py index bc3d75a..01e2dc4 100755 --- a/scripts/protect.py +++ b/scripts/protect.py @@ -58,6 +58,7 @@ import pywikibot from pywikibot import i18n, pagegenerators from pywikibot.bot import SingleSiteBot +from pywikibot.tools.formatter import color_format
# This is required for the text that is shown when you run this script # with the parameter -help. @@ -185,8 +186,9 @@ else: options['summary'] = arg[len('-summary:'):] elif arg.startswith('-images'): - pywikibot.output('\n\03{lightred}-image option is deprecated. ' - 'Please use -imagelinks instead.\03{default}\n') + pywikibot.output(color_format( + '\n{lightred}-image option is deprecated. ' + 'Please use -imagelinks instead.{default}\n')) local_args.append('-imagelinks' + arg[7:]) elif arg.startswith('-unprotect'): default_level = 'all' diff --git a/scripts/redirect.py b/scripts/redirect.py index 2ffce7e..9084e2d 100755 --- a/scripts/redirect.py +++ b/scripts/redirect.py @@ -85,6 +85,7 @@ import datetime import pywikibot from pywikibot import i18n, xmlreader, Bot +from pywikibot.tools.formatter import color_format
if sys.version_info[0] > 2: basestring = (str, ) @@ -406,8 +407,8 @@ # Show the title of the page we're working on. # Highlight the title in purple. done = not self.getOption('delete') - pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" - % redir_page.title()) + pywikibot.output(color_format( + '\n\n>>> {lightpurple}{0}{default} <<<', redir_page.title())) try: targetPage = redir_page.getRedirectTarget() except pywikibot.IsNotRedirectPage: @@ -531,8 +532,8 @@ redir = 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.title()) + pywikibot.output(color_format( + '\n\n>>> {lightpurple}{0}{default} <<<', redir.title())) newRedir = redir redirList = [] # bookkeeping to detect loops while True: diff --git a/scripts/reflinks.py b/scripts/reflinks.py index f5c73e4..3035fc1 100755 --- a/scripts/reflinks.py +++ b/scripts/reflinks.py @@ -38,7 +38,7 @@ one from i18n/reflinks.py """ # (C) Nicolas Dumazet (NicDumZ), 2008 -# (C) Pywikibot team, 2008-2014 +# (C) Pywikibot team, 2008-2015 # # Distributed under the terms of the MIT license. # @@ -59,6 +59,7 @@ import pywikibot
from pywikibot import i18n, pagegenerators, textlib, xmlreader, Bot +from pywikibot.tools.formatter import color_format
from scripts import noreferences
@@ -566,9 +567,9 @@ # If file has a PDF suffix self.getPDFTitle(ref, f) else: - pywikibot.output( - u'\03{lightyellow}WARNING\03{default} : ' - u'media : %s ' % ref.link) + pywikibot.output(color_format( + '{lightyellow}WARNING{default} : ' + 'media : {0} ', ref.link)) if ref.title: if not re.match( u'(?i) *microsoft (word|excel|visio)', @@ -576,9 +577,9 @@ ref.transform(ispdf=True) repl = ref.refTitle() else: - pywikibot.output( - u'\03{lightyellow}WARNING\03{default} : ' - u'PDF title blacklisted : %s ' % ref.title) + pywikibot.output(color_format( + '{lightyellow}WARNING{default} : ' + 'PDF title blacklisted : {0} ', ref.title)) repl = ref.refLink() else: repl = ref.refLink() @@ -590,15 +591,15 @@ domain.findall(redir) == domain.findall(link): if soft404.search(redir) and \ not soft404.search(ref.link): - pywikibot.output( - u'\03{lightyellow}WARNING\03{default} : ' - u'Redirect 404 : %s ' % ref.link) + pywikibot.output(color_format( + '{lightyellow}WARNING{default} : ' + 'Redirect 404 : {0} ', ref.link)) continue if dirIndex.match(redir) and \ not dirIndex.match(ref.link): - pywikibot.output( - u'\03{lightyellow}WARNING\03{default} : ' - u'Redirect to root : %s ' % ref.link) + pywikibot.output(color_format( + u'{lightyellow}WARNING{default} : ' + u'Redirect to root : {0} ', ref.link)) continue
# uncompress if necessary @@ -617,9 +618,9 @@ except UnicodeError: # example : http://www.adminet.com/jo/20010615%C2%A6/ECOC0100037D.html # in [[fr:Cyanure]] - pywikibot.output( - u'\03{lightred}Bad link\03{default} : %s in %s' - % (ref.url, page.title(asLink=True))) + pywikibot.output(color_format( + '{lightred}Bad link{default} : %s in %s', + ref.url, page.title(asLink=True))) continue except HTTPError as e: pywikibot.output(u'HTTP error (%s) for %s on %s' @@ -684,9 +685,9 @@ pywikibot.output(u'No content-type found for %s' % ref.link) continue elif not self.MIME.search(contentType): - pywikibot.output( - u'\03{lightyellow}WARNING\03{default} : media : %s ' - % ref.link) + pywikibot.output(color_format( + '{lightyellow}WARNING{default} : media : %s ', + ref.link)) repl = ref.refLink() new_text = new_text.replace(match.group(), repl) continue @@ -740,9 +741,9 @@ if self.titleBlackList.match(ref.title): repl = ref.refLink() new_text = new_text.replace(match.group(), repl) - pywikibot.output(u'\03{lightred}WARNING\03{default} %s : ' - u'Blacklisted title (%s)' - % (ref.link, ref.title)) + pywikibot.output(color_format( + '{lightred}WARNING{default} {0} : ' + 'Blacklisted title ({1})', ref.link, ref.title)) continue
# Truncate long titles. 175 is arbitrary @@ -773,8 +774,8 @@ return
if editedpages % 20 == 0: - pywikibot.output( - '\03{lightgreen}Checking stop page...\03{default}') + pywikibot.output(color_format( + '{lightgreen}Checking stop page...{default}')) actualRev = self.stopPage.latest_revision_id if actualRev != self.stopPageRevId: pywikibot.output( diff --git a/scripts/replace.py b/scripts/replace.py index f93c841..da09945 100755 --- a/scripts/replace.py +++ b/scripts/replace.py @@ -153,6 +153,7 @@ from pywikibot import fixes
from pywikibot.tools import chars, deprecated_args +from pywikibot.tools.formatter import color_format
if sys.version_info[0] > 2: basestring = (str, ) @@ -712,8 +713,8 @@ site=page.site) # 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.output(color_format( + '\n\n>>> {lightpurple}{0}{default} <<<', page.title())) pywikibot.showDiff(original_text, new_text) if self.getOption('always'): break diff --git a/scripts/revertbot.py b/scripts/revertbot.py index 1477f17..1f677a1 100755 --- a/scripts/revertbot.py +++ b/scripts/revertbot.py @@ -14,7 +14,7 @@ """ # # (C) Bryan Tong Minh, 2008 -# (C) Pywikibot team, 2008-2014 +# (C) Pywikibot team, 2008-2015 # # Ported by Geoffrey "GEOFBOT" Mon - User:Sn1per # for Google Code-In 2013 @@ -30,6 +30,7 @@ import pywikibot from pywikibot import i18n from pywikibot import pagegenerators +from pywikibot.tools.formatter import color_format
docuReplacements = { '¶ms;': pagegenerators.parameterHelp @@ -104,9 +105,9 @@ 'timestamp': rev.timestamp}) if self.comment: comment += ': ' + self.comment - pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" - % page.title(asLink=True, forceInterwiki=True, - textlink=True)) + pywikibot.output(color_format( + '\n\n>>> {lightpurple}{0}{default} <<<', + page.title(asLink=True, forceInterwiki=True, textlink=True))) if not self.rollback: old = page.text page.text = rev.text diff --git a/scripts/script_wui.py b/scripts/script_wui.py index 320e4a6..a4a20b8 100755 --- a/scripts/script_wui.py +++ b/scripts/script_wui.py @@ -89,6 +89,7 @@ import pywikibot # pywikibot.botirc depends on https://pypi.python.org/pypi/irc import pywikibot.botirc +from pywikibot.tools.formatter import color_format
if sys.version_info[0] > 2: import _thread as thread @@ -126,7 +127,8 @@ """WikiUserInterface bot."""
def __init__(self, *arg): - pywikibot.output(u'\03{lightgreen}* Initialization of bot\03{default}') + pywikibot.output(color_format( + '{lightgreen}* Initialization of bot{default}'))
pywikibot.botirc.IRCBot.__init__(self, *arg)
diff --git a/scripts/spamremove.py b/scripts/spamremove.py index c22d0e4..0a8044d 100755 --- a/scripts/spamremove.py +++ b/scripts/spamremove.py @@ -23,7 +23,7 @@
""" # -# (C) Pywikibot team, 2007-2014 +# (C) Pywikibot team, 2007-2015 # # Distributed under the terms of the MIT license. # @@ -36,6 +36,7 @@ import pywikibot from pywikibot import i18n from pywikibot.editor import TextEditor +from pywikibot.tools.formatter import color_format
def main(*args): @@ -76,8 +77,8 @@ 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.output(color_format( + '\n\n>>> {lightpurple}{0}{default} <<<', p.title())) lines = text.split('\n') newpage = [] lastok = "" @@ -85,7 +86,7 @@ if spamSite in line: if lastok: pywikibot.output(lastok) - pywikibot.output('\03{lightred}%s\03{default}' % line) + pywikibot.output(color_format('{lightred}{0}{default}', line)) lastok = None else: newpage.append(line) diff --git a/scripts/upload.py b/scripts/upload.py index 060d111..ce7032a 100755 --- a/scripts/upload.py +++ b/scripts/upload.py @@ -70,6 +70,7 @@ from pywikibot.tools import ( deprecated ) +from pywikibot.tools.formatter import color_format
if sys.version_info[0] > 2: from urllib.parse import urlparse @@ -374,9 +375,9 @@
while not self.description or self.verifyDescription: if not self.description: - pywikibot.output( - u'\03{lightred}It is not possible to upload a file ' - 'without a summary/description.\03{default}') + pywikibot.output(color_format( + '{lightred}It is not possible to upload a file ' + 'without a summary/description.{default}'))
assert not always # if no description, default is 'yes' diff --git a/scripts/weblinkchecker.py b/scripts/weblinkchecker.py index 5452fdc..23afde0 100755 --- a/scripts/weblinkchecker.py +++ b/scripts/weblinkchecker.py @@ -119,6 +119,7 @@
from pywikibot import i18n, config, pagegenerators, textlib, xmlreader, weblib from pywikibot.bot import ExistingPageBot, SingleSiteBot +from pywikibot.tools.formatter import color_format
# TODO: Convert to httlib2 if sys.version_info[0] > 2: @@ -769,16 +770,16 @@ (url, errorReport, containingPage, archiveURL) = self.queue[0] self.queue = self.queue[1:] talkPage = containingPage.toggleTalkPage() - pywikibot.output( - u'\03{lightaqua}** Reporting dead link on %s...\03{default}' - % talkPage.title(asLink=True)) + pywikibot.output(color_format( + '{lightaqua}** Reporting dead link on {0}...{default}', + talkPage.title(asLink=True))) try: content = talkPage.get() + "\n\n" if url in content: - pywikibot.output( - u'\03{lightaqua}** Dead link seems to have already ' - u'been reported on %s\03{default}' - % talkPage.title(asLink=True)) + pywikibot.output(color_format( + '{lightaqua}** Dead link seems to have already ' + 'been reported on {0}{default}', + talkPage.title(asLink=True))) self.semaphore.release() continue except (pywikibot.NoPage, pywikibot.IsRedirectPage): @@ -817,10 +818,10 @@ try: talkPage.put(content, comment) except pywikibot.SpamfilterError as error: - pywikibot.output( - u'\03{lightaqua}** SpamfilterError while trying to ' - u'change %s: %s\03{default}' - % (talkPage.title(asLink=True), error.url)) + pywikibot.output(color_format( + '{lightaqua}** SpamfilterError while trying to ' + 'change {0}: {1}{default}', + talkPage.title(asLink=True), error.url))
self.semaphore.release()