jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/462891 )
Change subject: [cleanup] cleanup scripts/category.py
......................................................................
[cleanup] cleanup scripts/category.py
- use str.format(...) instead of modulo for type specifier
arguments.
- use "+" to concatenate strings in some cases
- remove preleading "u" from strings
Change-Id: I34a808cd60a7e966991bbfbde3f2a67f55cbff67
---
M scripts/category.py
1 file changed, 19 insertions(+), 19 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/category.py b/scripts/category.py
index 6443dca..6e379bb 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -204,30 +204,30 @@
return redir_target
if self.create:
redir_target.text = ''
- pywikibot.output('Redirect target %s does not exist '
- 'yet; creating.'
- % redir_target.title(as_link=True))
+ pywikibot.output('Redirect target {} does not exist '
+ 'yet; creating.'.format(
+ redir_target.title(as_link=True)))
return redir_target
if self.edit_redirects:
return page
- pywikibot.warning('Redirect target %s can not '
- 'be modified; skipping.'
- % redir_target.title(as_link=True))
+ pywikibot.warning('Redirect target {} can not '
+ 'be modified; skipping.'.format(
+ redir_target.title(as_link=True)))
return None
if self.edit_redirects:
return page
- pywikibot.warning('Page %s is a redirect to %s; skipping.'
- % (page.title(as_link=True),
- redir_target.title(as_link=True)))
+ pywikibot.warning('Page {} is a redirect to {}; skipping.'
+ .format(page.title(as_link=True),
+ redir_target.title(as_link=True)))
return None
return page
if self.create:
page.text = ''
- pywikibot.output('Page %s does not exist yet; creating.'
- % page.title(as_link=True))
+ pywikibot.output('Page {} does not exist yet; creating.'
+ .format(page.title(as_link=True)))
return page
- pywikibot.warning('Page %s does not exist; skipping.'
- % page.title(as_link=True))
+ pywikibot.warning('Page {} does not exist; skipping.'
+ .format(page.title(as_link=True)))
return None
def determine_template_target(self, page):
@@ -300,8 +300,8 @@
if not self.is_loaded:
try:
if config.verbose_output:
- pywikibot.output('Reading dump from %s'
- % config.shortpath(self.filename))
+ pywikibot.output('Reading dump from '
+ + config.shortpath(self.filename))
with open_archive(self.filename, 'rb') as f:
databases = pickle.load(f)
# keys are categories, values are 2-tuples with lists as
@@ -778,8 +778,8 @@
Do not use this function from outside the class.
"""
# Some preparing
- pywikibot.output('Moving text from %s to %s.' % (
- self.oldcat.title(), self.newcat.title()))
+ pywikibot.output('Moving text from {} to {}.'.format(
+ self.oldcat.title(), self.newcat.title()))
comma = self.site.mediawiki_message('comma-separator')
authors = comma.join(self.oldcat.contributingUsers())
template_vars = {'oldcat': self.oldcat.title(), 'authors': authors}
@@ -1032,7 +1032,7 @@
def output_range(self, start, end):
"""Output a section and categories from the text."""
- pywikibot.output(self.text[start:end] + '…')
+ pywikibot.output(self.text[start:end] + '...')
# if categories weren't visible, show them additionally
if len(self.text) > end:
@@ -1315,7 +1315,7 @@
cat = pywikibot.Category(self.site, self.catTitle)
pywikibot.output('Generating tree...', newline=False)
tree = self.treeview(cat)
- pywikibot.output(u'')
+ pywikibot.output('')
if self.filename:
pywikibot.output('Saving results in ' + self.filename)
with codecs.open(self.filename, 'a', 'utf-8') as f:
--
To view, visit https://gerrit.wikimedia.org/r/462891
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I34a808cd60a7e966991bbfbde3f2a67f55cbff67
Gerrit-Change-Number: 462891
Gerrit-PatchSet: 1
Gerrit-Owner: D3r1ck01 <alangiderick(a)gmail.com>
Gerrit-Reviewer: D3r1ck01 <alangiderick(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/462525 )
Change subject: [simplify] Introduce new verbose_output method
......................................................................
[simplify] Introduce new verbose_output method
Use a new verbose_output method instead of several
"if pywikibot.config.verbose_output" statements
detached from I4ef9009c91e
Change-Id: I939ba830222a1ea09c4d3503cc0dc38b51d44a07
---
M scripts/patrol.py
1 file changed, 34 insertions(+), 43 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/patrol.py b/scripts/patrol.py
index c48d50f..139d293 100755
--- a/scripts/patrol.py
+++ b/scripts/patrol.py
@@ -66,6 +66,12 @@
_logger = 'patrol'
+def verbose_output(string):
+ """Verbose output."""
+ if pywikibot.config.verbose_output:
+ pywikibot.output(string)
+
+
class PatrolBot(SingleSiteBot):
"""Bot marks the edits as patrolled based on info obtained by whitelist."""
@@ -126,8 +132,7 @@
# Check for a more recent version after versionchecktime in sec.
if (self.whitelist_load_ts and (time.time() - self.whitelist_load_ts <
self.getOption('versionchecktime'))):
- if pywikibot.config.verbose_output:
- pywikibot.output('Whitelist not stale yet')
+ verbose_output('Whitelist not stale yet')
return
whitelist_page = pywikibot.Page(self.site,
@@ -145,8 +150,7 @@
# As there hasn't been any change to the whitelist
# it has been effectively reloaded 'now'
self.whitelist_load_ts = time.time()
- if pywikibot.config.verbose_output:
- pywikibot.output('Whitelist not modified')
+ verbose_output('Whitelist not modified')
return
if self.whitelist:
@@ -167,8 +171,7 @@
def in_list(self, pagelist, title):
"""Check if title present in pagelist."""
- if pywikibot.config.verbose_output:
- pywikibot.output('Checking whitelist for: ' + title)
+ verbose_output('Checking whitelist for: ' + title)
# quick check for exact match
if title in pagelist:
@@ -176,25 +179,21 @@
# quick check for wildcard
if '' in pagelist:
- if pywikibot.config.verbose_output:
- pywikibot.output('wildcarded')
+ verbose_output('wildcarded')
return '.*'
for item in pagelist:
- if pywikibot.config.verbose_output:
- pywikibot.output('checking against whitelist item = ' + item)
+ verbose_output('checking against whitelist item = ' + item)
if isinstance(item, LinkedPagesRule):
- if pywikibot.config.verbose_output:
- pywikibot.output('invoking programmed rule')
+ verbose_output('invoking programmed rule')
if item.match(title):
return item
elif title_match(item, title):
return item
- if pywikibot.config.verbose_output:
- pywikibot.output('not found')
+ verbose_output('not found')
def parse_page_tuples(self, wikitext, user=None):
"""Parse page details apart from 'user:' for use."""
@@ -224,14 +223,12 @@
name, sep, prefix = obj.title.partition('/')
if name.lower() in self._prefixindex_aliases:
if not prefix:
- if pywikibot.config.verbose_output:
- pywikibot.output('Whitelist everything')
+ verbose_output('Whitelist everything')
page = ''
else:
page = prefix
- if pywikibot.config.verbose_output:
- pywikibot.output('Whitelist prefixindex hack '
- 'for: ' + page)
+ verbose_output('Whitelist prefixindex hack for: '
+ + page)
# p = pywikibot.Page(self.site, obj.target[20:])
# obj.namespace = p.namespace
# obj.target = p.title()
@@ -241,8 +238,7 @@
# 'user:'
# the user will be the target of subsequent rules
current_user = obj.title
- if pywikibot.config.verbose_output:
- pywikibot.output('Whitelist user: ' + current_user)
+ verbose_output('Whitelist user: ' + current_user)
continue
else:
page = obj.canonical_title()
@@ -250,19 +246,17 @@
if current_user:
if not user or current_user == user:
if self.is_wikisource_author_page(page):
- if pywikibot.config.verbose_output:
- pywikibot.output('Whitelist author: ' + page)
+ verbose_output('Whitelist author: ' + page)
page = LinkedPagesRule(page)
else:
- if pywikibot.config.verbose_output:
- pywikibot.output('Whitelist page: ' + page)
- if pywikibot.config.verbose_output:
- pywikibot.output('Adding {0}:{1}'
- .format(current_user, page))
+ verbose_output('Whitelist page: ' + page)
+ verbose_output('Adding {0}:{1}'
+ .format(current_user, page))
whitelist[current_user].append(page)
- elif pywikibot.config.verbose_output:
- pywikibot.output('Discarding whitelist page for '
- 'another user: ' + page)
+ else:
+ verbose_output(
+ 'Discarding whitelist page for another user: '
+ + page)
else:
raise Exception('No user set for page ' + page)
@@ -283,9 +277,8 @@
pywikibot.debug('Author ns: {0}; name: {1}'
.format(author_ns, author_ns_prefix), _logger)
if title.find(author_ns_prefix + ':') == 0:
- if pywikibot.config.verbose_output:
- author_page_name = title[len(author_ns_prefix) + 1:]
- pywikibot.output('Found author ' + author_page_name)
+ author_page_name = title[len(author_ns_prefix) + 1:]
+ verbose_output('Found author ' + author_page_name)
return True
def run(self, feed=None):
@@ -322,24 +315,22 @@
self.load_whitelist()
self.repeat_start_ts = time.time()
- if pywikibot.config.verbose_output or self.getOption('ask'):
- pywikibot.output('User {0} has created or modified page {1}'
- .format(username, title))
+ if self.getOption('ask'):
+ verbose_output('User {0} has created or modified page {1}'
+ .format(username, title))
if self.getOption('autopatroluserns') and (page['ns'] == 2 or
page['ns'] == 3):
# simple rule to whitelist any user editing their own userspace
if title.partition(':')[2].split('/')[0].startswith(username):
- if pywikibot.config.verbose_output:
- pywikibot.output('{0} is whitelisted to modify {1}'
- .format(username, title))
+ verbose_output('{0} is whitelisted to modify {1}'
+ .format(username, title))
choice = True
if not choice and username in self.whitelist:
if self.in_list(self.whitelist[username], title):
- if pywikibot.config.verbose_output:
- pywikibot.output('{0} is whitelisted to modify {1}'
- .format(username, title))
+ verbose_output('{0} is whitelisted to modify {1}'
+ .format(username, title))
choice = True
if self.getOption('ask'):
--
To view, visit https://gerrit.wikimedia.org/r/462525
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I939ba830222a1ea09c4d3503cc0dc38b51d44a07
Gerrit-Change-Number: 462525
Gerrit-PatchSet: 3
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: jenkins-bot (75)