Build Update for wikimedia/pywikibot-core
-------------------------------------
Build: #1800
Status: Failed
Duration: 32 minutes and 59 seconds
Commit: 463adf6 (master)
Author: Ricordisamoa
Message: override ItemPage.getRedirectTarget()
* Added 'ns' argument to ItemPage.__init__()
defaulting to the site's item_namespace;
* Expanded docstring of APISite.getredirtarget();
* Added a line to wikibase_tests.py.
Change-Id: I571490fddfe426efc83fde655031a3b40676b327
View the changeset: https://github.com/wikimedia/pywikibot-core/compare/839910d4d853...463adf6b…
View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/44054202
--
You can configure recipients for build notifications in your .travis.yml file. See http://docs.travis-ci.com/user/notifications
jenkins-bot has submitted this change and it was merged.
Change subject: override ItemPage.getRedirectTarget()
......................................................................
override ItemPage.getRedirectTarget()
* Added 'ns' argument to ItemPage.__init__()
defaulting to the site's item_namespace;
* Expanded docstring of APISite.getredirtarget();
* Added a line to wikibase_tests.py.
Change-Id: I571490fddfe426efc83fde655031a3b40676b327
---
M pywikibot/page.py
M pywikibot/site.py
M tests/wikibase_tests.py
3 files changed, 32 insertions(+), 5 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 08eddc3..2853387 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3089,7 +3089,7 @@
been looked up, the item is then defined by the qid.
"""
- def __init__(self, site, title=None):
+ def __init__(self, site, title=None, ns=None):
"""
Constructor.
@@ -3098,15 +3098,19 @@
@param title: id number of item, "Q###",
-1 or None for an empty item.
@type title: str
+ @type ns: namespace
+ @type ns: Namespace instance, or int, or None
+ for default item_namespace
"""
+ if ns is None:
+ ns = site.item_namespace
# Special case for empty item.
if title is None or title == '-1':
- super(ItemPage, self).__init__(site, u'-1', ns=site.item_namespace)
+ super(ItemPage, self).__init__(site, u'-1', ns=ns)
self.id = u'-1'
return
- super(ItemPage, self).__init__(site, title,
- ns=site.item_namespace)
+ super(ItemPage, self).__init__(site, title, ns=ns)
# Link.__init__, called from Page.__init__, has cleaned the title
# stripping whitespace and uppercasing the first letter according
@@ -3223,6 +3227,15 @@
'claims': self.claims
}
+ def getRedirectTarget(self):
+ target = super(ItemPage, self).getRedirectTarget()
+ cmodel = target.content_model
+ if cmodel != 'wikibase-item':
+ raise pywikibot.Error(u'%s has redirect target %s with content '
+ u'model %s instead of wikibase-item' %
+ (self, target, cmodel))
+ return self.__class__(target.site, target.title(), target.namespace())
+
def toJSON(self, diffto=None):
data = super(ItemPage, self).toJSON(diffto=diffto)
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 3a994c3..16fe681 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -2364,7 +2364,20 @@
return page._isredir
def getredirtarget(self, page):
- """Return Page object for the redirect target of page."""
+ """
+ Return page object for the redirect target of page.
+
+ @param page: page to search redirects for
+ @type page: BasePage
+ @return: redirect target of page
+ @rtype: BasePage
+
+ @raise IsNotRedirectPage: page is not a redirect
+ @raise RuntimeError: no redirects found
+ @raise CircularRedirect: page is a circular redirect
+ @raise InterwikiRedirectPage: the redirect target is
+ on another site
+ """
if not self.page_isredirect(page):
raise IsNotRedirectPage(page)
if hasattr(page, '_redirtarget'):
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index caf3b30..c07a03f 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -464,6 +464,7 @@
target = pywikibot.ItemPage(wikidata, 'Q8422626')
self.assertTrue(item.isRedirectPage())
self.assertEqual(item.getRedirectTarget(), target)
+ self.assertIsInstance(item.getRedirectTarget(), pywikibot.ItemPage)
class TestPropertyPage(WikidataTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/178796
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I571490fddfe426efc83fde655031a3b40676b327
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)openmailbox.org>
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: 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: [IMPROV] Pagegens: Use -logevents instead of -*log
......................................................................
[IMPROV] Pagegens: Use -logevents instead of -*log
With a887aff93c0aa0859a93cac1e57f4738de59787e the LogeventsPageGenerator
was introduced which uses the -*log notation from compat (e.g. -movelog)
but it's not feasable to support this with the upcoming argparse patch,
because it doesn't allow such dynamic arguments.
This is a replacement so that when the argparse patch lands, that the
users hopefully haven't used the old notation. Instead of semicolons
it's using normal commas which are safer to use on the bash (just the
new notation). It also does only allow positive integers as a total
value (both notations).
Change-Id: If6c24333ea892386203dc9a4affff289ef7f05eb
---
M pywikibot/pagegenerators.py
1 file changed, 59 insertions(+), 23 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index e5c0e31..1e30a03 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -87,18 +87,22 @@
-search Work on all pages that are found in a MediaWiki search
across all namespaces.
--<logevent>log Work on articles that were on a specified special:log.
+-logevents Work on articles that were on a specified Special:Log.
+ The value may be a comma separated list of three values:
+ logevent,username,total
+ To use the default value, use an empty string.
You have options for every type of logs given by the
- <logevent> parameter which could be one of the following:
+ log event parameter which could be one of the following:
block, protect, rights, delete, upload, move, import,
patrol, merge, suppress, review, stable, gblblock,
renameuser, globalauth, gblrights, abusefilter, newusers
+ It uses the default number of pages 10.
Examples:
- -movelog gives 500 pages from move log (should be redirects)
- -deletelog:10 gives 10 pages from deletion log
- -protect:Dummy gives 500 pages from protect by user Dummy
- -patrol:Dummy;20 gives 20 pages patroled by user Dummy
- In some cases this must be written as -patrol:"Dummy;20"
+ -logevents:move gives pages from move log (should be redirects)
+ -logevents:delete,,20 gives 20 pages from deletion log
+ -logevents:protect,Usr gives pages from protect by user Usr
+ -logevents:patrol,Usr,20 gives 20 patroled pages by user Usr
+ In some cases it must be written as -logevents:"patrol,Usr,20"
-namespaces Filter the page generator to only yield pages in the
-namespace specified namespaces. Separate multiple namespace
@@ -344,6 +348,35 @@
start=startfrom,
recurse=recurse,
content=content)
+
+ def _parse_log_events(self, logtype, user=None, total=None):
+ """
+ Parse the -logevent argument information.
+
+ @param logtype: A valid logtype
+ @type logtype: str
+ @param user: A username associated to the log events. Ignored if
+ empty string or None.
+ @type user: str
+ @param total: The total amount of pages returned.
+ @type total: str (castable to int) or int (positive)
+ @return: The generator or None if invalid 'total' value.
+ @rtype: LogeventsPageGenerator
+ """
+ # TODO: Check if logtype is one of the allowed log types
+ # TODO: -*log used 500 as default total, also use with -logevents?
+ if total is not None:
+ try:
+ total = int(total)
+ if total <= 0:
+ raise ValueError
+ except ValueError:
+ pywikibot.error(u'Total number of log ({0}) events must be a '
+ 'positive int.'.format(total))
+ return None
+ # 'user or None', because user might be an empty string when
+ # 'foo,,bar' was used.
+ return LogeventsPageGenerator(logtype, user or None, total=total)
def handleArg(self, arg):
"""Parse one argument at a time.
@@ -609,29 +642,32 @@
elif arg.startswith('-intersect'):
self.intersect = True
return True
+ elif arg.startswith('-logevents:'):
+ gen = self._parse_log_events(*arg[len('-logevents:'):].split(','))
elif arg.startswith('-'):
mode, log, user = arg.partition('log')
# exclude -log, -nolog
if log == 'log' and mode not in ['-', '-no']:
+ mode = mode[1:]
+ user = user[1:]
total = 500
- if not user:
- user = None
- else:
+ if user:
try:
- total = int(user[1:])
+ total = int(user)
+ except:
+ params = user.split(';')
+ if len(params) == 2:
+ user, total = params
+ else:
+ user = params[0]
+ else:
user = None
- except ValueError:
- user = user[1:]
- result = user.split(';')
- user = result[0]
- try:
- total = int(result[1])
- except (ValueError, IndexError):
- pywikibot.error(
- u'Value specified after ";" not an int.')
- return False
- # TODO: Check if mode[1:] is one of the allowed log types
- gen = LogeventsPageGenerator(mode[1:], user, total=total)
+ else:
+ user = None
+ pywikibot.warning(u'The usage of "{0}" is discouraged. Use '
+ '-logevents "{1}" instead.'.format(
+ arg, ','.join((mode, user or '', str(total)))))
+ gen = self._parse_log_events(mode, user, total)
if gen:
self.gens.append(gen)
--
To view, visit https://gerrit.wikimedia.org/r/179126
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If6c24333ea892386203dc9a4affff289ef7f05eb
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.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 <>