jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/513564 )
Change subject: [bugfix] Do not ignore -pattern option in imageharvest.py
......................................................................
[bugfix] Do not ignore -pattern option in imageharvest.py
-pattern option toggles image_url to True.
This must not be overridden in run_bot function.
Also fix the compat's [s]top option to break uploading
which was never reached currently.
Other improvements:
- shorten "if url == '':" to "if not url:"
- shorten assignments to minimum, maximum and basicdec
- use a slice generator for ilinks if image_url is True
instead of filling a list
Bug: T224714
Change-Id: Ie39862b1ae6f35bb5ab952e78c734c1db96ef06c
---
M scripts/imageharvest.py
1 file changed, 32 insertions(+), 43 deletions(-)
Approvals:
Dvorapa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/imageharvest.py b/scripts/imageharvest.py
index cf41dea..8ec9a09 100644
--- a/scripts/imageharvest.py
+++ b/scripts/imageharvest.py
@@ -18,7 +18,7 @@
-justshown Choose _only_ images shown on the page, not those linked
"""
#
-# (C) Pywikibot team, 2004-2018
+# (C) Pywikibot team, 2004-2019
#
# Distributed under the terms of the MIT license.
#
@@ -33,6 +33,7 @@
import pywikibot
+from pywikibot.bot import QuitKeyboardInterrupt
from pywikibot.specialbots import UploadRobot
from pywikibot.tools import PY2
@@ -74,61 +75,49 @@
def run_bot(give_url, image_url, desc):
"""Run the bot."""
url = give_url
- image_url = ''
- if url == '':
+ if not url:
if image_url:
url = pywikibot.input('What URL range should I check '
'(use $ for the part that is changeable)')
else:
url = pywikibot.input('From what URL should I get the images?')
- if image_url:
- minimum = 1
- maximum = 99
- answer = pywikibot.input(
- 'What is the first number to check (default: 1)')
- if answer:
- minimum = int(answer)
- answer = pywikibot.input(
- 'What is the last number to check (default: 99)')
- if answer:
- maximum = int(answer)
-
- if not desc:
- basicdesc = pywikibot.input(
- 'What text should be added at the end of '
- 'the description of each image from this url?')
- else:
- basicdesc = desc
+ basicdesc = desc or pywikibot.input(
+ 'What text should be added at the end of '
+ 'the description of each image from this url?')
if image_url:
- ilinks = []
- i = minimum
- while i <= maximum:
- ilinks += [url.replace('$', str(i))]
- i += 1
+ minimum = int(pywikibot.input(
+ 'What is the first number to check (default: 1)') or 1)
+ maximum = int(pywikibot.input(
+ 'What is the last number to check (default: 99)') or 99)
+ ilinks = (url.replace('$', str(i))
+ for i in range(minimum, maximum + 1))
else:
ilinks = get_imagelinks(url)
for image in ilinks:
- if pywikibot.input_yn('Include image {}?'.format(image), default=False,
- automatic_quit=False):
- desc = pywikibot.input('Give the description of this image:')
- categories = []
- while True:
- cat = pywikibot.input('Specify a category (or press enter to '
- 'end adding categories)')
- if not cat.strip():
- break
- if ':' in cat:
- categories.append('[[{}]]'.format(cat))
- else:
- categories.append('[[{}:{}]]'
- .format(mysite.namespace(14), cat))
- desc += '\n\n' + basicdesc + '\n\n' + '\n'.join(categories)
- UploadRobot(image, description=desc).run()
- elif answer == 's':
+ try:
+ include = pywikibot.input_yn('Include image {}?'.format(image),
+ default=False)
+ except QuitKeyboardInterrupt:
break
+ if not include:
+ continue
+ desc = pywikibot.input('Give the description of this image:')
+ categories = []
+ while True:
+ cat = pywikibot.input('Specify a category (or press enter to '
+ 'end adding categories)')
+ if not cat.strip():
+ break
+ if ':' in cat:
+ categories.append('[[{}]]'.format(cat))
+ else:
+ categories.append('[[{}:{}]]'
+ .format(mysite.namespace(14), cat))
+ desc += '\n\n' + basicdesc + '\n\n' + '\n'.join(categories)
+ UploadRobot(image, description=desc).run()
def main(*args):
--
To view, visit https://gerrit.wikimedia.org/r/513564
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie39862b1ae6f35bb5ab952e78c734c1db96ef06c
Gerrit-Change-Number: 513564
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/513316 )
Change subject: [tests] Fix similar code checking in codeclimate
......................................................................
[tests] Fix similar code checking in codeclimate
similar-code threshold describes the mass code block to be
analyzed for duplication. This was mistakenly decreased from
default 32 to 2. The count threshold should be increased
instead.
Refer https://github.com/codeclimate/codeclimate-duplication
for this settings
Change-Id: Idec34f3d3571d81ea9544dd20c398c580ead3625
---
M .codeclimate.yml
1 file changed, 5 insertions(+), 2 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.codeclimate.yml b/.codeclimate.yml
index d671f0f..2b6b811 100644
--- a/.codeclimate.yml
+++ b/.codeclimate.yml
@@ -13,9 +13,12 @@
method-lines:
config:
threshold: 30
- similar-code:
+
+plugins:
+ duplication:
+ enabled: true
config:
- threshold: 3
+ count_threshold: 3
exclude_patterns:
- "docs/"
--
To view, visit https://gerrit.wikimedia.org/r/513316
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Idec34f3d3571d81ea9544dd20c398c580ead3625
Gerrit-Change-Number: 513316
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/513544 )
Change subject: [docs] Add @rtype for Page.getReferences and related methods
......................................................................
[docs] Add @rtype for Page.getReferences and related methods
Page.getReferences, APISite.pagebacklinks, APISite.pagereferences,
and APISite.page_embeddedin return an iterable of page objects.
Also explicitly use typing.Iterable instead of Iterable so that it won't
be confused with collections.abc.Iterable (which does not support
__getitem__ protocol).
Replace pywikibot.APISite which does not exist with
pywikibot.site.APISite.
+ Other minor changes.
Change-Id: Ic1aaa6b18300465c7158f6bc00a04bbe24696a93
---
M pywikibot/page.py
M pywikibot/site.py
M pywikibot/textlib.py
M tests/aspects.py
4 files changed, 19 insertions(+), 15 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index b7f2dbc..97edd3b 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -917,7 +917,7 @@
not actually exist on the wiki.
@return: Page or None if self is a special page.
- @rtype: Page or None
+ @rtype: typing.Optional[pywikibot.Page]
"""
ns = self.namespace()
if ns < 0: # Special page
@@ -1039,6 +1039,7 @@
@param total: iterate no more than this number of pages in total
@param content: if True, retrieve the content of the current version
of each referring page (default False)
+ @rtype: typing.Iterable[pywikibot.Page]
"""
# N.B.: this method intentionally overlaps with backlinks() and
# embeddedin(). Depending on the interface, it may be more efficient
@@ -3417,7 +3418,7 @@
page title (optional)
@type subpage: str
@return: Page object of user page or user subpage
- @rtype: Page
+ @rtype: pywikibot.Page
"""
if self._isAutoblock:
# This user is probably being queried for purpose of lifting
@@ -3436,7 +3437,7 @@
talk page title (optional)
@type subpage: str
@return: Page object of user talk page or user talk subpage
- @rtype: Page
+ @rtype: pywikibot.Page
"""
if self._isAutoblock:
# This user is probably being queried for purpose of lifting
diff --git a/pywikibot/site.py b/pywikibot/site.py
index d074b6c..388964c 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1878,9 +1878,9 @@
@param dbname: database name
@type dbname: str
@param site: Site to load sitematrix from. (Default meta.wikimedia.org)
- @type site: APISite
+ @type site: pywikibot.site.APISite
@return: site object for the database name
- @rtype: APISite
+ @rtype: pywikibot.site.APISite
"""
# TODO this only works for some WMF sites
if not site:
@@ -3652,6 +3652,7 @@
@param total: Maximum number of pages to retrieve in total.
@param content: if True, load the current content of each iterated page
(default False)
+ @rtype: typing.Iterable[pywikibot.Page]
@raises KeyError: a namespace identifier was not resolved
@raises TypeError: a namespace identifier has an inappropriate
type such as NoneType or bool
@@ -3711,6 +3712,7 @@
list of namespace identifiers.
@param content: if True, load the current content of each iterated page
(default False)
+ @rtype: typing.Iterable[pywikibot.Page]
@raises KeyError: a namespace identifier was not resolved
@raises TypeError: a namespace identifier has an inappropriate
type such as NoneType or bool
@@ -3742,6 +3744,7 @@
@type namespaces: iterable of basestring or Namespace key,
or a single instance of those types. May be a '|' separated
list of namespace identifiers.
+ @rtype: typing.Iterable[pywikibot.Page]
@raises KeyError: a namespace identifier was not resolved
@raises TypeError: a namespace identifier has an inappropriate
type such as NoneType or bool
@@ -6905,7 +6908,7 @@
shows all protection levels.
@type level: str or False
@return: The pages which are protected.
- @rtype: Iterable[pywikibot.Page]
+ @rtype: typing.Iterable[pywikibot.Page]
"""
namespaces = self.namespaces.resolve(namespace)
# always assert that, so we are be sure that type could be 'create'
@@ -7028,7 +7031,7 @@
@type lint_from: str representing digit or integer
@return: pages with Linter errors.
- @rtype: Iterable[pywikibot.Page]
+ @rtype: typing.Iterable[pywikibot.Page]
"""
query = self._generator(api.ListGenerator, type_arg='linterrors',
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index b0ee716..d92bc93 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -644,7 +644,7 @@
callable
@param site: a Site object to use. It should match the origin
or target site of the text
- @type site: pywikibot.APISite
+ @type site: pywikibot.site.APISite
"""
def to_link(source):
"""Return the link from source when it's a Page otherwise itself."""
diff --git a/tests/aspects.py b/tests/aspects.py
index 09e817e..4d7e6bc 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -183,11 +183,11 @@
if additional items are in the iterator.
@param gen: Page generator
- @type gen: Iterable[pywikibot.BasePage]
+ @type gen: typing.Iterable[pywikibot.Page]
@param count: number of pages to get
@type count: int
@param site: Site of expected pages
- @type site: pywikibot.APISite
+ @type site: pywikibot.site.APISite
"""
original_iter = iter(gen)
@@ -271,11 +271,11 @@
Only iterates to the length of titles plus two.
@param gen: Page generator
- @type gen: Iterable[pywikibot.BasePage]
+ @type gen: typing.Iterable[pywikibot.Page]
@param titles: Expected titles
@type titles: iterator
@param site: Site of expected pages
- @type site: pywikibot.APISite
+ @type site: pywikibot.site.APISite
"""
titles = self._get_canonical_titles(titles, site)
gen_titles = self._get_gen_titles(gen, len(titles), site)
@@ -288,11 +288,11 @@
Only iterates to the length of titles plus two.
@param gen: Page generator
- @type gen: Iterable[pywikibot.BasePage]
+ @type gen: typing.Iterable[pywikibot.Page]
@param titles: Expected titles
@type titles: iterator
@param site: Site of expected pages
- @type site: pywikibot.APISite
+ @type site: pywikibot.site.APISite
"""
titles = self._get_canonical_titles(titles, site)
gen_titles = self._get_gen_titles(gen, len(titles), site)
@@ -1065,7 +1065,7 @@
"""Create a Page object for the sites main page.
@param site: Override current site, obtained using L{get_site}.
- @type site: pywikibot.APISite or None
+ @type site: pywikibot.site.APISite or None
@param force: Get an unused Page object
@type force: bool
@rtype: pywikibot.Page
--
To view, visit https://gerrit.wikimedia.org/r/513544
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic1aaa6b18300465c7158f6bc00a04bbe24696a93
Gerrit-Change-Number: 513544
Gerrit-PatchSet: 1
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/497101 )
Change subject: [tests] Give a better failure message for paraminfo_tests
......................................................................
[tests] Give a better failure message for paraminfo_tests
Currently we get an assertion error listing two sets when the first set
is not greater or equal than the second.
Now calculate the difference which values are in the second and not
in the first set as expected.
This is an improvement to detect the missing parameter in the first.
Bug: T218506
Change-Id: Ibcdffd5050c136805d48bf5dddd67011d81d84d7
---
M tests/paraminfo_tests.py
1 file changed, 6 insertions(+), 1 deletion(-)
Approvals:
Dvorapa: Looks good to me, but someone else must approve
Lokal Profil: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/paraminfo_tests.py b/tests/paraminfo_tests.py
index 8ae81d0..63e501a 100644
--- a/tests/paraminfo_tests.py
+++ b/tests/paraminfo_tests.py
@@ -49,7 +49,12 @@
def _check_param_superset(self, site, module, parameter, expected):
"""Check that a parameter only contains entries in expected list."""
values = self._get_param_values(site, module, parameter)
- self.assertGreaterEqual(set(expected), set(values))
+ exp = set(expected)
+ val = set(values)
+ if not exp.issuperset(val):
+ diff = val - exp
+ self.fail('Unexpected param{} {} in values'
+ .format('s' if len(diff) > 1 else '', diff))
class MediaWikiKnownTypesTestCase(KnownTypesTestBase,
--
To view, visit https://gerrit.wikimedia.org/r/497101
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibcdffd5050c136805d48bf5dddd67011d81d84d7
Gerrit-Change-Number: 497101
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Lokal Profil <andre.costa(a)wikimedia.se>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/503736 )
Change subject: [bugfix] Show page list at the end of the script
......................................................................
[bugfix] Show page list at the end of the script
With -get option the page content is printed after the page title
but complete title list is not printed in this case.
Bug: T220905
Change-Id: I65bb48d733cb92864694b9180d5e040a19cb6b98
---
M scripts/listpages.py
1 file changed, 6 insertions(+), 3 deletions(-)
Approvals:
Dvorapa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/listpages.py b/scripts/listpages.py
index 1ec6268..1292c20 100755
--- a/scripts/listpages.py
+++ b/scripts/listpages.py
@@ -259,8 +259,9 @@
if not notitle:
page_fmt = Formatter(page, outputlang)
output_list += [page_fmt.output(num=i, fmt=fmt)]
- pywikibot.stdout(output_list[-1])
if page_get:
+ if output_list:
+ pywikibot.stdout(output_list.pop(-1))
try:
pywikibot.stdout(page.text)
except pywikibot.Error as err:
@@ -271,10 +272,12 @@
.format(page.title(), filename))
with open(filename, mode='wb') as f:
f.write(page.text.encode(encoding))
- pywikibot.output('{0} page(s) found'.format(i))
+ text = '\n'.join(output_list)
if page_target:
- page_target.text = '\n'.join(output_list)
+ page_target.text = text
page_target.save(summary=summary)
+ pywikibot.stdout(text)
+ pywikibot.output('{0} page(s) found'.format(i))
return True
else:
pywikibot.bot.suggest_help(missing_generator=True)
--
To view, visit https://gerrit.wikimedia.org/r/503736
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I65bb48d733cb92864694b9180d5e040a19cb6b98
Gerrit-Change-Number: 503736
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/513305 )
Change subject: Revert "A BaseSite subclass for non MW sites."
......................................................................
Revert "A BaseSite subclass for non MW sites."
A Site that does nothing except raising exceptions
is not an appropriate implementation. Refer PEP20:
Now is better than never.
Although never is often better than *right* now.
Pretty sure the last fits here since 4 years
This reverts commit 46a3a8525e59218c371af7f77366ed831427b7f4.
Change-Id: Idfe3add9d80a10cde060fbbb4273a1df004a6525
---
M pywikibot/site.py
M tests/site_tests.py
2 files changed, 0 insertions(+), 40 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index d074b6c..47ccc63 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1820,25 +1820,6 @@
super(RemovedSite, self).__init__(code, fam, user, sysop)
-class NonMWAPISite(BaseSite):
-
- """API interface to non MediaWiki sites."""
-
- def __init__(self, url):
- """Initializer."""
- self.netloc = urlparse(url).netloc
-
- def __getattribute__(self, attr):
- """Return attribute if present else raise NotImplementedError."""
- whitelist = ['__getattribute__', 'netloc']
- if attr in whitelist:
- return super(NonMWAPISite, self).__getattribute__(attr)
- else:
- raise NotImplementedError('The attribute %s has not been on '
- 'site %s implemented yet.'
- % (attr, self.netloc))
-
-
class APISite(BaseSite):
"""
diff --git a/tests/site_tests.py b/tests/site_tests.py
index dd8f68f..d4baea1 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -3531,27 +3531,6 @@
pywikibot.Site, 'en', 'wikidata')
-class TestNonMWAPISite(TestCase):
-
- """Test the BaseSite subclass, site.NonMWAPISite."""
-
- net = False
-
- def test_non_mw_sites(self):
- """Test NonMWAPISite for sites not using MediaWiki."""
- self._run_test('http://moinmo.in/$1')
- self._run_test('http://twiki.org/cgi-bin/view/$1')
- self._run_test('http://www.usemod.com/cgi-bin/wiki.pl?$1')
- self._run_test('https://developer.mozilla.org/en/docs/$1')
- self._run_test('http://www.tvtropes.org/pmwiki/pmwiki.php/Main/$1')
-
- def _run_test(self, url):
- """Run test method."""
- site = pywikibot.site.NonMWAPISite(url)
- with self.assertRaises(NotImplementedError):
- site.attr
-
-
class TestSiteProofreadinfo(DefaultSiteTestCase):
"""Test proofreadinfo information."""
--
To view, visit https://gerrit.wikimedia.org/r/513305
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Idfe3add9d80a10cde060fbbb4273a1df004a6525
Gerrit-Change-Number: 513305
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <Ladsgroup(a)gmail.com>
Gerrit-Reviewer: Maverick <manpreetkaur9411(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)