jenkins-bot has submitted this change and it was merged.
Change subject: Fix crash during handling of unusual api response
......................................................................
Fix crash during handling of unusual api response
commit 0658eba in 2010 changed a debugging output such that it always
throws an exception because string format arguments are not all used
in the format string.
Change-Id: I3742affd93899176ac261dd8f5958d8ed1967105
---
M pywikibot/data/api.py
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 4f46027..9cb5e5c 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -1064,8 +1064,8 @@
return
if "query" not in self.data:
pywikibot.debug(
- u"%s: stopped iteration because 'query' not found in api response."
- % (self.__class__.__name__, self.resultkey),
+ u"%s: stopped iteration because 'query' not found in api "
+ u"response." % self.__class__.__name__,
_logger)
pywikibot.debug(unicode(self.data), _logger)
return
--
To view, visit https://gerrit.wikimedia.org/r/168280
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3742affd93899176ac261dd8f5958d8ed1967105
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: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Fix doctest broken by deprecation warning
......................................................................
Fix doctest broken by deprecation warning
MW API has deprecated the old request query system, issuing a warning
if neither 'continue' nor 'rawcontinue' are in the request params.
This breaks the doctest for the raw Request object, which prevents
jenkins from approving code changes which dont resolve this issue.
Modified the expected outcome to allow for warnings in the response,
so that the dev system isnt in stalemate while waiting for the right
fix.
Change-Id: I07081de95437724233afe38df663256a3e495280
---
M pywikibot/data/api.py
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 4f46027..95b9770 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -196,8 +196,8 @@
>>> data = r.submit() # doctest: +IGNORE_UNICODE
>>> isinstance(data, dict)
True
- >>> sorted(data.keys()) # doctest: +IGNORE_UNICODE
- ['query']
+ >>> 'query' in data
+ True
>>> sorted(data[u'query'].keys()) # doctest: +IGNORE_UNICODE
['namespaces', 'userinfo']
--
To view, visit https://gerrit.wikimedia.org/r/168700
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I07081de95437724233afe38df663256a3e495280
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: TestCaseBase should inherit from unittest.TestCase
......................................................................
TestCaseBase should inherit from unittest.TestCase
All classes in the test aspect class heirachy should inherit
from unittest.TestCase.
Fixing this slightly changes the MRU, but otherwise has no effect.
It does allow better static and dynamic checking of the code.
Change-Id: I3a3c857c3a26bf70262926062d1e9f032a648ee9
---
M tests/aspects.py
1 file changed, 4 insertions(+), 4 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/aspects.py b/tests/aspects.py
index b7a9b34..0f3b9f1 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -43,7 +43,7 @@
from tests import unittest, patch_request, unpatch_request
-class TestCaseBase(object):
+class TestCaseBase(unittest.TestCase):
"""Base class for all tests."""
@@ -116,7 +116,7 @@
pywikibot.Site = self.old_Site_lookup_method
-class ForceCacheMixin(object):
+class ForceCacheMixin(TestCaseBase):
"""Aggressively cached API test cases.
@@ -137,7 +137,7 @@
unpatch_request()
-class CacheInfoMixin(object):
+class CacheInfoMixin(TestCaseBase):
"""Report cache hits and misses."""
@@ -387,7 +387,7 @@
return super(MetaTestCaseClass, cls).__new__(cls, name, bases, dct)
-class TestCase(TestTimerMixin, TestCaseBase, unittest.TestCase):
+class TestCase(TestTimerMixin, TestCaseBase):
"""Run tests on multiple sites."""
--
To view, visit https://gerrit.wikimedia.org/r/167996
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3a3c857c3a26bf70262926062d1e9f032a648ee9
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Fix harvest_template linked page check
......................................................................
Fix harvest_template linked page check
Change-Id: I4d52872b9ea04e462b48336b653cf762d9e84fb8
---
M scripts/harvest_template.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index 74ecc21..94b1e3a 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -95,7 +95,7 @@
except pywikibot.NoPage:
linked_item = None
- if not item or not linked_item.exists():
+ if not linked_item or not linked_item.exists():
pywikibot.output(u'%s doesn\'t have a wikidata item to link with. Skipping' % (linked_page))
return
--
To view, visit https://gerrit.wikimedia.org/r/167820
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4d52872b9ea04e462b48336b653cf762d9e84fb8
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: 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: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Search user-config.py in default dir before creating a new one
......................................................................
Search user-config.py in default dir before creating a new one
Also logs directory of config-user.py.
Change-Id: Ic8ac542919e18ad16458d21e0f9713ade899b964
---
M pwb.py
M pywikibot/bot.py
M pywikibot/config2.py
3 files changed, 47 insertions(+), 28 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py
index befa539..16efbca 100644
--- a/pwb.py
+++ b/pwb.py
@@ -1,11 +1,14 @@
# -*- coding: utf-8 -*-
-"""wrapper script to use rewrite in 'directory' mode - run scripts using
-python pwb.py <name_of_script> <options>
+"""Wrapper script to use Pywikibot in 'directory' mode.
+
+Run scripts using:
+
+ python pwb.py <name_of_script> <options>
and it will use the package directory to store all user files, will fix up
search paths so the package does not need to be installed, etc.
"""
-# (C) Pywikibot team, 2013
+# (C) Pywikibot team, 2014
#
# Distributed under the terms of the MIT license.
#
@@ -24,12 +27,15 @@
def tryimport_pwb():
- # See if we can import pywikibot. If so, we need to patch pwb.argvu, too.
- # If pywikibot is not available, we create a mock object to remove the
- # need for if statements further on.
+ """Try to import pywikibot.
+
+ If so, we need to patch pwb.argvu, too.
+ If pywikibot is not available, we create a mock object to remove the
+ need for if statements further on.
+ """
global pwb
try:
- import pywikibot
+ import pywikibot # noqa
pwb = pywikibot
except RuntimeError:
pwb = lambda: None
@@ -143,21 +149,18 @@
print("Upgrade to Python 2.7, or run 'pip install ordereddict'")
sys.exit(1)
-if "PYWIKIBOT2_DIR" not in os.environ:
- os.environ["PYWIKIBOT2_DIR"] = os.path.split(__file__)[0]
-
-for i, x in enumerate(sys.argv):
- if x.startswith("-dir:"):
- os.environ["PYWIKIBOT2_DIR"] = x[5:]
- sys.argv.pop(i)
- break
-
-user_config_path = os.path.join(os.environ["PYWIKIBOT2_DIR"], "user-config.py")
-if not os.path.exists(user_config_path):
- print("NOTE: %s was not found" % user_config_path)
+# Search for user-config.py before creating one.
+try:
+ # user-config.py already exists
+ import pywikibot # noqa
+except RuntimeError as err:
+ # user-config.py to be created
+ print("NOTE: 'user-config.py' was not found!")
print("Please follow the prompts to create it:")
- path = 'generate_user_files.py'
- run_python_file(path, [path], [path.decode('ascii')])
+ run_python_file('generate_user_files.py',
+ ['generate_user_files.py'] + sys.argv[1:],
+ [])
+ sys.exit(1)
if len(sys.argv) > 1:
tryimport_pwb()
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 52a31c0..6386c82 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -280,6 +280,9 @@
if hasattr(os, 'uname'):
log(u'SYSTEM: %s' % unicode(os.uname()))
+ # config file dir
+ log(u'CONFIG FILE DIR: %s' % pywikibot.config2.base_dir)
+
all_modules = sys.modules.keys()
# These are the main dependencies of pywikibot.
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 55453dc..7316d9f 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -163,12 +163,16 @@
if test_directory is not None:
test_directory = os.path.abspath(test_directory)
- NAME = "pywikibot"
+
+ DIRNAME_WIN = u"Pywikibot"
+ DIRNAME_WIN_FBCK = u"pywikibot"
+ DIRNAME_UNIX = u".pywikibot"
+
base_dir = ""
for arg in sys.argv[1:]:
if arg.startswith("-dir:"):
base_dir = arg[5:]
- sys.argv.remove(arg)
+ base_dir = os.path.expanduser(base_dir)
break
else:
if 'PYWIKIBOT2_DIR' in os.environ:
@@ -176,20 +180,29 @@
elif exists('.'):
return os.path.abspath('.')
else:
+ base_dir_cand = []
home = os.path.expanduser("~")
if sys.platform == 'win32':
import platform
win_version = int(platform.version()[0])
if win_version == 5:
- base_dir = os.path.join(home, "Application Data", NAME)
+ sub_dir = ["Application Data"]
elif win_version == 6:
- base_dir = os.path.join(home, "AppData\\Roaming", NAME)
+ sub_dir = ["AppData", "Roaming"]
+ base_dir_cand.extend([[home] + sub_dir + [DIRNAME_WIN],
+ [home] + sub_dir + [DIRNAME_WIN_FBCK]])
#TODO: Throw exception otherwise to notify the user that the
# version of Windows is not (yet) supported
else:
- base_dir = os.path.join(home, "." + NAME)
- if not os.path.isdir(base_dir):
- os.makedirs(base_dir, mode=0o700)
+ base_dir_cand.append([home, DIRNAME_UNIX])
+
+ for dir in base_dir_cand:
+ dir = os.path.join(*dir)
+ if not os.path.isdir(dir):
+ os.makedirs(dir, mode=0o700)
+ if exists(dir):
+ base_dir = dir
+
if not os.path.isabs(base_dir):
base_dir = os.path.normpath(os.path.join(os.getcwd(), base_dir))
# make sure this path is valid and that it contains user-config file
--
To view, visit https://gerrit.wikimedia.org/r/87893
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic8ac542919e18ad16458d21e0f9713ade899b964
Gerrit-PatchSet: 18
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: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: ItemPage.fromPage should strip #section
......................................................................
ItemPage.fromPage should strip #section
When ItemPage.fromPage is asked to create an ItemPage object from
a Page, if the Page object has a 'section', it will send the #section
urlencoded to Wikibase API to be resolved to a data item, and Wikibase
will return -1 (missing).
Bug: 72317
Change-Id: Ifd6976f4132f827ddb12670dfe391ff7e7661d53
---
M pywikibot/page.py
M tests/wikibase_tests.py
2 files changed, 15 insertions(+), 1 deletion(-)
Approvals:
Multichill: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 1b2b788..2c3db36 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3150,7 +3150,7 @@
# clear id, and temporarily store data needed to lazy loading the item
del i.id
i._site = page.site
- i._title = page.title()
+ i._title = page.title(withSection=False)
if not lazy_load and not i.exists():
raise pywikibot.NoPage(i)
return i
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index f41640e..4c6d932 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -280,6 +280,20 @@
item.get()
self.assertTrue(item.exists())
+ def test_fromPage_noprops_with_section(self):
+ page = pywikibot.Page(self.nyc.site, self.nyc.title() + '#foo')
+ item = pywikibot.ItemPage.fromPage(page)
+ self.assertEqual(item._link._title, '-1')
+ self.assertTrue(hasattr(item, 'id'))
+ self.assertTrue(hasattr(item, '_content'))
+ self.assertEqual(item.title(), 'Q60')
+ self.assertTrue(hasattr(item, '_content'))
+ self.assertEqual(item.id, 'Q60')
+ self.assertEqual(item.getID(), 'Q60')
+ self.assertEqual(item.getID(numeric=True), 60)
+ item.get()
+ self.assertTrue(item.exists())
+
def test_fromPage_props(self):
page = self.nyc
# fetch page properties
--
To view, visit https://gerrit.wikimedia.org/r/167819
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifd6976f4132f827ddb12670dfe391ff7e7661d53
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: 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 <>