jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/341995 )
Change subject: Add -property option to pagegenerators.py
......................................................................
Add -property option to pagegenerators.py
- new -property option for pagegenerators.py
- ask for a poperty name or show the whole list when "?" no input (default)
is given or the given property name was invalid
- test the new option with GeneratorFactory
- rename _get_property_names to get_property_names which is no longer
a helper function for site.pages_with_property method
Change-Id: Ib128f197f2b43d00ea2ad1846a3d1788ad936abe
---
M pywikibot/pagegenerators.py
M pywikibot/site.py
M tests/pagegenerators_tests.py
M tests/site_tests.py
4 files changed, 63 insertions(+), 6 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 98ed579..e344976 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -50,6 +50,7 @@
)
from pywikibot import date, config, i18n, xmlreader
+from pywikibot.bot import ListOption
from pywikibot.comms import http
from pywikibot.exceptions import ArgumentDeprecationWarning, UnknownExtension
from pywikibot.logentries import LogEntryFactory
@@ -246,6 +247,9 @@
-unwatched Work on all articles that are not watched by anyone.
Argument can be given as "-unwatched:n" where
n is the maximum number of articles to work on.
+
+-property:name Work on all pages with a given propery name from
+ Special:PagesWithProp.
-usercontribs Work on all articles that were edited by a certain user.
(Example : -usercontribs:DumZiBoT)
@@ -661,6 +665,20 @@
elif arg == '-unwatched':
gen = UnwatchedPagesPageGenerator(total=intNone(value),
site=self.site)
+ elif arg == '-property':
+ if not value:
+ question = 'Which property name to be used?'
+ value = pywikibot.input(question + ' (List [?])')
+ pnames = self.site.get_property_names()
+ # also use the default by <enter> key
+ if value in '?' or value not in pnames:
+ for i, item in enumerate(pnames, start=1):
+ pywikibot.output(
+ '{0:{1}}: {2}'.format(i, len(str(len(pnames))),
+ item))
+ prefix, value = pywikibot.input_choice(
+ question, ListOption(self.site.get_property_names()))
+ gen = page_with_property_generator(value, site=self.site)
elif arg == '-usercontribs':
gen = UserContributionsGenerator(value)
elif arg == '-withoutinterwiki':
@@ -2168,6 +2186,22 @@
yield page
+def page_with_property_generator(name, total=None, site=None):
+ """
+ Special:PagesWithProperty page generator.
+
+ @param name: Property name of pages to be retrieved
+ @type name: str
+ @param total: Maximum number of pages to retrieve in total
+ @type total: int
+ @param site: Site for generator results.
+ @type site: L{pywikibot.site.BaseSite}
+ """
+ if site is None:
+ site = pywikibot.Site()
+ return site.pages_with_property(name, total=total)
+
+
def WantedPagesPageGenerator(total=100, site=None):
"""
Wanted page generator.
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 0ee4981..28643e1 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -6584,7 +6584,7 @@
protect_type=type, total=total)
@need_version('1.21')
- def _get_property_names(self, force=False):
+ def get_property_names(self, force=False):
"""
Get property names for pages_with_property().
@@ -6607,9 +6607,9 @@
@return: return a generator of Page objects
@rtype: iterator
"""
- if propname not in self._get_property_names():
+ if propname not in self.get_property_names():
raise NotImplementedError(
- '{0} is not a valid page property'.format(propname))
+ '"{0}" is not a valid page property'.format(propname))
pwpgen = self._generator(api.PageGenerator,
type_arg='pageswithprop',
gpwppropname=propname,
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index 389c6ae..50628bd 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -1021,6 +1021,29 @@
self.assertIsNotNone(gen)
self.assertPagesInNamespaces(gen, set([1, 3]))
+ def test_pages_with_property_generator(self):
+ """Test the pages_with_property_generator method."""
+ mysite = self.get_site()
+ for item in ('defaultsort', 'disambiguation', 'displaytitle',
+ 'hiddencat', 'invalid_property'):
+ if item in mysite.get_property_names():
+ gf = pagegenerators.GeneratorFactory()
+ gf.handleArg('-property:{0}'.format(item))
+ gf.handleArg('-limit:10')
+ gen = gf.getCombinedGenerator()
+ self.assertIsNotNone(gen)
+ pages = list(gen)
+ self.assertLessEqual(len(pages), 10)
+ for page in pages:
+ self.assertIsInstance(page, pywikibot.Page)
+ if item == 'disambiguation':
+ self.assertTrue(page.isDisambig())
+ else:
+ with self.assertRaises(NotImplementedError):
+ mysite.pages_with_property(item)
+ self.fail(
+ 'NotImplementedError not raised for {0}'.format(item))
+
def test_empty_generator(self):
"""Test empty generator."""
gf = pagegenerators.GeneratorFactory(site=self.site)
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 1b2030e..5b9c4eb 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -1000,7 +1000,7 @@
if MediaWikiVersion(self.site.version()) < MediaWikiVersion('1.21'):
raise unittest.SkipTest('requires v1.21+')
mysite = self.get_site()
- pnames = mysite._get_property_names()
+ pnames = mysite.get_property_names()
for item in ('defaultsort', 'disambiguation', 'displaytitle',
'hiddencat', 'invalid_property'):
if item in pnames:
@@ -3328,9 +3328,9 @@
cached = True
def test_get_property_names(self, key):
- """Test _get_property_names method."""
+ """Test get_property_names method."""
mysite = self.get_site(key)
- pnames = mysite._get_property_names()
+ pnames = mysite.get_property_names()
self.assertIsInstance(pnames, list)
for item in ('defaultsort', 'disambiguation', 'displaytitle',
'forcetoc', 'graph_specs', 'hiddencat', 'newsectionlink',
--
To view, visit https://gerrit.wikimedia.org/r/341995
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib128f197f2b43d00ea2ad1846a3d1788ad936abe
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(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/342122 )
Change subject: Fix logging in python3 when deprecated_args decorator is used
......................................................................
Fix logging in python3 when deprecated_args decorator is used
Remove check on record path, which was failing in python 3.
Remove special treatment between python 2 and 3, leaving the default
behaviour for each version.
Logging out put is slightly different in python 3.6 with respect to the
others, as record.pathname is warnings.py.
Leave indication of original caller module:linenno in message.
Bug: T159077
Change-Id: I0c13551406e709d0082874d383962fd514dcae99
---
M pywikibot/tools/_logging.py
1 file changed, 0 insertions(+), 12 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/tools/_logging.py b/pywikibot/tools/_logging.py
index 55d4c7d..b318281 100644
--- a/pywikibot/tools/_logging.py
+++ b/pywikibot/tools/_logging.py
@@ -72,27 +72,15 @@
"""Strip trailing newlines before outputting text to file."""
# Warnings captured from the warnings system are not processed by
# logoutput(), so the 'context' variables are missing.
- # The same context details are provided by Python 3.X, but need to
- # be extracted from the warning message for Python <= 2.7.
if record.name == 'py.warnings' and 'caller_file' not in record.__dict__:
assert len(record.args) == 1, \
'Arguments for record is not correctly set'
msg = record.args[0]
- if PY2:
- record.pathname = msg.partition(':')[0]
- record.lineno = msg.partition(':')[2].partition(':')[0]
- record.module = msg.rpartition('/')[2].rpartition('.')[0]
- else:
- assert msg.startswith(record.pathname + ':'), \
- 'Record argument should start with path'
-
record.__dict__['caller_file'] = record.pathname
record.__dict__['caller_name'] = record.module
record.__dict__['caller_line'] = record.lineno
- # Remove the path and the line number, and strip the extra space
- msg = msg.partition(':')[2].partition(':')[2].lstrip()
record.args = (msg,)
text = logging.handlers.RotatingFileHandler.format(self, record)
--
To view, visit https://gerrit.wikimedia.org/r/342122
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0c13551406e709d0082874d383962fd514dcae99
Gerrit-PatchSet: 1
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: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(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/342193 )
Change subject: api.py: Fix typo in ListGenerator docstring
......................................................................
api.py: Fix typo in ListGenerator docstring
side-wide -> site-wide
Change-Id: I69e1614f188e72795d0f25fd328bb08e2be2c918
---
M pywikibot/data/api.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 4b251eb..9030e4b 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -2957,7 +2957,7 @@
"""Iterator for queries of type action=query&list=foo.
See the API documentation for types of lists that can be queried. Lists
- include both side-wide information (such as 'allpages') and page-specific
+ include both site-wide information (such as 'allpages') and page-specific
information (such as 'backlinks').
This iterator yields a dict object for each member of the list returned
--
To view, visit https://gerrit.wikimedia.org/r/342193
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I69e1614f188e72795d0f25fd328bb08e2be2c918
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/342172 )
Change subject: test_allpages_langlinks_enabled: Use project namespace instead of main
......................................................................
test_allpages_langlinks_enabled: Use project namespace instead of main
Pages on the main namespace of wikidata have no language links, therefore
the test timeouts there. Use project namespace (4) instead of the
main (default) to resolve the issue.
Bug: T160148
Change-Id: Ia1a2445f907557aca76c505e74095d881c50069f
---
M tests/site_tests.py
1 file changed, 3 insertions(+), 2 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/tests/site_tests.py b/tests/site_tests.py
index c4f1675..69e967c 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -605,10 +605,11 @@
def test_allpages_langlinks_enabled(self):
"""Test allpages with langlinks enabled."""
mysite = self.get_site()
- for page in mysite.allpages(filterlanglinks=True, total=5):
+ for page in mysite.allpages(
+ filterlanglinks=True, total=3, namespace=4):
self.assertIsInstance(page, pywikibot.Page)
self.assertTrue(mysite.page_exists(page))
- self.assertEqual(page.namespace(), 0)
+ self.assertEqual(page.namespace(), 4)
self.assertNotEqual(page.langlinks(), [])
def test_allpages_langlinks_disabled(self):
--
To view, visit https://gerrit.wikimedia.org/r/342172
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia1a2445f907557aca76c505e74095d881c50069f
Gerrit-PatchSet: 2
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 <>