jenkins-bot has submitted this change and it was merged.
Change subject: Replace print statements by pywikibot.output ......................................................................
Replace print statements by pywikibot.output
Change-Id: I1003d927d27a7c77a7aecda086f6737d3c225ebe --- M scripts/category.py M scripts/flickrripper.py M scripts/harvest_template.py M scripts/pagefromfile.py M scripts/reflinks.py M scripts/replicate_wiki.py M scripts/solve_disambiguation.py M scripts/upload.py M scripts/version.py 9 files changed, 49 insertions(+), 55 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/category.py b/scripts/category.py index ddf5262..e5ede3d 100755 --- a/scripts/category.py +++ b/scripts/category.py @@ -672,19 +672,16 @@ contextLength = full_text.find('\n\n', contextLength + 2) if contextLength > 1000 or contextLength < 0: contextLength = 500 - print - pywikibot.output(full_text[:contextLength]) - print + + pywikibot.output('\n' + full_text[:contextLength] + '\n')
subcatlist = self.catDB.getSubcats(current_cat) supercatlist = self.catDB.getSupercats(current_cat) - print + if len(subcatlist) == 0: - print 'This category has no subcategories.' - print + pywikibot.output('This category has no subcategories.\n') if len(supercatlist) == 0: - print 'This category has no supercategories.' - print + pywikibot.output('This category has no supercategories.\n') # show subcategories as possible choices (with numbers) for i in range(len(supercatlist)): # layout: we don't expect a cat to have more than 10 supercats @@ -694,22 +691,22 @@ # layout: we don't expect a cat to have more than 100 subcats pywikibot.output(u'%2d - Move down to %s' % (i, subcatlist[i].title())) - print ' j - Jump to another category' - print ' s - Skip this article' - print ' r - Remove this category tag' - print ' ? - Print first part of the page (longer and longer)' + pywikibot.output(' j - Jump to another category') + pywikibot.output(' s - Skip this article') + pywikibot.output(' r - Remove this category tag') + pywikibot.output(' ? - Print first part of the page (longer and longer)') pywikibot.output(u'Enter - Save category as %s' % current_cat.title())
flag = False while not flag: - print '' + pywikibot.output('') choice = pywikibot.input(u'Choice:') if choice in ['s', 'S']: flag = True elif choice == '': pywikibot.output(u'Saving category as %s' % current_cat.title()) if current_cat == original_cat: - print 'No changes necessary.' + pywikibot.output('No changes necessary.') else: catlib.change_category(article, original_cat, current_cat, comment=self.editSummary) @@ -728,15 +725,13 @@ flag = True elif choice == '?': contextLength += 500 - print - pywikibot.output(full_text[:contextLength]) - print + pywikibot.output('\n' + full_text[:contextLength] + '\n')
# if categories possibly weren't visible, show them additionally # (maybe this should always be shown?) if len(full_text) > contextLength: - print '' - print 'Original categories: ' + pywikibot.output('') + pywikibot.output('Original categories: ') for cat in article.categories(): pywikibot.output(u'* %s' % cat.title()) elif choice[0] == 'u': diff --git a/scripts/flickrripper.py b/scripts/flickrripper.py index da96c14..d36275d 100644 --- a/scripts/flickrripper.py +++ b/scripts/flickrripper.py @@ -257,7 +257,7 @@ autonomous=False): """ Process a single Flickr photo """ if photo_id: - print photo_id + pywikibot.output(str(photo_id)) (photoInfo, photoSizes) = getPhoto(flickr, photo_id) if isAllowedLicense(photoInfo) or override: #Get the url of the largest photo @@ -522,7 +522,7 @@ pywikibot.input("Press ENTER after you authorized this program") flickr.get_token_part_two((token, frob)) else: - print 'Accessing public content only' + pywikibot.output('Accessing public content only') flickr = flickrapi.FlickrAPI(config.flickr['api_key'])
group_id = u'' @@ -547,7 +547,7 @@ if config.flickr['reviewer']: reviewer = config.flickr['reviewer'] elif 'commons' in config.sysopnames['commons']: - print config.sysopnames['commons'] + pywikibot.output(config.sysopnames['commons']) reviewer = config.sysopnames['commons']['commons'] elif 'commons' in config.usernames['commons']: reviewer = config.usernames['commons']['commons'] diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py index ea01b18..a0a947f 100755 --- a/scripts/harvest_template.py +++ b/scripts/harvest_template.py @@ -146,7 +146,7 @@ elif claim.getType() == 'string': claim.setTarget(value.strip()) else: - print "%s is not a supported datatype." % claim.getType() + pywikibot.output("%s is not a supported datatype." % claim.getType()) continue
pywikibot.output('Adding %s --> %s' % (claim.getID(), claim.getTarget())) diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py index 2a8c56c..d6dcb34 100644 --- a/scripts/pagefromfile.py +++ b/scripts/pagefromfile.py @@ -259,7 +259,7 @@ f = codecs.open(self.filename, 'r', encoding=config.textfile_encoding) except IOError as err: - print err + pywikibot.output(str(err)) return
text = f.read() diff --git a/scripts/reflinks.py b/scripts/reflinks.py index 9320ab6..a1cacd3 100644 --- a/scripts/reflinks.py +++ b/scripts/reflinks.py @@ -336,7 +336,7 @@ if not name in foundRefNames: # first time ever we meet this name if name == 'population': - print "in" + pywikibot.output("in") v[2] = quoted v[0] = name else: diff --git a/scripts/replicate_wiki.py b/scripts/replicate_wiki.py index c2c80d0..67d073d 100644 --- a/scripts/replicate_wiki.py +++ b/scripts/replicate_wiki.py @@ -58,7 +58,7 @@ else: original_wiki = config.mylang
- print "Syncing from " + original_wiki + pywikibot.output("Syncing from " + original_wiki)
family = options.family or config.family
@@ -69,19 +69,19 @@ if options.namespace and 'help' in options.namespace: nsd = namespaces(self.original) for k in nsd: - print k, nsd[k] + pywikibot.output('%s %s' % (k, nsd[k])) sys.exit()
self.sites = map(lambda s: getSite(s, family), sites)
self.differences = {} self.user_diff = {} - print 'Syncing to', + pywikibot.output('Syncing to', newline=False) for s in self.sites: self.differences[s] = [] self.user_diff[s] = [] - print s, - print + pywikibot.output(str(s), newline=False) + pywikibot.output('')
def check_sysops(self): '''Check if sysops are the same @@ -115,9 +115,9 @@ ]
if self.options.namespace: - print options.namespace + pywikibot.output(str(options.namespace)) namespaces = [int(options.namespace)] - print "Checking these namespaces", namespaces, "\n" + pywikibot.output("Checking these namespaces: %s\n" % (namespaces,))
for ns in namespaces: self.check_namespace(ns) @@ -125,7 +125,7 @@ def check_namespace(self, namespace): '''Check an entire namespace'''
- print "\nCHECKING NAMESPACE", namespace + pywikibot.output("\nCHECKING NAMESPACE %s" % namespace) pages = imap(lambda p: p.title(), self.original.allpages('!', namespace=namespace)) for p in pages: @@ -134,10 +134,10 @@ try: self.check_page(p) except pywikibot.exceptions.NoPage: - print 'Bizarre NoPage exception that we are just going to ignore' + pywikibot.output('Bizarre NoPage exception that we are just going to ignore') except pywikibot.exceptions.IsRedirectPage: - print 'error: Redirectpage - todo: handle gracefully' - print + pywikibot.output('error: Redirectpage - todo: handle gracefully') + pywikibot.output('')
def generate_overviews(self): '''Create page on wikis with overview of bot results''' @@ -155,7 +155,7 @@ else: output += "All users from original are also present on this wiki"
- print output + pywikibot.output(output) sync_overview_page.put(output, self.put_message(site))
def put_message(self, site): @@ -164,7 +164,7 @@ def check_page(self, pagename): '''Check one page'''
- print "\nChecking", pagename, + pywikibot.output("\nChecking %s" % pagename) sys.stdout.flush() page1 = Page(self.original, pagename) txt1 = page1.get() @@ -175,7 +175,7 @@ if prefix: prefix += ':' new_pagename = prefix + page1.titleWithoutNamespace() - print "\nCross namespace, new title: ", new_pagename + pywikibot.output("\nCross namespace, new title: %s", new_pagename) else: new_pagename = pagename
@@ -189,12 +189,12 @@ if str(site) in config.replicate_replace: txt_new = multiple_replace(txt1, config.replicate_replace[str(site)]) if txt1 != txt_new: - print 'NOTE: text replaced using config.sync_replace' - print txt1, txt_new, txt2 + pywikibot.output('NOTE: text replaced using config.sync_replace') + pywikibot.output('%s %s %s' % (txt1, txt_new, txt2)) txt1 = txt_new
if txt1 != txt2: - print "\n", site, 'DIFFERS' + pywikibot.output("\n %s DIFFERS" % site) self.differences[site].append(pagename)
if self.options.replace: diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py index b435cba..1187113 100644 --- a/scripts/solve_disambiguation.py +++ b/scripts/solve_disambiguation.py @@ -1071,10 +1071,10 @@ generator = pagegenerators.NamespaceFilterPageGenerator( generator, [0]) except pywikibot.NoPage: - print "Disambiguation category for your wiki is not known." + pywikibot.output("Disambiguation category for your wiki is not known.") raise elif arg.startswith("-"): - print "Unrecognized command line argument: %s" % arg + pywikibot.output("Unrecognized command line argument: %s" % arg) # show help text and exit pywikibot.showHelp() else: diff --git a/scripts/upload.py b/scripts/upload.py index 476841e..c1a15b6 100755 --- a/scripts/upload.py +++ b/scripts/upload.py @@ -84,8 +84,7 @@ infile = uo.open(self.url)
if 'text/html' in infile.info().getheader('Content-Type'): - print \ -"Couldn't download the image: the requested URL was not found on server." + pywikibot.output(u"Couldn't download the image: the requested URL was not found on server.") return
content_len = infile.info().getheader('Content-Length') @@ -157,7 +156,7 @@ invalid = set(forbidden) & set(newfn) if invalid: c = "".join(invalid) - print "Invalid character(s): %s. Please try again" % c + pywikibot.output("Invalid character(s): %s. Please try again" % c) continue if ext not in allowed_formats: choice = pywikibot.inputChoice( diff --git a/scripts/version.py b/scripts/version.py index 94d8f65..42a08b6 100755 --- a/scripts/version.py +++ b/scripts/version.py @@ -17,13 +17,13 @@ from pywikibot import config2 as config
if __name__ == '__main__': - print 'Pywikibot: %s' % getversion() - print 'Release version: %s' % pywikibot.__release__ - print 'Python: %s' % sys.version - #print 'config-settings:' - #print 'site_interface =', config.site_interface - #print 'API_config_expiry =', config.API_config_expiry + pywikibot.output('Pywikibot: %s' % getversion()) + pywikibot.output('Release version: %s' % pywikibot.__release__) + pywikibot.output('Python: %s' % sys.version) + #pywikibot.output('config-settings:') + #pywikibot.output('site_interface =', config.site_interface) + #pywikibot.output('API_config_expiry =', config.API_config_expiry) if not __import__('unicodedata').normalize('NFC', u'\u092e\u093e\u0930\u094d\u0915 \u091c\u093c\u0941\u0915\u0947\u0930\u092c\u0930\u094d\u0917') == u'\u092e\u093e\u0930\u094d\u0915 \u091c\u093c\u0941\u0915\u0947\u0930\u092c\u0930\u094d\u0917': - print u'unicode test: triggers problem #3081100' + pywikibot.output(u'unicode test: triggers problem #3081100') else: - print u'unicode test: ok' + pywikibot.output(u'unicode test: ok')
pywikibot-commits@lists.wikimedia.org