Skip to content

Commit b1ea2fd

Browse files
author
DrTrigon
committed
improvement; follow-up to r11390 in order to use proper output/logging functions
1 parent ae83586 commit b1ea2fd

32 files changed

+147
-164
lines changed

blockpageschecker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def main():
354354

355355
if changes == 0:
356356
# We tried to fix edit-protection templates, but it did not work.
357-
pywikibot.output('Warning : No edit-protection template could be found')
357+
pywikibot.warning('No edit-protection template could be found')
358358

359359
if moveBlockCheck and changes > -1:
360360
# checking move protection now
@@ -402,7 +402,7 @@ def main():
402402

403403
if changes == 0:
404404
# We tried to fix move-protection templates, but it did not work.
405-
pywikibot.output('Warning : No move-protection template could be found')
405+
pywikibot.warning('No move-protection template could be found')
406406

407407

408408
if oldtext != text:

blockreview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def run(self):
8282
self.unblock_tpl[self.site.lang],
8383
defaultNamespace=10)
8484
except KeyError:
85-
pywikibot.output(u'ERROR: Language "%s" not supported by this bot.'
85+
pywikibot.error(u'Language "%s" not supported by this bot.'
8686
% self.site.lang)
8787
else:
8888
for page in genPage.getReferences(follow_redirects=False,

category.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ def load(self, page):
302302
% page.title(asLink=True))
303303
except pywikibot.IsRedirectPage, arg:
304304
redirTarget = pywikibot.Page(self.site, arg.args[0])
305-
pywikibot.output(u"WARNING: Page %s is a redirect to %s; skipping."
306-
% (page.title(asLink=True),
307-
redirTarget.title(asLink=True)))
305+
pywikibot.warning(u"Page %s is a redirect to %s; skipping."
306+
% (page.title(asLink=True),
307+
redirTarget.title(asLink=True)))
308308
else:
309309
return text
310310
return None

catimages.py

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
3535
X-untagged[:#] Use daniel's tool as generator:
3636
X http://toolserver.org/~daniel/WikiSense/UntaggedImages.php
37-
38-
3937
"""
4038

4139
#
@@ -214,10 +212,10 @@ def _detect_Faces_CV(self):
214212
# how small and how many features are detected as faces (or eyes)
215213
scale = max([1., np.average(np.array(img.shape)[0:2]/500.)])
216214
except IOError:
217-
pywikibot.output(u'WARNING: unknown file type [_detect_Faces_CV]')
215+
pywikibot.warning(u'unknown file type [_detect_Faces_CV]')
218216
return
219217
except AttributeError:
220-
pywikibot.output(u'WARNING: unknown file type [_detect_Faces_CV]')
218+
pywikibot.warning(u'unknown file type [_detect_Faces_CV]')
221219
return
222220

223221
#detectAndDraw( image, cascade, nestedCascade, scale );
@@ -419,10 +417,10 @@ def _detect_People_CV(self):
419417
scale = max([1., np.average(np.array(img.shape)[0:2]/400.)])
420418
#scale = max([1., np.average(np.array(img.shape)[0:2]/300.)])
421419
except IOError:
422-
pywikibot.output(u'WARNING: unknown file type [_detect_People_CV]')
420+
pywikibot.warning(u'unknown file type [_detect_People_CV]')
423421
return
424422
except AttributeError:
425-
pywikibot.output(u'WARNING: unknown file type [_detect_People_CV]')
423+
pywikibot.warning(u'unknown file type [_detect_People_CV]')
426424
return
427425

428426
# similar to face detection
@@ -529,10 +527,10 @@ def _util_get_Geometry_CVnSCIPY(self):
529527
# how small and how many features are detected
530528
scale = max([1., np.average(np.array(img.shape)[0:2]/500.)])
531529
except IOError:
532-
pywikibot.output(u'WARNING: unknown file type [_detect_Geometry_CV]')
530+
pywikibot.warning(u'unknown file type [_detect_Geometry_CV]')
533531
return self._buffer_Geometry
534532
except AttributeError:
535-
pywikibot.output(u'WARNING: unknown file type [_detect_Geometry_CV]')
533+
pywikibot.warning(u'unknown file type [_detect_Geometry_CV]')
536534
return self._buffer_Geometry
537535

538536
# similar to face or people detection
@@ -750,7 +748,7 @@ def _detect_SegmentColors_JSEGnPIL(self): # may be SLIC other other too...
750748
(l, t) = (0, 0)
751749
i = im
752750
except IOError:
753-
pywikibot.output(u'WARNING: unknown file type [_detect_SegmentColors_JSEGnPIL]')
751+
pywikibot.warning(u'unknown file type [_detect_SegmentColors_JSEGnPIL]')
754752
return
755753

756754
result = []
@@ -764,7 +762,7 @@ def _detect_SegmentColors_JSEGnPIL(self): # may be SLIC other other too...
764762
##(pic, scale) = self._util_detect_ColorSegments_JSEG(pic) # (final split)
765763
#hist = self._util_get_ColorSegmentsHist_PIL(i, pic, scale) #
766764
except TypeError:
767-
pywikibot.output(u'WARNING: unknown file type [_detect_SegmentColors_JSEGnPIL]')
765+
pywikibot.warning(u'unknown file type [_detect_SegmentColors_JSEGnPIL]')
768766
return
769767
i = 0
770768
# (may be do an additional region merge according to same color names...)
@@ -805,7 +803,7 @@ def _detect_AverageColor_PILnCV(self):
805803
i = Image.open(self.image_path_JPEG)
806804
h = i.histogram()
807805
except IOError:
808-
pywikibot.output(u'WARNING: unknown file type [_detect_AverageColor_PILnCV]')
806+
pywikibot.warning(u'unknown file type [_detect_AverageColor_PILnCV]')
809807
return
810808

811809
result = self._util_average_Color_colormath(h)
@@ -863,7 +861,7 @@ def _detect_Properties_PIL(self):
863861
try:
864862
i = Image.open(self.image_path)
865863
except IOError:
866-
pywikibot.output(u'WARNING: unknown (image) file type [_detect_Properties_PIL]')
864+
pywikibot.warning(u'unknown (image) file type [_detect_Properties_PIL]')
867865
return
868866

869867
# http://mail.python.org/pipermail/image-sig/1999-May/000740.html
@@ -906,7 +904,7 @@ def _detect_Properties_PIL(self):
906904
# result = {}
907905
# # DO NOT use ImageMagick (identify) instead of PIL to get these info !!
908906
else:
909-
pywikibot.output(u'WARNING: unknown (generic) file type [_detect_Properties_PIL]')
907+
pywikibot.warning(u'unknown (generic) file type [_detect_Properties_PIL]')
910908
return
911909

912910
result['Dimensions'] = self.image_size
@@ -1001,7 +999,7 @@ def _util_detect_ColorSegments_JSEG(self, im):
1001999
try:
10021000
smallImg = im.resize( tuple(np.int_(np.array(im.size)/scale)), Image.ANTIALIAS )
10031001
except IOError:
1004-
pywikibot.output(u'WARNING: unknown file type [_util_detect_ColorSegments_JSEG]')
1002+
pywikibot.warning(u'unknown file type [_util_detect_ColorSegments_JSEG]')
10051003
return
10061004

10071005
#im.thumbnail(size, Image.ANTIALIAS) # size is 640x480
@@ -1070,7 +1068,7 @@ def _util_get_ColorSegmentsHist_PIL(self, im, pic, scale):
10701068
try:
10711069
smallImg = im.resize( tuple(np.int_(np.array(im.size)/scale)), Image.ANTIALIAS )
10721070
except IOError:
1073-
pywikibot.output(u'WARNING: unknown file type [_util_get_ColorSegmentsHist_PIL]')
1071+
pywikibot.warning(u'unknown file type [_util_get_ColorSegmentsHist_PIL]')
10741072
return
10751073

10761074
imgsize = float(smallImg.size[0]*smallImg.size[1])
@@ -1190,10 +1188,10 @@ def _detect_Trained_CV(self, info_desc, cascade_file, maxdim=500.):
11901188
# how small and how many features are detected
11911189
scale = max([1., np.average(np.array(img.shape)[0:2]/maxdim)])
11921190
except IOError:
1193-
pywikibot.output(u'WARNING: unknown file type [_detect_Trained_CV]')
1191+
pywikibot.warning(u'unknown file type [_detect_Trained_CV]')
11941192
return
11951193
except AttributeError:
1196-
pywikibot.output(u'WARNING: unknown file type [_detect_Trained_CV]')
1194+
pywikibot.warning(u'unknown file type [_detect_Trained_CV]')
11971195
return
11981196

11991197
# similar to face detection
@@ -1358,10 +1356,10 @@ def _detect_EmbeddedText_poppler(self):
13581356
# pdfinterp.process_pdf(rsrcmgr, device, fp, set(), maxpages=0, password='',
13591357
# caching=True, check_extractable=False)
13601358
#except AssertionError:
1361-
# pywikibot.output(u'WARNING: pdfminer missed, may be corrupt [_detect_EmbeddedText_poppler]')
1359+
# pywikibot.warning(u'pdfminer missed, may be corrupt [_detect_EmbeddedText_poppler]')
13621360
# return
13631361
#except TypeError:
1364-
# pywikibot.output(u'WARNING: pdfminer missed, may be corrupt [_detect_EmbeddedText_poppler]')
1362+
# pywikibot.warning(u'pdfminer missed, may be corrupt [_detect_EmbeddedText_poppler]')
13651363
# return
13661364
#fp.close()
13671365
#device.close()
@@ -1417,7 +1415,7 @@ def _recognize_OpticalCodes_dmtxNzbar(self):
14171415

14181416
scale = max([1., np.average(np.array(img.size)/200.)])
14191417
except IOError:
1420-
pywikibot.output(u'WARNING: unknown file type [_recognize_OpticalCodes_dmtxNzbar]')
1418+
pywikibot.warning(u'unknown file type [_recognize_OpticalCodes_dmtxNzbar]')
14211419
return
14221420

14231421
smallImg = img.resize( (int(img.size[0]/scale), int(img.size[1]/scale)) )
@@ -1454,7 +1452,7 @@ def _recognize_OpticalCodes_dmtxNzbar(self):
14541452
img = Image.open(self.image_path_JPEG).convert('L')
14551453
width, height = img.size
14561454
except IOError:
1457-
pywikibot.output(u'WARNING: unknown file type [_recognize_OpticalCodes_dmtxNzbar]')
1455+
pywikibot.warning(u'unknown file type [_recognize_OpticalCodes_dmtxNzbar]')
14581456
return
14591457

14601458
scanner = zbar.ImageScanner()
@@ -1504,10 +1502,10 @@ def _detect_Chessboard_CV(self):
15041502

15051503
scale = max([1., np.average(np.array(im.shape)[0:2]/1000.)])
15061504
except IOError:
1507-
pywikibot.output(u'WARNING: unknown file type [_detect_Chessboard_CV]')
1505+
pywikibot.warning(u'unknown file type [_detect_Chessboard_CV]')
15081506
return
15091507
except AttributeError:
1510-
pywikibot.output(u'WARNING: unknown file type [_detect_Chessboard_CV]')
1508+
pywikibot.warning(u'unknown file type [_detect_Chessboard_CV]')
15111509
return
15121510

15131511
smallImg = np.empty( (cv.Round(im.shape[1]/scale), cv.Round(im.shape[0]/scale)), dtype=np.uint8 )
@@ -1522,7 +1520,7 @@ def _detect_Chessboard_CV(self):
15221520
#found_all, corners = cv.FindChessboardCorners( im, chessboard_dim )
15231521
found_all, corners = cv2.findChessboardCorners( im, chessboard_dim )
15241522
except cv2.error, e:
1525-
pywikibot.output(u'%s' % e)
1523+
pywikibot.error(u'%s' % e)
15261524

15271525
#cv2.drawChessboardCorners( im, chessboard_dim, corners, found_all )
15281526
##cv2.imshow("win", im)
@@ -1806,7 +1804,7 @@ def _detect_Faces_EXIF(self):
18061804
try:
18071805
(width, height) = (int(float(width)+0.5), int(float(height)+0.5))
18081806
except ValueError:
1809-
pywikibot.output(u'WARNING: %s contains incompatible unit(s), skipped' % ((width, height),))
1807+
pywikibot.warning(u'%s contains incompatible unit(s), skipped' % ((width, height),))
18101808
return
18111809
else:
18121810
(width, height) = self.image_size
@@ -1921,8 +1919,8 @@ def _detect_Faces_EXIF(self):
19211919
available = [item in res for item in ['FacesDetected', 'ValidAFPoints']]
19221920
unknown = ['face' in item.lower() for item in res.keys()]
19231921
if make and (True in (available+unknown)):
1924-
pywikibot.output(u"WARNING: skipped '%s' since not supported (yet) [_detect_Faces_EXIF]" % make)
1925-
pywikibot.output(u"WARNING: FacesDetected: %s - ValidAFPoints: %s" % tuple(available))
1922+
pywikibot.warning(u"skipped '%s' since not supported (yet) [_detect_Faces_EXIF]" % make)
1923+
pywikibot.warning(u"FacesDetected: %s - ValidAFPoints: %s" % tuple(available))
19261924

19271925
# finally, rotate face coordinates if image was rotated
19281926
if wasRotated:
@@ -2209,7 +2207,7 @@ def _detect_AudioFeatures_YAAFE(self):
22092207

22102208
# Load important components
22112209
if (yaafe.loadComponentLibrary('yaafe-io')!=0):
2212-
pywikibot.output(u'WARNING: cannot load yaafe-io component library !') # ! needed, else it will crash !
2210+
pywikibot.warning(u'cannot load yaafe-io component library !') # ! needed, else it will crash !
22132211

22142212
# Build a DataFlow object using FeaturePlan
22152213
fp = yaafe.FeaturePlan(sample_rate=44100, normalize=0.98, resample=False)
@@ -2764,7 +2762,7 @@ def downloadImage(self):
27642762
#self.image_size = (None, None)
27652763
mime = mimetypes.guess_all_extensions('%s/%s' % tuple(self.image_mime[0:2]))
27662764
if self.image_fileext.lower() not in mime:
2767-
pywikibot.output(u'WARNING: File extension does not match MIME type! File extension should be %s.' % mime)
2765+
pywikibot.warning(u'File extension does not match MIME type! File extension should be %s.' % mime)
27682766

27692767
# SVG: rasterize the SVG to bitmap (MAY BE GET FROM WIKI BY DOWNLOAD?...)
27702768
# (Mediawiki uses librsvg too: http://commons.wikimedia.org/wiki/SVG#SVGs_in_MediaWiki)
@@ -3481,12 +3479,12 @@ def main():
34813479
Bot.downloadImage()
34823480
except IOError, err:
34833481
# skip if download not possible
3484-
pywikibot.output(u"WARNING: %s, skipped..." % err)
3482+
pywikibot.warning(u"%s, skipped..." % err)
34853483
continue
34863484
except Exception, err:
34873485
# skip on any unexpected error, but report it
3488-
pywikibot.output(u"ERROR: %s" % err)
3489-
pywikibot.output(u"ERROR: was not able to process page %s !!!\n" %\
3486+
pywikibot.error(u"%s" % err)
3487+
pywikibot.error(u"was not able to process page %s !!!\n" %\
34903488
image.title(asLink=True))
34913489
continue
34923490
resultCheck = Bot.checkStep()
@@ -3496,8 +3494,8 @@ def main():
34963494
if ret:
34973495
outresult.append( ret )
34983496
except AttributeError:
3499-
pywikibot.output(u"ERROR: was not able to process page %s !!!\n" %\
3500-
image.title(asLink=True))
3497+
pywikibot.error(u"was not able to process page %s !!!\n" %\
3498+
image.title(asLink=True))
35013499
limit += -1
35023500
if not tagged:
35033501
posfile = open(os.path.join(scriptdir, 'cache/catimages_start'), "w")
@@ -3548,13 +3546,13 @@ def trainbot(generator, Bot, image_old_namespace, image_namespace):
35483546
Bot.downloadImage()
35493547
except IOError, err:
35503548
# skip if download not possible
3551-
pywikibot.output(u"WARNING: %s, skipped..." % err)
3549+
pywikibot.warning(u"%s, skipped..." % err)
35523550
continue
35533551
except Exception, err:
35543552
# skip on any unexpected error, but report it
3555-
pywikibot.output(u"ERROR: %s" % err)
3556-
pywikibot.output(u"ERROR: was not able to process page %s !!!\n" %\
3557-
image.title(asLink=True))
3553+
pywikibot.error(u"%s" % err)
3554+
pywikibot.error(u"was not able to process page %s !!!\n" %\
3555+
image.title(asLink=True))
35583556
continue
35593557

35603558
# gather all features (information) related to current image

catlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,8 @@ def change_category(article, oldCat, newCat, comment=None, sortKey=None,
655655
newCatList.append(cat)
656656

657657
if not changesMade:
658-
wikipedia.output(u'ERROR: %s is not in category %s!'
659-
% (article.title(asLink=True), oldCat.title()))
658+
wikipedia.error(u'%s is not in category %s!'
659+
% (article.title(asLink=True), oldCat.title()))
660660
else:
661661
text = article.get(get_redirect=True)
662662
try:

censure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333

3434
site = pywikibot.getSite()
3535
if not (site.language() + '.' + site.family.name) in badWordList or not (site.language() + '.' + site.family.name) in logPages:
36-
pywikibot.output('Error: your language isn\'t supported, see the source code for further details')
36+
pywikibot.error('your language isn\'t supported, see the source code for further details')
3737
sys.exit(1)
3838
ownWordPage = pywikibot.Page(site, badWordList[site.language() + '.' + site.family.name])
3939
try:
4040
ownWordList = ownWordPage.get(get_redirect = True)
4141
except pywikibot.NoPage:
42-
pywikibot.output('Error: the page containing the bad word list of your language doesn\'t exist')
42+
pywikibot.error('the page containing the bad word list of your language doesn\'t exist')
4343
sys.exit(1)
4444
ownWordList = ownWordList.split('\n')
4545
del ownWordList[0]
@@ -109,7 +109,7 @@ def checkPage(title, onlyLastDiff = False):
109109
pywikibot.output(u'%s doesn\'t match any of the bad word list' %title)
110110

111111
def main():
112-
pywikibot.output('Warning: this script should not be run manually/directly, but automatically by maintainer.py')
112+
pywikibot.warning('this script should not be run manually/directly, but automatically by maintainer.py')
113113
if len(sys.argv) == 1:
114114
pywikibot.output("Usage: censure.py <article title>")
115115
sys.exit(1)

checkimages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ def findAdditionalProblems(self):
16001600
elif imagechanges.lower() == 'true':
16011601
imagestatus = True
16021602
else:
1603-
pywikibot.output(u"Error! Imagechanges set wrongly!")
1603+
pywikibot.error(u"Imagechanges set wrongly!")
16041604
self.settingsData = None
16051605
break
16061606
summary = tupla[5]

featured.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ def featuredArticles(site, pType):
322322
try:
323323
method = info[site.lang][0]
324324
except KeyError:
325-
pywikibot.output(
326-
u'Error: language %s doesn\'t has %s category source.'
325+
pywikibot.error(
326+
u'language %s doesn\'t has %s category source.'
327327
% (site.lang, pType))
328328
return
329329
name = info[site.lang][1]

fixing_redirects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def workon(page):
187187
try:
188188
page.put(text, comment)
189189
except (pywikibot.Error):
190-
pywikibot.output('Error: unable to put %s' % page)
190+
pywikibot.error('unable to put %s' % page)
191191

192192
def main():
193193
featured = False

0 commit comments

Comments
 (0)