jenkins-bot has submitted this change and it was merged.
Change subject: Use a new FatalServerError exception for SSL certificate failures
......................................................................
Use a new FatalServerError exception for SSL certificate failures
Failures in SSL certificate verification are unlikely to be fixed by
just retrying the request. This commit introduces a new FatalServerError
class for this (and maybe other) server error.
Change-Id: I19bf597d967e753b944bd5e7ef6c21b06bc900d7
---
M pywikibot/comms/http.py
M pywikibot/data/api.py
M pywikibot/exceptions.py
3 files changed, 18 insertions(+), 1 deletion(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index a8dc98f..1dee9ec 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -27,8 +27,9 @@
import logging
import atexit
+from httplib2 import SSLHandshakeError
from pywikibot import config
-from pywikibot.exceptions import Server504Error
+from pywikibot.exceptions import FatalServerError, Server504Error
import pywikibot
import cookielib
import threadedhttp
@@ -38,6 +39,11 @@
# global variables
+
+# The OpenSSL error code for
+# certificate verify failed
+# cf. `openssl errstr 14090086`
+SSL_CERT_VERIFY_FAILED = ":14090086:"
# the User-agent: header. The default is
# '<script>/<revision> Pywikipediabot/2.0', where '<script>' is the currently
@@ -112,6 +118,10 @@
request.lock.acquire()
#TODO: do some error correcting stuff
+ if isinstance(request.data, SSLHandshakeError):
+ if SSL_CERT_VERIFY_FAILED in str(request.data):
+ raise FatalServerError(str(request.data))
+
#if all else fails
if isinstance(request.data, Exception):
raise request.data
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 237d433..2b23fb4 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -289,6 +289,10 @@
pywikibot.log(u"Caught HTTP 504 error; retrying")
self.wait()
continue
+ except FatalServerError:
+ # This error is not going to be fixed by just waiting
+ pywikibot.error(traceback.format_exc())
+ raise
#TODO: what other exceptions can occur here?
except Exception, e:
# for any other error on the http request, wait and retry
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index c5a7b3f..8972fed 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -119,6 +119,9 @@
class ServerError(Error):
"""Got unexpected server response"""
+class FatalServerError(ServerError):
+ """A fatal server error that's not going to be corrected by just sending
+ the request again."""
class Server504Error(Error):
"""Server timed out with http 504 code"""
--
To view, visit https://gerrit.wikimedia.org/r/80348
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I19bf597d967e753b944bd5e7ef6c21b06bc900d7
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mineo <themineo(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mineo <themineo(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: Make WikidataItemGenerator work if page is already on the repo
......................................................................
Make WikidataItemGenerator work if page is already on the repo
Bug: https://sourceforge.net/p/pywikipediabot/bugs/1653/
Change-Id: Ia9916450a077f6604a3bc3649da4715a280e5b52
---
M pywikibot/pagegenerators.py
1 file changed, 9 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, but someone else must approve
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 8318048..d07b9e0 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -816,13 +816,21 @@
# entry.title() returns a Page object
yield entry.title()
+
def WikidataItemGenerator(gen):
"""
A wrapper generator used to take another generator
and yield their relevant Wikidata items
"""
for page in gen:
- yield pywikibot.ItemPage.fromPage(page)
+ if isinstance(page, pywikibot.ItemPage):
+ yield page
+ elif page.site.data_repository() == page.site:
+ # These are already items, just not item pages
+ # FIXME: If we've already fetched content, we should retain it
+ yield pywikibot.ItemPage(page.site, page.title())
+ else:
+ yield pywikibot.ItemPage.fromPage(page)
#TODO below
--
To view, visit https://gerrit.wikimedia.org/r/80706
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia9916450a077f6604a3bc3649da4715a280e5b52
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Sk!d <swuensch(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: use i18n messages; pep8 changes, update from core (gerrit: 79582)
......................................................................
use i18n messages; pep8 changes, update from core (gerrit: 79582)
Change-Id: Ib5a544ba0b7a123ca2cb4c15a5e0603ebdc9baea
---
M blockpageschecker.py
1 file changed, 155 insertions(+), 119 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/blockpageschecker.py b/blockpageschecker.py
index c6dd531..4329983 100644
--- a/blockpageschecker.py
+++ b/blockpageschecker.py
@@ -56,15 +56,17 @@
# (C) Monobi a.k.a. Wikihermit, 2007
# (C) Filnik, 2007-2011
# (C) NicDumZ, 2008-2009
-# (C) Pywikipedia bot team, 2007-2010
+# (C) Pywikipedia bot team, 2007-2013
#
# Distributed under the terms of the MIT license.
#
__version__ = '$Id$'
#
-import re, webbrowser
+import re
+import webbrowser
import wikipedia as pywikibot
+from pywikibot import i18n
import pagegenerators
import config
import catlib
@@ -80,78 +82,73 @@
################### -- Edit below! -- #################
templateSemiProtection = {
- 'en': None,
- 'it':[r'\{\{(?:[Tt]emplate:|)[Aa]vvisobloccoparziale(?:|[ _]scad\|.*?|\|.*?)\}\}',
- r'\{\{(?:[Tt]emplate:|)[Aa]bp(?:|[ _]scad\|(?:.*?))\}\}'],
- 'fr': [ur'\{\{(?:[Tt]emplate:|[Mm]odèle:|)[Ss]emi[- ]?protection(|[^\}]*)\}\}'],
- 'ja':[ur'(?<!\<nowiki\>)\{\{(?:[Tt]emplate:|)半保護(?:[Ss]|)(?:\|.+|)\}\}(?!\<\/nowiki\>)\s*(?:\r\n|)*'],
- #'zh':[ur'\{\{(?:[Tt]emplate:|)Protected|(?:[Ss]|[Ss]emi|半)(?:\|.+|)\}\}(\n+?|)',ur'\{\{(?:[Tt]emplate:|)Mini-protected|(?:[Ss]|[Ss]emi|半)(?:\|.+|)\}\}(\n+?|)',ur'\{\{(?:[Tt]emplate:|)Protected-logo|(?:[Ss]|[Ss]emi|半)(?:\|.+|)\}\}(\n+?|)'],
- }
-# Regex to get the total-protection template
-templateTotalProtection = {
- 'en': None,
- 'it':[r'\{\{(?:[Tt]emplate:|)[Aa]vvisoblocco(?:|[ _]scad\|(?:.*?)|minaccia|cancellata)\}\}',
- r'\{\{(?:[Tt]emplate:|)(?:[Cc][Tt]|[Cc]anc fatte|[Cc][Ee])\}\}', r'<div class="toccolours[ _]itwiki[ _]template[ _]avviso">(?:\s|\n)*?[Qq]uesta pagina'],
- 'fr':[ur'\{\{(?:[Tt]emplate:|[Mm]odèle:|)[Pp]rotection(|[^\}]*)\}\}',
- ur'\{\{(?:[Tt]emplate:|[Mm]odèle:|)(?:[Pp]age|[Aa]rchive|[Mm]odèle) protégée?(|[^\}]*)\}\}'],
- 'ja':[ur'(?<!\<nowiki\>)\{\{(?:[Tt]emplate:|)保護(?:性急|)(?:[Ss]|)(?:\|.+|)\}\}(?!\<\/nowiki\>)\s*(?:\r\n|)*'],
- #'zh':[r'\{\{(?:[Tt]emplate:|)Protected|(?:[Nn]|[Nn]ormal)(?:\|.+|)\}\}(\n+?|)',r'\{\{(?:[Tt]emplate:|)Mini-protected|(?:[Nn]|[Nn]ormal)(?:\|.+|)\}\}(\n+?|)',r'\{\{(?:[Tt]emplate:|)Protected-logo|(?:[Nn]|[Nn]ormal)(?:\|.+|)\}\}(\n+?|)'],
- }
-# Regex to get the semi-protection move template
-templateSemiMoveProtection = {
- 'en': None,
- 'it':[r'\{\{(?:[Tt]emplate:|)[Aa]vvisobloccospostamento(?:|[ _]scad\|.*?|\|.*?)\}\}'],
- 'ja':[ur'(?<!\<nowiki\>)\{\{(?:[Tt]emplate:|)移動半保護(?:[Ss]|)(?:\|.+|)\}\}(?!\<\/nowiki\>)\s*(?:\r\n|)*'],
- #'zh':[r'\{\{(?:[Tt]emplate:|)Protected|(?:MS|ms)(?:\|.+|)\}\}(\n+?|)',r'\{\{(?:[Tt]emplate:|)Mini-protected|(?:MS|ms)(?:\|.+|)\}\}(\n+?|)',r'\{\{(?:[Tt]emplate:|)Protected-logo|(?:MS|ms)(?:\|.+|)\}\}(\n+?|)'],
- }
-# Regex to get the total-protection move template
-templateTotalMoveProtection = {
- 'en': None,
- 'it':[r'\{\{(?:[Tt]emplate:|)[Aa]vvisobloccospostamento(?:|[ _]scad\|.*?|\|.*?)\}\}'],
- 'ja':[ur'(?<!\<nowiki\>)\{\{(?:[Tt]emplate:|)移動保護(?:[Ss]|)(?:\|.+|)\}\}(?!\<\/nowiki\>)\s*(?:\r\n|)*'],
- #'zh':[ur'\{\{(?:[Tt]emplate:|)Protected|(?:[Mm]|[Mm]ove|移[動动])(?:\|.+|)\}\}(\n+?|)',ur'\{\{(?:[Tt]emplate:|)Mini-protected|(?:[Mm]|[Mm]ove|移[動动])(?:\|.+|)\}\}(\n+?|)',ur'\{\{(?:[Tt]emplate:|)Protected-logo|(?:[Mm]|[Mm]ove|移[動动])(?:\|.+|)\}\}(\n+?|)'],
- }
-
-# If you use only one template for all the type of protection, put it here.
-# You may use only one template or an unique template and some other "old" template that the
-# script should still check (as on it.wikipedia)
-templateUnique = {
- 'en': None,
- 'it': [r'\{\{(?:[Tt]emplate:|)[Pp]rotetta\}\}'],
+ 'en': None,
+ 'it': [r'\{\{(?:[Tt]emplate:|)[Aa]vvisobloccoparziale(?:|[ _]scad\|.*?|\|.*?)\}\}',
+ r'\{\{(?:[Tt]emplate:|)[Aa]bp(?:|[ _]scad\|(?:.*?))\}\}'],
+ 'fr': [ur'\{\{(?:[Tt]emplate:|[Mm]odèle:|)[Ss]emi[- ]?protection(|[^\}]*)\}\}'],
+ 'ja': [ur'(?<!\<nowiki\>)\{\{(?:[Tt]emplate:|)半保護(?:[Ss]|)(?:\|.+|)\}\}(?!\<\/nowiki\>)\s*(?:\r\n|)*'],
}
-# Array: 0 => Semi-block, 1 => Total Block, 2 => Semi-Move, 3 => Total-Move, 4 => template-unique
+# Regex to get the total-protection template
+templateTotalProtection = {
+ 'en': None,
+ 'it': [r'\{\{(?:[Tt]emplate:|)[Aa]vvisoblocco(?:|[ _]scad\|(?:.*?)|minaccia|cancellata)\}\}',
+ r'\{\{(?:[Tt]emplate:|)(?:[Cc][Tt]|[Cc]anc fatte|[Cc][Ee])\}\}',
+ r'<div class="toccolours[ _]itwiki[ _]template[ _]avviso">(?:\s|\n)*?[Qq]uesta pagina'],
+ 'fr': [ur'\{\{(?:[Tt]emplate:|[Mm]odèle:|)[Pp]rotection(|[^\}]*)\}\}',
+ ur'\{\{(?:[Tt]emplate:|[Mm]odèle:|)(?:[Pp]age|[Aa]rchive|[Mm]odèle) protégée?(|[^\}]*)\}\}'],
+ 'ja': [ur'(?<!\<nowiki\>)\{\{(?:[Tt]emplate:|)保護(?:性急|)(?:[Ss]|)(?:\|.+|)\}\}(?!\<\/nowiki\>)\s*(?:\r\n|)*'],
+}
+
+# Regex to get the semi-protection move template
+templateSemiMoveProtection = {
+ 'en': None,
+ 'it': [r'\{\{(?:[Tt]emplate:|)[Aa]vvisobloccospostamento(?:|[ _]scad\|.*?|\|.*?)\}\}'],
+ 'ja': [ur'(?<!\<nowiki\>)\{\{(?:[Tt]emplate:|)移動半保護(?:[Ss]|)(?:\|.+|)\}\}(?!\<\/nowiki\>)\s*(?:\r\n|)*'],
+}
+
+# Regex to get the total-protection move template
+templateTotalMoveProtection = {
+ 'en': None,
+ 'it': [r'\{\{(?:[Tt]emplate:|)[Aa]vvisobloccospostamento(?:|[ _]scad\|.*?|\|.*?)\}\}'],
+ 'ja': [ur'(?<!\<nowiki\>)\{\{(?:[Tt]emplate:|)移動保護(?:[Ss]|)(?:\|.+|)\}\}(?!\<\/nowiki\>)\s*(?:\r\n|)*'],
+}
+
+# If you use only one template for all the type of protection, put it here.
+# You may use only one template or an unique template and some other "old"
+# template that the script should still check (as on it.wikipedia)
+templateUnique = {
+ 'en': None,
+ 'it': [r'\{\{(?:[Tt]emplate:|)[Pp]rotetta\}\}'],
+}
+
+# Array: 0 => Semi-block, 1 => Total Block, 2 => Semi-Move, 3 => Total-Move,
+# 4 => template-unique
templateNoRegex = {
- 'it':['{{Avvisobloccoparziale}}', '{{Avvisoblocco}}', None, None, '{{Protetta}}'],
- 'fr':['{{Semi-protection}}', '{{Protection}}', None, None, None],
- 'ja':[u'{{半保護}}', u'{{保護}}', u'{{移動半保護}}', u'{{移動保護}}', None],
- #'zh':[u'{{Protected/semi}}',u'{{Protected}}',u'{{Protected/ms}}',u'{{Protected/move}}', None],
- }
+ 'it': ['{{Avvisobloccoparziale}}', '{{Avvisoblocco}}', None, None,
+ '{{Protetta}}'],
+ 'fr': ['{{Semi-protection}}', '{{Protection}}', None, None, None],
+ 'ja': [u'{{半保護}}', u'{{保護}}', u'{{移動半保護}}', u'{{移動保護}}', None],
+}
# Category where the bot will check
categoryToCheck = {
- 'en':[u'Category:Protected'],
- 'ar':[u'تصنيف:محتويات محمية'],
- 'fr':[u'Category:Page semi-protégée', u'Category:Page protégée', u'Catégorie:Article protégé'],
- 'he':[u'קטגוריה:ויקיפדיה: דפים מוגנים', u'קטגוריה:ויקיפדיה: דפים מוגנים חלקית'],
- 'it':[u'Categoria:Pagine protette - scadute', u'Categoria:Pagine semiprotette', u'Categoria:Voci protette'],
- 'ja':[u'Category:編集保護中の記事',u'Category:編集半保護中の記事',
- u'Category:移動保護中の記事',],
- 'pt':[u'Category:!Páginas protegidas', u'Category:!Páginas semiprotegidas'],
- 'zh':[u'Category:被保护的页面',u'Category:被保護的模板',u'Category:暂时不能移动的页面',
- u'Category:被半保护的页面',],
- }
-# Comment used when the Bot edits
-comment = {
- 'en':u'Bot: Deleting out-dated template',
- 'ar':u'بوت: حذف قالب قديم',
- 'fr':u'Robot: Mise à jour des bandeaux de protection',
- 'he':u'בוט: מסיר תבנית שעבר זמנה',
- 'it':u'Bot: Tolgo o sistemo template di avviso blocco',
- 'ja':u'ロボットによる: 保護テンプレート除去',
- 'pt':u'Bot: Retirando predefinição de proteção',
- 'zh':u'機器人: 移除過期的保護模板',
- }
+ 'en': [u'Category:Protected'],
+ 'ar': [u'تصنيف:محتويات محمية'],
+ 'fr': [u'Category:Page semi-protégée', u'Category:Page protégée',
+ u'Catégorie:Article protégé'],
+ 'he': [u'קטגוריה:ויקיפדיה: דפים מוגנים',
+ u'קטגוריה:ויקיפדיה: דפים מוגנים חלקית'],
+ 'it': [u'Categoria:Pagine protette - scadute',
+ u'Categoria:Pagine semiprotette', u'Categoria:Voci protette'],
+ 'ja': [u'Category:編集保護中の記事', u'Category:編集半保護中の記事',
+ u'Category:移動保護中の記事'],
+ 'pt': [u'Category:!Páginas protegidas',
+ u'Category:!Páginas semiprotegidas'],
+ 'zh': [u'Category:被保护的页面', u'Category:被保護的模板',
+ u'Category:暂时不能移动的页面', u'Category:被半保护的页面'],
+}
+
# Check list to block the users that haven't set their preferences
project_inserted = ['en', 'fr', 'it', 'ja', 'pt', 'zh']
@@ -159,24 +156,25 @@
#------------------ END PREFERENCES ------------------#
################## -- Edit above! -- ##################
+
def understandBlock(text, TTP, TSP, TSMP, TTMP, TU):
""" Understand if the page is blocked and if it has the right template """
- if TTP != None:
- for catchRegex in TTP: # TTP = templateTotalProtection
+ if TTP:
+ for catchRegex in TTP: # TTP = templateTotalProtection
resultCatch = re.findall(catchRegex, text)
if resultCatch:
return ('sysop-total', catchRegex)
- if TSP != None:
+ if TSP:
for catchRegex in TSP:
resultCatch = re.findall(catchRegex, text)
if resultCatch:
return ('autoconfirmed-total', catchRegex)
- if TU != None:
+ if TU:
for catchRegex in TU:
resultCatch = re.findall(catchRegex, text)
if resultCatch:
return ('unique', catchRegex)
- if TSMP != None and TTMP != None and TTP != TTMP and TSP != TSMP:
+ if TSMP and TTMP and TTP != TTMP and TSP != TSMP:
for catchRegex in TTMP:
resultCatch = re.findall(catchRegex, text)
if resultCatch:
@@ -188,6 +186,7 @@
# If editable means that we have no regex, won't change anything with this
# regex
return ('editable', r'\A\n')
+
def showQuest(site, page):
quest = pywikibot.inputChoice(u'Do you want to open the page?',
@@ -203,13 +202,16 @@
editor = editarticle.TextEditor()
text = editor.edit(page.get())
+
def main():
""" Main Function """
# Loading the comments
- global categoryToCheck, comment, project_inserted
+ global categoryToCheck, project_inserted
# always, define a generator to understand if the user sets one,
# defining what's genFactory
- always = False; generator = False; show = False
+ always = False
+ generator = False
+ show = False
moveBlockCheck = False
protectedpages = False
protectType = 'edit'
@@ -238,7 +240,8 @@
genFactory.handleArg(arg)
if config.mylang not in project_inserted:
- pywikibot.output(u"Your project is not supported by this script.\nYou have to edit the script and add it!")
+ pywikibot.output(u"Your project is not supported by this script.\n"
+ u"You have to edit the script and add it!")
return
site = pywikibot.getSite()
if protectedpages:
@@ -252,7 +255,7 @@
TU = pywikibot.translate(site, templateUnique)
category = pywikibot.translate(site, categoryToCheck)
- commentUsed = pywikibot.translate(site, comment)
+ commentUsed = i18n.twtranslate(site, 'blockpageschecker-summary')
if not generator:
generator = genFactory.getCombinedGenerator()
if not generator:
@@ -298,11 +301,13 @@
try:
config.sysopnames[site.family.name][site.lang]
except:
- pywikibot.output("%s is sysop-protected : this account can't edit it! Skipping..." % pagename)
+ pywikibot.output(u"%s is sysop-protected: "
+ u"this account can't edit it! Skipping..."
+ % pagename)
continue
- # Understand, according to the template in the page, what should be the protection
- # and compare it with what there really is.
+ # Understand, according to the template in the page, what should be the
+ # protection and compare it with what there really is.
TemplateInThePage = understandBlock(text, TTP, TSP, TSMP, TTMP, TU)
# Only to see if the text is the same or not...
oldtext = text
@@ -312,11 +317,12 @@
if not editRestr:
# page is not edit-protected
# Deleting the template because the page doesn't need it.
- if TU != None:
+ if TU:
replaceToPerform = u'|'.join(TTP + TSP + TU)
else:
replaceToPerform = u'|'.join(TTP + TSP)
- text, changes = re.subn('<noinclude>(%s)</noinclude>' % replaceToPerform, '', text)
+ text, changes = re.subn('<noinclude>(%s)</noinclude>'
+ % replaceToPerform, '', text)
if changes == 0:
text, changes = re.subn('(%s)' % replaceToPerform, '', text)
msg = u'The page is editable for all'
@@ -326,28 +332,33 @@
elif editRestr[0] == 'sysop':
# total edit protection
- if (TemplateInThePage[0] == 'sysop-total' and TTP != None) or (TemplateInThePage[0] == 'unique' and TU != None):
+ if (TemplateInThePage[0] == 'sysop-total' and TTP) or \
+ (TemplateInThePage[0] == 'unique' and TU):
msg = 'The page is protected to the sysop'
if not moveBlockCheck:
msg += ', skipping...'
pywikibot.output(msg)
else:
- pywikibot.output(u'The page is protected to the sysop, but the template seems not correct. Fixing...')
- if TU != None:
+ pywikibot.output(u'The page is protected to the sysop, but the '
+ u'template seems not correct. Fixing...')
+ if TU:
text, changes = re.subn(TemplateInThePage[1], TNR[4], text)
else:
text, changes = re.subn(TemplateInThePage[1], TNR[1], text)
- elif TSP != None or TU != None:
+ elif TSP or TU:
# implicitely editRestr[0] = 'autoconfirmed', edit-Semi-protection
- if TemplateInThePage[0] == 'autoconfirmed-total' or TemplateInThePage[0] == 'unique':
+ if TemplateInThePage[0] == 'autoconfirmed-total' or \
+ TemplateInThePage[0] == 'unique':
msg = 'The page is editable only for the autoconfirmed users'
if not moveBlockCheck:
msg += ', skipping...'
pywikibot.output(msg)
else:
- pywikibot.output(u'The page is editable only for the autoconfirmed users, but the template seems not correct. Fixing...')
- if TU != None:
+ pywikibot.output(u'The page is editable only for the '
+ u'autoconfirmed users, but the template '
+ u'seems not correct. Fixing...')
+ if TU:
text, changes = re.subn(TemplateInThePage[1], TNR[4], text)
else:
text, changes = re.subn(TemplateInThePage[1], TNR[0], text)
@@ -365,52 +376,72 @@
changes = -1
if not moveRestr:
- pywikibot.output(u'The page is movable for all, deleting the template...')
+ pywikibot.output(u'The page is movable for all, deleting the '
+ u'template...')
# Deleting the template because the page doesn't need it.
- if TU != None:
+ if TU:
replaceToPerform = u'|'.join(TSMP + TTMP + TU)
else:
replaceToPerform = u'|'.join(TSMP + TTMP)
- text, changes = re.subn('<noinclude>(%s)</noinclude>' % replaceToPerform, '', text)
+ text, changes = re.subn('<noinclude>(%s)</noinclude>'
+ % replaceToPerform, '', text)
if changes == 0:
text, changes = re.subn('(%s)' % replaceToPerform, '', text)
elif moveRestr[0] == 'sysop':
# move-total-protection
- if (TemplateInThePage[0] == 'sysop-move' and TTMP != None) or (TemplateInThePage[0] == 'unique' and TU != None):
- pywikibot.output(u'The page is protected from moving to the sysop, skipping...')
- if TU != None:
- text = oldtext # no changes needed, better to revert the old text.
+ if (TemplateInThePage[0] == 'sysop-move' and TTMP) or \
+ (TemplateInThePage[0] == 'unique' and TU):
+ pywikibot.output(u'The page is protected from moving to '
+ u'the sysop, skipping...')
+ if TU:
+ # no changes needed, better to revert the old text.
+ text = oldtext
else:
- pywikibot.output(u'The page is protected from moving to the sysop, but the template seems not correct. Fixing...')
- if TU != None:
- text, changes = re.subn(TemplateInThePage[1], TNR[4], text)
+ pywikibot.output(u'The page is protected from moving to '
+ u'the sysop, but the template seems not '
+ u'correct. Fixing...')
+ if TU:
+ text, changes = re.subn(TemplateInThePage[1], TNR[4],
+ text)
else:
- text, changes = re.subn(TemplateInThePage[1], TNR[3], text)
+ text, changes = re.subn(TemplateInThePage[1], TNR[3],
+ text)
- elif TSMP != None or TU != None:
- # implicitely moveRestr[0] = 'autoconfirmed', move-semi-protection
- if TemplateInThePage[0] == 'autoconfirmed-move' or TemplateInThePage[0] == 'unique':
- pywikibot.output(u'The page is movable only for the autoconfirmed users, skipping...')
- if TU != None:
- text = oldtext # no changes needed, better to revert the old text.
+ elif TSMP or TU:
+ # implicitely moveRestr[0] = 'autoconfirmed',
+ # move-semi-protection
+ if TemplateInThePage[0] == 'autoconfirmed-move' or \
+ TemplateInThePage[0] == 'unique':
+ pywikibot.output(u'The page is movable only for the '
+ u'autoconfirmed users, skipping...')
+ if TU:
+ # no changes needed, better to revert the old text.
+ text = oldtext
else:
- pywikibot.output(u'The page is movable only for the autoconfirmed users, but the template seems not correct. Fixing...')
- if TU != None:
- text, changes = re.subn(TemplateInThePage[1], TNR[4], text)
+ pywikibot.output(u'The page is movable only for the '
+ u'autoconfirmed users, but the template '
+ u'seems not correct. Fixing...')
+ if TU:
+ text, changes = re.subn(TemplateInThePage[1], TNR[4],
+ text)
else:
- text, changes = re.subn(TemplateInThePage[1], TNR[2], text)
+ text, changes = re.subn(TemplateInThePage[1], TNR[2],
+ text)
if changes == 0:
- # We tried to fix move-protection templates, but it did not work.
+ # We tried to fix move-protection templates, but it did not work
pywikibot.warning('No move-protection template could be found')
-
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(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
+ % page.title())
pywikibot.showDiff(oldtext, text)
if not always:
- choice = pywikibot.inputChoice(u'Do you want to accept these changes?', ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
+ choice = pywikibot.inputChoice(u'Do you want to accept these '
+ u'changes?',
+ ['Yes', 'No', 'All'],
+ ['y', 'N', 'a'], 'N')
if choice == 'a':
always = True
if always or choice == 'y':
@@ -421,8 +452,8 @@
pywikibot.output(u'Edit conflict! skip!')
break
except pywikibot.ServerError:
- # Sometimes there is this error that's quite annoying because
- # can block the whole process for nothing.
+ # Sometimes there is this error that's quite annoying
+ # because can block the whole process for nothing.
errorCount += 1
if errorCount < 5:
pywikibot.output(u'Server Error! Wait..')
@@ -432,19 +463,24 @@
# Prevent Infinite Loops
raise pywikibot.ServerError(u'Fifth Server Error!')
except pywikibot.SpamfilterError, e:
- pywikibot.output(u'Cannot change %s because of blacklist entry %s' % (page.title(), e.url))
+ pywikibot.output(u'Cannot change %s because of '
+ u'blacklist entry %s'
+ % (page.title(), e.url))
break
except pywikibot.PageNotSaved, error:
- pywikibot.output(u'Error putting page: %s' % (error.args,))
+ pywikibot.output(u'Error putting page: %s'
+ % (error.args,))
break
except pywikibot.LockedPage:
- pywikibot.output(u'The page is still protected. Skipping...')
+ pywikibot.output(u'The page is still protected. '
+ u'Skipping...')
break
else:
# Break only if the errors are one after the other
errorCount = 0
break
+
if __name__ == "__main__":
try:
main()
--
To view, visit https://gerrit.wikimedia.org/r/79583
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib5a544ba0b7a123ca2cb4c15a5e0603ebdc9baea
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: set Wikidata as "shared data repository" for Wikivoyage
......................................................................
set Wikidata as "shared data repository" for Wikivoyage
At the moment, only Wikipedia pages are allowed within
the ItemPage.fromPage constructor however, Wikidata
supports Wikivoyage sitelinks.
Change-Id: I16f4c2721cfe3e369a18fdb7fffd73913bfb3193
---
M pywikibot/families/wikivoyage_family.py
1 file changed, 3 insertions(+), 0 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/families/wikivoyage_family.py b/pywikibot/families/wikivoyage_family.py
index 25e9f67..49647d8 100644
--- a/pywikibot/families/wikivoyage_family.py
+++ b/pywikibot/families/wikivoyage_family.py
@@ -20,3 +20,6 @@
for lang in self.languages_by_size])
# Global bot allowed languages on http://meta.wikimedia.org/wiki/Bot_policy/Implementation#Current_implementa…
self.cross_allowed = ['es', 'ru', ]
+
+ def shared_data_repository(self, code, transcluded=False):
+ return ('wikidata', 'wikidata')
--
To view, visit https://gerrit.wikimedia.org/r/80704
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I16f4c2721cfe3e369a18fdb7fffd73913bfb3193
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)live.it>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot
DrTrigon has submitted this change and it was merged.
Change subject: add url/link which points to more info about installation and patch
......................................................................
add url/link which points to more info about installation and patch
Change-Id: I44550cc294d2762d1ea5285221cd23221ba80d75
---
M externals/__init__.py
1 file changed, 3 insertions(+), 1 deletion(-)
Approvals:
DrTrigon: Verified; Looks good to me, approved
diff --git a/externals/__init__.py b/externals/__init__.py
index e7db1c4..3bb6677 100644
--- a/externals/__init__.py
+++ b/externals/__init__.py
@@ -203,7 +203,9 @@
" automatically install it."
" If you say Yes, externals will need administrator"
" privileges, and you might be asked for the administrator"
- " password.")
+ " password. For more info, please confer:\n"
+ " http://www.mediawiki.org/wiki/Manual:Pywikipediabot/"
+ "Installation#Dependencies")
lowlevel_warning("Give externals permission to try to install package?"
" (y/N)")
v = raw_input().upper()
--
To view, visit https://gerrit.wikimedia.org/r/79989
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I44550cc294d2762d1ea5285221cd23221ba80d75
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: DrTrigon <dr.trigon(a)surfeu.ch>
Gerrit-Reviewer: Bináris <wikiposta(a)gmail.com>
Gerrit-Reviewer: DrTrigon <dr.trigon(a)surfeu.ch>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: pep8 changes
......................................................................
pep8 changes
Change-Id: I98e325661635314db5d5fd929c380409938f227c
---
M scripts/claimit.py
1 file changed, 18 insertions(+), 10 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/claimit.py b/scripts/claimit.py
index c1dd021..02bdf35 100755
--- a/scripts/claimit.py
+++ b/scripts/claimit.py
@@ -18,6 +18,7 @@
import pywikibot
from pywikibot import pagegenerators
+
class ClaimRobot:
"""
A bot to add Wikidata claims
@@ -43,7 +44,8 @@
source_values = json.loads(page.get())
source_values = source_values['wikipedia']
for lang in source_values:
- source_values[lang] = pywikibot.ItemPage(self.repo, source_values[lang])
+ source_values[lang] = pywikibot.ItemPage(self.repo,
+ source_values[lang])
if lang in source_values:
self.source = pywikibot.Claim(self.repo, 'p143')
@@ -58,18 +60,22 @@
pywikibot.output('Processing %s' % page)
if not item.exists():
pywikibot.output('%s doesn\'t have a wikidata item :(' % page)
- #TODO FIXME: We should provide an option to create the page
+ # TODO FIXME: We should provide an option to create the page
else:
for claim in self.claims:
if claim.getID() in item.get().get('claims'):
- pywikibot.output(u'A claim for %s already exists. Skipping' % (claim.getID(),))
+ pywikibot.output(
+ u'A claim for %s already exists. Skipping'
+ % (claim.getID(),))
#TODO FIXME: This is a very crude way of dupe checking
else:
- pywikibot.output('Adding %s --> %s' % (claim.getID(), claim.getTarget()))
+ pywikibot.output('Adding %s --> %s'
+ % (claim.getID(), claim.getTarget()))
item.addClaim(claim)
if self.source:
claim.addSource(self.source, bot=True)
- #TODO FIXME: We need to check that we aren't adding a duplicate
+ # TODO FIXME: We need to check that we aren't adding a
+ # duplicate
def main():
@@ -85,14 +91,16 @@
repo = pywikibot.Site().data_repository()
- for i in xrange (0, len(commandline_claims), 2):
+ for i in xrange(0, len(commandline_claims), 2):
claim = pywikibot.Claim(repo, commandline_claims[i])
if claim.getType() == 'wikibase-item':
- target = pywikibot.ItemPage(repo, commandline_claims[i+1])
+ target = pywikibot.ItemPage(repo, commandline_claims[i + 1])
elif claim.getType() == 'string':
- target = commandline_claims[i+1]
+ target = commandline_claims[i + 1]
else:
- raise NotImplementedError("%s datatype is not yet supported by claimit.py" % claim.getType())
+ raise NotImplementedError(
+ "%s datatype is not yet supported by claimit.py"
+ % claim.getType())
claim.setTarget(target)
claims.append(claim)
@@ -100,7 +108,7 @@
if not generator:
# FIXME: Should throw some help
return
-
+
bot = ClaimRobot(generator, claims)
bot.run()
--
To view, visit https://gerrit.wikimedia.org/r/80540
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I98e325661635314db5d5fd929c380409938f227c
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: jenkins-bot