jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[cleanup] cleanup scripts/pagefromfile.py

- remove preleading "u" from strings
- use single quotes for string literals and double quotes
**only** if they consist of single quotes within them
- use str.format(...) instead of modulo for type specifier
arguments

Change-Id: I8610b993b8016162c7378313825431ad312df55c
---
M scripts/pagefromfile.py
1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py
index 09b7f8e..52f1d44 100755
--- a/scripts/pagefromfile.py
+++ b/scripts/pagefromfile.py
@@ -139,23 +139,25 @@
else:
comment = i18n.twtranslate(self.site, 'pagefromfile-msg')

- comment_top = comment + " - " + i18n.twtranslate(
+ comment_top = comment + ' - ' + i18n.twtranslate(
self.site, 'pagefromfile-msg_top')
- comment_bottom = comment + " - " + i18n.twtranslate(
+ comment_bottom = comment + ' - ' + i18n.twtranslate(
self.site, 'pagefromfile-msg_bottom')
- comment_force = "%s *** %s ***" % (
+ comment_force = '{0} *** {1} ***'.format(
comment, i18n.twtranslate(self.site, 'pagefromfile-msg_force'))

if page.exists():
if not self.getOption('redirect') and page.isRedirectPage():
- pywikibot.output(u"Page %s is redirect, skipping!" % title)
+ pywikibot.output('Page {0} is redirect, skipping!'
+ .format(title))
return
pagecontents = page.text
nocontent = self.getOption('nocontent')
if nocontent and (
nocontent in pagecontents or
nocontent.lower() in pagecontents):
- pywikibot.output('Page has %s so it is skipped' % nocontent)
+ pywikibot.output('Page has {0} so it is skipped'
+ .format(nocontent))
return
if self.getOption('append'):
separator = self.getOption('append')[1]
@@ -171,11 +173,12 @@
.format(title, self.getOption('append')[0]))
contents = above + separator + below
elif self.getOption('force'):
- pywikibot.output(u"Page %s already exists, ***overwriting!"
- % title)
+ pywikibot.output('Page {0} already exists, ***overwriting!'
+ .format(title))
comment = comment_force
else:
- pywikibot.output('Page %s already exists, not adding!' % title)
+ pywikibot.output('Page {0} already exists, not adding!'
+ .format(title))
return
else:
if self.getOption('autosummary'):
@@ -224,7 +227,7 @@

def __iter__(self):
"""Read file and yield a tuple of page title and content."""
- pywikibot.output('\n\nReading \'%s\'...' % self.filename)
+ pywikibot.output("\n\nReading '{0}'...".format(self.filename))
try:
with codecs.open(self.filename, 'r',
encoding=config.textfile_encoding) as f:
@@ -241,12 +244,12 @@
length, title, contents = self.findpage(text[position:])
except AttributeError:
if not length:
- pywikibot.output(u'\nStart or end marker not found.')
+ pywikibot.output('\nStart or end marker not found.')
else:
- pywikibot.output(u'End of file.')
+ pywikibot.output('End of file.')
break
except NoTitle as err:
- pywikibot.output(u'\nNo title found - skipping a page.')
+ pywikibot.output('\nNo title found - skipping a page.')
position += err.offset
continue
if length == 0:
@@ -324,11 +327,11 @@
elif option in ('nocontent', 'summary'):
options[option] = value
else:
- pywikibot.output(u"Disregarding unknown argument %s." % arg)
+ pywikibot.output('Disregarding unknown argument {0}.'.format(arg))

failed_filename = False
while not os.path.isfile(filename):
- pywikibot.output('\nFile \'%s\' does not exist. ' % filename)
+ pywikibot.output("\nFile '{0}' does not exist. ".format(filename))
_input = pywikibot.input(
'Please enter the file name [q to quit]:')
if _input == 'q':
@@ -348,5 +351,5 @@
bot.run()


-if __name__ == "__main__":
+if __name__ == '__main__':
main()

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I8610b993b8016162c7378313825431ad312df55c
Gerrit-Change-Number: 462448
Gerrit-PatchSet: 3
Gerrit-Owner: D3r1ck01 <alangiderick@gmail.com>
Gerrit-Reviewer: D3r1ck01 <alangiderick@gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)