jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] TokenWallet: Assert a username
......................................................................
[FIX] TokenWallet: Assert a username
The TokenWallet assumed the normal user and not the sysopuser is logged
in. This worked as long as both are named the same, but if a sysopuser
is logged in with a name different from the normal username, it'll fail
and tell that the normal user is not logged in.
It now just checks whether a user is logged in, which is also what the
next statement requires.
Bug: 72238
Change-Id: Iccce554b5c9e83a42ae87c0bd69e38f880e3f6ac
---
M pywikibot/site.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index d7727c0..660f9a1 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1276,7 +1276,7 @@
self.failed_cache.add((self.site.user(), key))
def __getitem__(self, key):
- assert(self.site.logged_in())
+ assert(self.site.user())
user_tokens = self._tokens.setdefault(self.site.user(), {})
# always preload all for users without tokens
--
To view, visit https://gerrit.wikimedia.org/r/167452
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iccce554b5c9e83a42ae87c0bd69e38f880e3f6ac
Gerrit-PatchSet: 1
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: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Fix harvest_template.py
......................................................................
Fix harvest_template.py
Broken by 806a5f2
Bug: 71699
Change-Id: I1c36907b7a7de3a952ec812fef505c8a38f4b187
---
M scripts/harvest_template.py
1 file changed, 47 insertions(+), 47 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
Multichill: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index cdb1275..13ce7cf 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -122,62 +122,62 @@
ns=10).title(withNamespace=False)
except pywikibot.exceptions.InvalidTitle:
pywikibot.error(u"Failed parsing template; '%s' should be the template name." % template)
- return
+ continue
# We found the template we were looking for
if template in self.templateTitles:
for field, value in fielddict.items():
field = field.strip()
value = value.strip()
if not field or not value:
- return
+ continue
- # This field contains something useful for us
- if field in self.fields:
- # Check if the property isn't already set
- claim = pywikibot.Claim(self.repo, self.fields[field])
- if claim.getID() in item.get().get('claims'):
- pywikibot.output(
- u'A claim for %s already exists. Skipping'
- % claim.getID())
- # TODO: Implement smarter approach to merging
- # harvested values with existing claims esp.
- # without overwriting humans unintentionally.
+ # This field contains something useful for us
+ if field in self.fields:
+ # Check if the property isn't already set
+ claim = pywikibot.Claim(self.repo, self.fields[field])
+ if claim.getID() in item.get().get('claims'):
+ pywikibot.output(
+ u'A claim for %s already exists. Skipping'
+ % claim.getID())
+ # TODO: Implement smarter approach to merging
+ # harvested values with existing claims esp.
+ # without overwriting humans unintentionally.
+ else:
+ if claim.type == 'wikibase-item':
+ # Try to extract a valid page
+ match = re.search(pywikibot.link_regex, value)
+ if not match:
+ pywikibot.output(u'%s field %s value %s isnt a wikilink. Skipping' % (claim.getID(), field, value))
+ continue
+
+ link_text = match.group(1)
+ linked_item = self._template_link_target(item, link_text)
+ if not linked_item:
+ continue
+
+ claim.setTarget(linked_item)
+ elif claim.type == 'string':
+ claim.setTarget(value.strip())
+ elif claim.type == 'commonsMedia':
+ commonssite = pywikibot.Site("commons", "commons")
+ imagelink = pywikibot.Link(value, source=commonssite, defaultNamespace=6)
+ image = pywikibot.FilePage(imagelink)
+ if image.isRedirectPage():
+ image = pywikibot.FilePage(image.getRedirectTarget())
+ if not image.exists():
+ pywikibot.output('[[%s]] doesn\'t exist so I can\'t link to it' % (image.title(),))
+ continue
+ claim.setTarget(image)
else:
- if claim.type == 'wikibase-item':
- # Try to extract a valid page
- match = re.search(pywikibot.link_regex, value)
- if not match:
- pywikibot.output(u'%s field %s value %s isnt a wikilink. Skipping' % (claim.getID(), field, value))
- return
+ pywikibot.output("%s is not a supported datatype." % claim.type)
+ continue
- link_text = match.group(1)
- linked_item = self._template_link_target(item, link_text)
- if not linked_item:
- return
-
- claim.setTarget(linked_item)
- elif claim.type == 'string':
- claim.setTarget(value.strip())
- elif claim.type == 'commonsMedia':
- commonssite = pywikibot.Site("commons", "commons")
- imagelink = pywikibot.Link(value, source=commonssite, defaultNamespace=6)
- image = pywikibot.FilePage(imagelink)
- if image.isRedirectPage():
- image = pywikibot.FilePage(image.getRedirectTarget())
- if not image.exists():
- pywikibot.output('[[%s]] doesn\'t exist so I can\'t link to it' % (image.title(),))
- return
- claim.setTarget(image)
- else:
- pywikibot.output("%s is not a supported datatype." % claim.type)
- return
-
- pywikibot.output('Adding %s --> %s' % (claim.getID(), claim.getTarget()))
- item.addClaim(claim)
- # A generator might yield pages from multiple sites
- source = self.getSource(page.site)
- if source:
- claim.addSource(source, bot=True)
+ pywikibot.output('Adding %s --> %s' % (claim.getID(), claim.getTarget()))
+ item.addClaim(claim)
+ # A generator might yield pages from multiple sites
+ source = self.getSource(page.site)
+ if source:
+ claim.addSource(source, bot=True)
def main():
--
To view, visit https://gerrit.wikimedia.org/r/166379
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1c36907b7a7de3a952ec812fef505c8a38f4b187
Gerrit-PatchSet: 1
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: Multichill <maarten(a)mdammers.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: MW 1.25wmf4 API deprecated paraminfo querymodules
......................................................................
MW 1.25wmf4 API deprecated paraminfo querymodules
The API action=paraminfo parameter querymodules has been deprecated
with parameter modules as the alternative, with query+value as the
replacement.
QueryGenerator updated to support both old and new syntax, depending
on the site version.
Bug: 72169
Change-Id: Ic02dfba4fd94d8c69b7f28037330cd6467f30234
---
M pywikibot/data/api.py
1 file changed, 14 insertions(+), 7 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 95f6b91..5357cc5 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -908,22 +908,29 @@
@property
def _modules(self):
- """Query api on self.site for paraminfo on querymodule=self.module."""
- if not set(self.module.split('|')) <= set(self.__modules.keys()):
+ """Query api on self.site for paraminfo on self.module."""
+ modules = self.module.split('|')
+ if not set(modules) <= set(self.__modules.keys()):
+ if LV(self.site.version()) < LV('1.25wmf4'):
+ key = 'querymodules'
+ value = self.module
+ else:
+ key = 'modules'
+ value = ['query+' + module for module in modules]
paramreq = CachedRequest(expiry=config.API_config_expiry,
site=self.site, action="paraminfo",
- querymodules=self.module)
+ **{key: value})
data = paramreq.submit()
assert "paraminfo" in data
- assert "querymodules" in data["paraminfo"]
- assert len(data["paraminfo"]["querymodules"]) == 1 + self.module.count("|")
- for paraminfo in data["paraminfo"]["querymodules"]:
+ assert key in data["paraminfo"]
+ assert len(data["paraminfo"][key]) == len(modules)
+ for paraminfo in data["paraminfo"][key]:
assert paraminfo["name"] in self.module
if "missing" in paraminfo:
raise Error("Invalid query module name '%s'." % self.module)
self.__modules[paraminfo["name"]] = paraminfo
_modules = {}
- for m in self.module.split('|'):
+ for m in modules:
_modules[m] = self.__modules[m]
return _modules
--
To view, visit https://gerrit.wikimedia.org/r/167168
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic02dfba4fd94d8c69b7f28037330cd6467f30234
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(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: pagefromfile.py: pep257 and optimisation
......................................................................
pagefromfile.py: pep257 and optimisation
Close open hanging file.
Use bot.userPut() instead of page.save().
Used PageSaveRelatedError hierarchy.
Change-Id: Ic2da03cac8e3939549fa6bd074539213ee594907
---
M scripts/pagefromfile.py
M tox.ini
2 files changed, 25 insertions(+), 17 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
XZise: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py
index 98df996..dc50d89 100644
--- a/scripts/pagefromfile.py
+++ b/scripts/pagefromfile.py
@@ -1,6 +1,8 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
+Bot to upload pages from a file.
+
This bot takes its input from a file that contains a number of
pages to be put on the wiki. The pages should all have the same
begin and end text (which may not overlap).
@@ -65,18 +67,23 @@
"""No title found."""
def __init__(self, offset):
+ """Constructor."""
self.offset = offset
class PageFromFileRobot(Bot):
"""
- Responsible for writing pages to the wiki, with the titles and contents
- given by a PageFromFileReader.
+ Responsible for writing pages to the wiki.
+
+ Titles and contents are given by a PageFromFileReader.
+
"""
def __init__(self, reader, **kwargs):
+ """Constructor."""
self.availableOptions.update({
+ 'always': True,
'force': False,
'append': None,
'summary': None,
@@ -90,10 +97,12 @@
self.reader = reader
def run(self):
+ """Start file processing and upload content."""
for title, contents in self.reader.run():
self.save(title, contents)
def save(self, title, contents):
+ """Upload page content."""
mysite = pywikibot.Site()
page = pywikibot.Page(mysite, title)
@@ -145,17 +154,12 @@
if self.getOption('autosummary'):
comment = ''
config.default_edit_summary = ''
- try:
- page.text = contents
- page.save(comment, minor=self.getOption('minor'))
- except pywikibot.LockedPage:
- pywikibot.output(u"Page %s is locked; skipping." % title)
- except pywikibot.EditConflict:
- pywikibot.output(u'Skipping %s because of edit conflict' % title)
- except pywikibot.SpamfilterError as error:
- pywikibot.output(
- u'Cannot change %s because of spam blacklist entry %s'
- % (title, error.url))
+
+ self.userPut(page, page.text, contents,
+ comment=comment,
+ minor=self.getOption('minor'),
+ show_diff=False,
+ ignore_save_related_errors=True)
class PageFromFileReader:
@@ -170,11 +174,11 @@
def __init__(self, filename, pageStartMarker, pageEndMarker,
titleStartMarker, titleEndMarker, include, notitle):
"""Constructor.
+
Check if self.file name exists. If not, ask for a new filename.
User can quit.
"""
-
self.filename = filename
self.pageStartMarker = pageStartMarker
self.pageEndMarker = pageEndMarker
@@ -187,13 +191,14 @@
"""Read file and yield page title and content."""
pywikibot.output('\n\nReading \'%s\'...' % self.filename)
try:
- f = codecs.open(self.filename, 'r',
- encoding=config.textfile_encoding)
+ with codecs.open(self.filename, 'r',
+ encoding=config.textfile_encoding) as f:
+ text = f.read()
+
except IOError as err:
pywikibot.output(str(err))
raise IOError
- text = f.read()
position = 0
length = 0
while True:
@@ -214,6 +219,7 @@
yield title, contents
def findpage(self, text):
+ """Find page to work on."""
pageR = re.compile(re.escape(self.pageStartMarker) + "(.*?)" +
re.escape(self.pageEndMarker), re.DOTALL)
titleR = re.compile(re.escape(self.titleStartMarker) + "(.*?)" +
@@ -236,6 +242,7 @@
def main():
+ """Main function."""
# Adapt these to the file you are using. 'pageStartMarker' and
# 'pageEndMarker' are the beginning and end of each entry. Take text that
# should be included and does not occur elsewhere in the text.
diff --git a/tox.ini b/tox.ini
index e002106..f722b37 100644
--- a/tox.ini
+++ b/tox.ini
@@ -58,6 +58,7 @@
./scripts/harvest_template.py \
./scripts/illustrate_wikidata.py \
./scripts/newitem.py \
+ ./scripts/pagefromfile.py \
./tests/aspects.py \
./tests/deprecation_tests.py \
./tests/api_tests.py \
--
To view, visit https://gerrit.wikimedia.org/r/166663
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic2da03cac8e3939549fa6bd074539213ee594907
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: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>