jenkins-bot has submitted this change and it was merged.
Change subject: Support querying for commonsMedia via WDQ
......................................................................
Support querying for commonsMedia via WDQ
commonsMedia is a normal STRING query but since it is not stored
as a plain string in pywikibot it must be handled separately.
This follows up on the comments in commit
If81659f2a17442cf182c8402a30e881d7851db17
Bug: T128987
Change-Id: Ibda2db95e83c5deae94bde422f76191f3c65a23a
---
M pywikibot/data/wikidataquery.py
M tests/wikidataquery_tests.py
2 files changed, 13 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/wikidataquery.py b/pywikibot/data/wikidataquery.py
index 8de89bd..c52f3a1 100644
--- a/pywikibot/data/wikidataquery.py
+++ b/pywikibot/data/wikidataquery.py
@@ -454,7 +454,10 @@
if claim.type == 'wikibase-item':
return HasClaim(claim.getID(numeric=True), claim.getTarget().getID(numeric=True))
- if Claim.types.get(claim.type) == basestring:
+ if claim.type == 'commonsMedia':
+ return StringClaim(claim.getID(numeric=True),
+ claim.getTarget().title(withNamespace=False))
+ if claim.type in ('string', 'url', 'math', 'external-id'):
return StringClaim(claim.getID(numeric=True), claim.getTarget())
else:
raise TypeError("Cannot construct a query from a claim of type %s"
diff --git a/tests/wikidataquery_tests.py b/tests/wikidataquery_tests.py
index 8ab9ef3..f9a76b8 100644
--- a/tests/wikidataquery_tests.py
+++ b/tests/wikidataquery_tests.py
@@ -171,6 +171,15 @@
q = query.fromClaim(claim)
self.assertEqual(str(q), 'string[268:"somestring"]')
+ # Datatype: commonsMedia
+ claim = Claim(self.repo, 'P18')
+ claim.setTarget(
+ pywikibot.FilePage(
+ pywikibot.Site(self.family, self.code),
+ 'Foo.jpg'))
+ q = query.fromClaim(claim)
+ self.assertEqual(str(q), 'string[18:"Foo.jpg"]')
+
def testQuerySets(self):
"""Test that we can join queries together correctly."""
# construct via queries
--
To view, visit https://gerrit.wikimedia.org/r/276146
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibda2db95e83c5deae94bde422f76191f3c65a23a
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Lokal Profil <lokal.profil(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Lokal Profil <lokal.profil(a)gmail.com>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Change: Unify name of parameters -pairs and -replacementfile in scripts
......................................................................
Change: Unify name of parameters -pairs and -replacementfile in scripts
Modify replace and movepages scripts to unify -pairs and -replacementfile
parameters.
Change replacebot_tests.py to reflect this change.
Bug: T117176
Change-Id: I8148e04e678b9eb03e37e644bbd362e7751c027a
---
M scripts/movepages.py
M scripts/replace.py
M tests/replacebot_tests.py
3 files changed, 24 insertions(+), 10 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/movepages.py b/scripts/movepages.py
index bf07c1b..0a1174b 100755
--- a/scripts/movepages.py
+++ b/scripts/movepages.py
@@ -26,9 +26,9 @@
-summary Prompt for a custom summary, bypassing the predefined message
texts. Argument can also be given as "-summary:XYZ".
--pairs Read pairs of file names from a file. The file must be in a
+-pairsfile Read pairs of file names from a file. The file must be in a
format [[frompage]] [[topage]] [[frompage]] [[topage]] ...
- Argument can also be given as "-pairs:filename"
+ Argument can also be given as "-pairsfile:filename"
"""
#
@@ -47,6 +47,8 @@
import pywikibot
+from pywikibot.exceptions import ArgumentDeprecationWarning
+from pywikibot.tools import issue_deprecation_warning
from pywikibot import i18n, pagegenerators
from pywikibot.bot import MultipleSitesBot
@@ -192,11 +194,16 @@
for arg in local_args:
if arg.startswith('-pairs'):
- if len(arg) == len('-pairs'):
+ issue_deprecation_warning(
+ '-pairs',
+ '-pairsfile',
+ 2, ArgumentDeprecationWarning)
+ elif arg.startswith('-pairsfile'):
+ if len(arg) == len('-pairsfile'):
filename = pywikibot.input(
u'Enter the name of the file containing pairs:')
else:
- filename = arg[len('-pairs:'):]
+ filename = arg[len('-pairsfile:'):]
oldName1 = None
for page in pagegenerators.TextfilePageGenerator(filename):
if oldName1:
diff --git a/scripts/replace.py b/scripts/replace.py
index 0941a59..7e3f0d9 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -75,9 +75,9 @@
(or no replacements are defined via -fix or the arguments)
it'll ask for additional replacements at start.
--replacementfile Lines from the given file name(s) will be read as replacement
+-pairsfile Lines from the given file name(s) will be read as replacement
arguments. i.e. a file containing lines "a" and "b", used as
- python pwb.py replace -page:X -replacementfile:file c d
+ python pwb.py replace -page:X -pairsfile:file c d
will replace 'a' with 'b' and 'c' with 'd'.
-always Don't prompt you for each replacement
@@ -152,6 +152,8 @@
import pywikibot
+from pywikibot.exceptions import ArgumentDeprecationWarning
+from pywikibot.tools import issue_deprecation_warning
from pywikibot import i18n, textlib, pagegenerators, Bot
from pywikibot import editor as editarticle
@@ -917,14 +919,19 @@
elif arg.startswith('-manualinput'):
manual_input = True
elif arg.startswith('-replacementfile'):
+ issue_deprecation_warning(
+ '-replacementfile',
+ '-pairsfile',
+ 2, ArgumentDeprecationWarning)
+ elif arg.startswith('-pairsfile'):
if len(commandline_replacements) % 2:
replacement_file_arg_misplaced = True
- if arg == '-replacementfile':
+ if arg == '-pairsfile':
replacement_file = pywikibot.input(
u'Please enter the filename to read replacements from:')
else:
- replacement_file = arg[len('-replacementfile:'):]
+ replacement_file = arg[len('-pairsfile:'):]
else:
commandline_replacements.append(arg)
@@ -936,7 +943,7 @@
if replacement_file_arg_misplaced:
pywikibot.error(
- '-replacementfile used between a pattern replacement pair.')
+ '-pairsfile used between a pattern replacement pair.')
return False
if replacement_file:
diff --git a/tests/replacebot_tests.py b/tests/replacebot_tests.py
index 4bbcb74..e7181e7 100644
--- a/tests/replacebot_tests.py
+++ b/tests/replacebot_tests.py
@@ -98,7 +98,7 @@
def test_invalid_replacements(self):
"""Test invalid command line replacement configurations."""
# old and new need to be together
- self.assertFalse(self._run('foo', '-replacementfile:/dev/null', 'bar'))
+ self.assertFalse(self._run('foo', '-pairsfile:/dev/null', 'bar'))
# only old provided
self.assertFalse(self._run('foo'))
--
To view, visit https://gerrit.wikimedia.org/r/275025
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8148e04e678b9eb03e37e644bbd362e7751c027a
Gerrit-PatchSet: 7
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Darthbhyrava <hbhyrava(a)gmail.com>
Gerrit-Reviewer: Darthbhyrava <hbhyrava(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
Build Update for wikimedia/pywikibot-core
-------------------------------------
Build: #3305
Status: Failed
Duration: 14 minutes and 32 seconds
Commit: e56d112 (correction)
Author: Andre Engels
Message: Two changes
1: going from gcmstartsortkey/gcmendsortkey: attempt to make starting inside a category work; doesn't work, but does fail a bit less badly now
2: corrected a missing argument in issue_deprecation_warning call (bugfix)
Change-Id: I229e05a2cd47059a1682a5b6c6a353af04968139
View the changeset: https://github.com/wikimedia/pywikibot-core/compare/10d0b7decd97^...e56d112…
View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/114772516
--
You can configure recipients for build notifications in your .travis.yml file. See https://docs.travis-ci.com/user/notifications
jenkins-bot has submitted this change and it was merged.
Change subject: Allow any claim of basestring type to create a STRING query
......................................................................
Allow any claim of basestring type to create a STRING query
Bug: T128987
Change-Id: If81659f2a17442cf182c8402a30e881d7851db17
---
M pywikibot/data/wikidataquery.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
Objections:
Ricordisamoa: There's a problem with this change, please improve
diff --git a/pywikibot/data/wikidataquery.py b/pywikibot/data/wikidataquery.py
index 9772706..8de89bd 100644
--- a/pywikibot/data/wikidataquery.py
+++ b/pywikibot/data/wikidataquery.py
@@ -454,7 +454,7 @@
if claim.type == 'wikibase-item':
return HasClaim(claim.getID(numeric=True), claim.getTarget().getID(numeric=True))
- if claim.type == 'string':
+ if Claim.types.get(claim.type) == basestring:
return StringClaim(claim.getID(numeric=True), claim.getTarget())
else:
raise TypeError("Cannot construct a query from a claim of type %s"
--
To view, visit https://gerrit.wikimedia.org/r/276131
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If81659f2a17442cf182c8402a30e881d7851db17
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Lokal Profil <lokal.profil(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>