jenkins-bot has submitted this change and it was merged.
Change subject: [FEAT] enable -always option for fixing_redirects.py
......................................................................
[FEAT] enable -always option for fixing_redirects.py
- use multiple inheritance of several bot classes
- global methods moved into class
- remove obsolete choice and replaceit variables because their content is
static. Remove obsolete code parts which depends on them.
- improve exception handling
- use wikidata for -featured option and use category contents
- check whether -featured option is available for the given site
- deny changes to user namespace as noted by comment
bug: T100122
Change-Id: I9c52afe218e20f6ab2ecf41fdaf7934341cd2093
---
M scripts/fixing_redirects.py
1 file changed, 64 insertions(+), 78 deletions(-)
Approvals:
XZise: Looks good to me, but someone else must approve
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py
index f689ec4..8dbf5b4 100755
--- a/scripts/fixing_redirects.py
+++ b/scripts/fixing_redirects.py
@@ -6,16 +6,14 @@
Can be using with:
¶ms;
--featured Run over featured pages
+-featured Run over featured pages (for some wikimedia wikis only)
Run fixing_redirects.py -help to see all the command-line
options -file, -ref, -links, ...
"""
#
-# This script based on disambredir.py and solve_disambiguation.py
-#
-# (C) Pywikibot team, 2004-2014
+# (C) Pywikibot team, 2004-2015
#
# Distributed under the terms of the MIT license.
#
@@ -23,10 +21,10 @@
__version__ = '$Id$'
#
-import sys
import pywikibot
from pywikibot import pagegenerators
-from pywikibot import i18n
+from pywikibot.bot import (SingleSiteBot, ExistingPageBot, NoRedirectPageBot,
+ AutomaticTWSummaryBot, suggest_help)
# This is required for the text that is shown when you run this script
# with the parameter -help.
@@ -34,74 +32,49 @@
'¶ms;': pagegenerators.parameterHelp,
}
-featured_articles = {
- 'ar': u'ويكيبيديا:مقالات مختارة',
- 'cs': u'Wikipedie:Nejlepší články',
- 'de': u'Wikipedia:Exzellente_Artikel',
- 'en': u'Wikipedia:Featured_articles',
- 'es': u'Wikipedia:Artículos_destacados',
- 'fa': u'ویکیپدیا:نوشتارهای برگزیده',
- 'fr': u'Wikipédia:Articles_de_qualité',
- 'he': u'פורטל:ערכים_מומלצים',
- 'is': u'Wikipedia:Úrvalsgreinar',
- 'it': u'Wikipedia:Articoli_in_vetrina',
- 'ja': u'Wikipedia:秀逸な記事',
- 'nl': u'Wikipedia:Etalage',
- 'nn': u'Wikipedia:Gode artiklar',
- 'no': u'Wikipedia:Anbefalte artikler',
- 'pl': u'Wikipedia:Artykuły_na_medal',
- 'pt': u'Wikipedia:Os_melhores_artigos',
- 'sv': u'Wikipedia:Utvalda_artiklar',
- 'vi': u'Wikipedia:Bài_viết_chọn_lọc',
- 'zh': u'Wikipedia:特色条目',
-}
+# Featured articles categories
+featured_articles = 'Q4387444'
-pageCache = []
+class FixingRedirectBot(SingleSiteBot, ExistingPageBot, NoRedirectPageBot,
+ AutomaticTWSummaryBot):
+ """Run over pages and resolve redirect links."""
-def workon(page):
- """Change all redirects from the given page to actual links."""
- mysite = pywikibot.Site()
- try:
- text = page.get()
- except pywikibot.IsRedirectPage:
- pywikibot.output(u'%s is a redirect page. Skipping' % page)
- return
- except pywikibot.NoPage:
- pywikibot.output(u'%s does not exist. Skipping' % page)
- return
- pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
- % page.title())
- links = page.linkedPages()
- if links is not None:
- links = pagegenerators.PreloadingGenerator(links)
-# pywikibot.getall(mysite, links)
- else:
- pywikibot.output('Nothing left to do.')
- return
+ ignore_save_related_errors = True
+ ignore_server_errors = True
+ summary_key = 'fixing_redirects-fixing'
- for page2 in links:
- try:
- target = page2.getRedirectTarget()
- except pywikibot.NoPage:
- try:
- target = page2.getMovedTarget()
- except (pywikibot.NoPage, pywikibot.BadTitle):
+ def treat_page(self):
+ """Change all redirects from the current page to actual links."""
+ links = self.current_page.linkedPages()
+ newtext = self.current_page.text
+ i = None
+ for i, page in enumerate(links):
+ if not page.exists():
+ try:
+ target = page.moved_target()
+ except (pywikibot.NoMoveTarget,
+ pywikibot.CircularRedirect,
+ pywikibot.InvalidTitle):
+ continue
+ elif page.isRedirectPage():
+ try:
+ target = page.getRedirectTarget()
+ except (pywikibot.CircularRedirect,
+ pywikibot.InvalidTitle):
+ continue
+ else:
continue
- except (pywikibot.Error, pywikibot.SectionError):
- continue
- # no fix to user namespaces
- if target.namespace() in [0, 1] and not page2.namespace() in [0, 1]:
- continue
- text = pywikibot.textlib.replace_links(text, [page2, target])
- if text != page.get():
- comment = i18n.twtranslate(mysite, 'fixing_redirects-fixing')
- pywikibot.showDiff(page.get(), text)
- try:
- page.put(text, comment)
- except (pywikibot.Error):
- pywikibot.error('unable to put %s' % page)
+ # no fix to user namespaces
+ if target.namespace() in [2, 3] and page.namespace() not in [2, 3]:
+ continue
+ newtext = pywikibot.textlib.replace_links(newtext, [page, target])
+
+ if i is None:
+ pywikibot.output('Nothing left to do.')
+ else:
+ self.put_current(newtext)
def main(*args):
@@ -123,28 +96,41 @@
for arg in local_args:
if arg == '-featured':
featured = True
- else:
- genFactory.handleArg(arg)
+ elif genFactory.handleArg(arg):
+ pass
mysite = pywikibot.Site()
if mysite.sitename() == 'wikipedia:nl':
pywikibot.output(
'\03{lightred}There is consensus on the Dutch Wikipedia that '
'bots should not be used to fix redirects.\03{default}')
- sys.exit()
+ return
if featured:
- featuredList = i18n.translate(mysite, featured_articles)
- ref = pywikibot.Page(pywikibot.Site(), featuredList)
- gen = ref.getReferences(namespaces=[0])
- if not gen:
+ repo = mysite.data_repository()
+ if repo:
+ dp = pywikibot.ItemPage(repo, featured_articles)
+ try:
+ ref = pywikibot.Category(mysite, dp.getSitelink(mysite))
+ except pywikibot.NoPage:
+ pass
+ else:
+ gen = ref.articles(namespaces=0, content=True)
+ if not gen:
+ suggest_help(
+ unknown_parameters=['-featured'],
+ additional_text='Option is not available for this site.')
+ return False
+ else:
gen = genFactory.getCombinedGenerator()
+ if gen:
+ gen = mysite.preloadpages(gen)
if gen:
- for page in pagegenerators.PreloadingGenerator(gen):
- workon(page)
+ bot = FixingRedirectBot(generator=gen)
+ bot.run()
return True
else:
- pywikibot.bot.suggest_help(missing_generator=True)
+ suggest_help(missing_generator=True)
return False
if __name__ == "__main__":
--
To view, visit https://gerrit.wikimedia.org/r/213193
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9c52afe218e20f6ab2ecf41fdaf7934341cd2093
Gerrit-PatchSet: 21
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [COMPAT] Add Page.getRestrictions() from compat
......................................................................
[COMPAT] Add Page.getRestrictions() from compat
getRestictions() was added to compat in 2008. Add it to core for compatibility
purpose and mark it as deprecated.
Change-Id: I6624638c2003d2fe96f783ae7a15c7d61bc60197
---
M pywikibot/page.py
1 file changed, 6 insertions(+), 0 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 278ed54..e82c183 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1965,6 +1965,12 @@
"""
return self.title(asUrl=True)
+ @deprecated('Page.protection()')
+ def getRestrictions(self):
+ """DEPRECATED. Use self.protection() instead."""
+ restrictions = self.protection()
+ return dict((k, list(restrictions[k])) for k in restrictions)
+
# ###### DISABLED METHODS (warnings provided) ######
# these methods are easily replaced by editing the page's text using
# textlib methods and then using put() on the result.
--
To view, visit https://gerrit.wikimedia.org/r/228645
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6624638c2003d2fe96f783ae7a15c7d61bc60197
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Use unittest2 for python <2.7.3
......................................................................
Use unittest2 for python <2.7.3
The unittest lib shipped with Python 2.7.2 has a minor issue and isn't
compatible with Pywikibot due to T106512.
Change-Id: I63baf41ff74d09bff293d325eb08a8a16b414f75
---
M dev-requirements.txt
M setup.py
M tests/__init__.py
3 files changed, 11 insertions(+), 7 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/dev-requirements.txt b/dev-requirements.txt
index ee37c1b..7746b8e 100644
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -1,6 +1,6 @@
# This is a PIP 6+ requirements file for development dependencies
#
-unittest2==0.8.0 ; python_version < '2.7'
+unittest2==0.8.0 ; python_full_version < '2.7.3'
six
diff --git a/setup.py b/setup.py
index 01920d1..0d6ad73 100644
--- a/setup.py
+++ b/setup.py
@@ -92,17 +92,20 @@
'git+https://github.com/nlhepler/pydot#egg=pydot-1.0.29',
]
+if PYTHON_VERSION < (2, 7, 3):
+ # work around distutils hardcoded unittest dependency
+ # work around T106512
+ import unittest # noqa
+ if 'test' in sys.argv:
+ import unittest2
+ sys.modules['unittest'] = unittest2
+
if sys.version_info[0] == 2:
if PY26:
# requests security extra includes pyOpenSSL. cryptography is the
# dependency of pyOpenSSL. 0.8.2 is the newest and compatible version
# for Python 2.6, which won't raise unexpected DeprecationWarning.
extra_deps['security'].append('cryptography<=0.8.2')
- # work around distutils hardcoded unittest dependency
- import unittest # noqa
- if 'test' in sys.argv:
- import unittest2
- sys.modules['unittest'] = unittest2
script_deps['replicate_wiki.py'] = ['argparse']
dependencies.append('future') # provides collections backports
diff --git a/tests/__init__.py b/tests/__init__.py
index df4e368..82757ed 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -27,8 +27,9 @@
print("ImportError: %s" % e)
sys.exit(1)
-if sys.version_info < (2, 7):
+if sys.version_info < (2, 7, 3):
# Unittest2 is a backport of python 2.7s unittest module to python 2.6
+ # Also use unittest2 for python 2.7.2 (T106512)
import unittest2 as unittest
else:
import unittest
--
To view, visit https://gerrit.wikimedia.org/r/229069
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I63baf41ff74d09bff293d325eb08a8a16b414f75
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: VcamX <vcamx3(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(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: flickrapi v2 not usable on Python 2.6
......................................................................
flickrapi v2 not usable on Python 2.6
Bug: T107830
Change-Id: I5e93127323cad53ba2a247e1bd9716f7502cbd44
---
M requirements.txt
M setup.py
2 files changed, 4 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
VcamX: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/requirements.txt b/requirements.txt
index 4410981..f4e1a20 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -66,7 +66,8 @@
# pkg_resources.VersionConflict: (requests 1.2.3 (/usr/lib/python2.7/site-packages), Requirement.parse('requests>=2.2.1'))
# If you see that on Python 2, change this to flickrapi==1.4.5
# On Python 3, force pip to install requests 2.2.1, or remove flickrapi below.
-flickrapi
+flickrapi>=1.4.5,<2 ; python_version < '2.7'
+flickrapi ; python_version >= '2.7'
# incomplete core component botirc
irc ; python_version > '2.6'
diff --git a/setup.py b/setup.py
index 01920d1..6738496 100644
--- a/setup.py
+++ b/setup.py
@@ -73,8 +73,8 @@
# and will be first packaged for Fedora Core 21.
# flickrapi 1.4.x does not run on Python 3, and setuptools can only
# select flickrapi 2.x for Python 3 installs.
-script_deps['flickrripper.py'].append('flickrapi' if sys.version_info[0] > 2
- else 'flickrapi>=1.4.5')
+script_deps['flickrripper.py'].append(
+ 'flickrapi>=1.4.5,<2' if PY26 else 'flickrapi')
# lunatic-python is only available for Linux
if sys.platform.startswith('linux'):
--
To view, visit https://gerrit.wikimedia.org/r/229071
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5e93127323cad53ba2a247e1bd9716f7502cbd44
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: VcamX <vcamx3(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>