jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/372778 )
Change subject: travis.yml: Print the length and type of config.authenticate values
......................................................................
travis.yml: Print the length and type of config.authenticate values
This is a temporary means to help us confirm that authenticate values are
initially set with correct type and format in user-config.py (or not).
Bug: T173498
Change-Id: I7b6f057477ec5793c33e0e5d3bd02a2e0a677e8d
---
M .travis.yml
1 file changed, 1 insertion(+), 0 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/.travis.yml b/.travis.yml
index 1541421..c5a9928 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -90,6 +90,7 @@
fi ;
fi
- echo "authenticate['wiki.musicbrainz.org'] = ('NOTSPAM', 'NOTSPAM')" >> ~/.pywikibot/user-config.py ;
+ - python -c "from __future__ import print_function;from pywikibot import config as c; a=c.authenticate; [(print('authenticate_key:', i), print('authenticate_value_type:', type(a[i])), print('authenticate_value_length:', len(a[i]))) for i in a]" # T173498
- echo "max_retries = 2" >> ~/.pywikibot/user-config.py
- echo "maximum_GET_length = 5000" >> ~/.pywikibot/user-config.py
--
To view, visit https://gerrit.wikimedia.org/r/372778
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7b6f057477ec5793c33e0e5d3bd02a2e0a677e8d
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/371659 )
Change subject: FilePage: add API query&prop=globalusage support
......................................................................
FilePage: add API query&prop=globalusage support
Raise UnknownExtension if GlobalUsage is not installed on wiki.
Bug: T168317
Change-Id: Id634380c2692411611dfe9414f9be2fe42c55c11
---
M pywikibot/page.py
M pywikibot/site.py
M tests/page_tests.py
3 files changed, 68 insertions(+), 0 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 3fbcf79..f815f53 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2693,6 +2693,16 @@
pywikibot.warning('Unsuccesfull request (%s): %s' % (req.status, req.uri))
return False
+ def globalusage(self, total=None):
+ """
+ Iterate all global usage for this page.
+
+ @param total: iterate no more than this number of pages in total
+ @return: a generator that yields Pages also on sites different from
+ self.site.
+ @rtype: generator
+ """
+ return self.site.globalusage(self, total=total)
wrapper = _ModuleDeprecationWrapper(__name__)
wrapper._add_deprecated_attr('ImagePage', FilePage)
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 1debbda..0e5efbd 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -3004,6 +3004,45 @@
)
self._update_page(page, query)
+ @need_extension('Global Usage')
+ def globalusage(self, page, total=None):
+ """Iterate global image usage for a given FilePage.
+
+ @param page: the page to return global image usage for.
+ @type image: FilePage
+ @param total: iterate no more than this number of pages in total.
+ @raises TypeError: input page is not a FilePage.
+ @raises SiteDefinitionError: Site could not be defined for a returned
+ entry in API response.
+ """
+ if not isinstance(page, pywikibot.FilePage):
+ raise TypeError('Page %s must be a FilePage.' % page)
+
+ title = page.title(withSection=False)
+ args = {'titles': title,
+ 'gufilterlocal': False,
+ }
+ query = self._generator(api.PropertyGenerator,
+ type_arg='globalusage',
+ guprop=['url', 'pageid', 'namespace'],
+ total=total, # will set gulimit=total in api,
+ **args)
+
+ self._update_page(page, query)
+
+ for pageitem in query:
+ assert 'globalusage' in pageitem, \
+ "API globalusage response lacks 'globalusage' key"
+ for entry in pageitem['globalusage']:
+ try:
+ gu_site = pywikibot.Site(url=entry['url'])
+ except SiteDefinitionError:
+ pywikibot.warning('Site could not be defined for global'
+ ' usage for {0}: {1}.'.format(page, entry))
+ continue
+ gu_page = pywikibot.Page(gu_site, entry['title'])
+ yield gu_page
+
def loadimageinfo(self, page, history=False,
url_width=None, url_height=None, url_param=None):
"""Load image info from api and save in page attributes.
diff --git a/tests/page_tests.py b/tests/page_tests.py
index 3c74326..9b7377b 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -628,6 +628,25 @@
self.site.loadimageinfo.assert_called_once_with(page, history=True)
+class TestFilePage(DefaultSiteTestCase):
+
+ """Test methods of the FilePage class."""
+
+ family = 'commons'
+ code = 'commons'
+
+ cached = True
+
+ def test_globalusage(self, key):
+ """Test globalusage generator."""
+ page = pywikibot.FilePage(self.site, 'File:Example.jpg')
+ gen = page.globalusage(total=3)
+ pages = list(gen)
+ self.assertEqual(len(pages), 3)
+ self.assertTrue(any(isinstance(p), pywikibot.Page) for p in pages)
+ self.assertTrue(any(p.site != self.site for p in pages))
+
+
class TestPageRepr(TestPageBaseUnicode):
"""Test for Page's repr implementation."""
--
To view, visit https://gerrit.wikimedia.org/r/371659
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id634380c2692411611dfe9414f9be2fe42c55c11
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Multichill <maarten(a)mdammers.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>