jenkins-bot has submitted this change and it was merged.
Change subject: Force anarchopedia to be MediaWiki v1.14
......................................................................
Force anarchopedia to be MediaWiki v1.14
Anarchopedia is v1.14alpha, and worked correctly
with Pywikibot except for minor quirks.
Workaround version comparisons preventing v1.14alpha
being adequate for v1.14 features.
Bug: T115441
Change-Id: I1bf854da4f3a49c00002a421c2be21b28aaf5390
---
M pywikibot/families/anarchopedia_family.py
1 file changed, 2 insertions(+), 4 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/families/anarchopedia_family.py b/pywikibot/families/anarchopedia_family.py
index 07ce1e2..bb793ad 100644
--- a/pywikibot/families/anarchopedia_family.py
+++ b/pywikibot/families/anarchopedia_family.py
@@ -5,7 +5,6 @@
__version__ = '$Id$'
from pywikibot import family
-from pywikibot.tools import deprecated
# The Anarchopedia family
@@ -73,10 +72,9 @@
self.nocapitalize = list(self.langs.keys())
- @deprecated('APISite.version()')
- def version(self, code):
+ def force_version(self, code):
"""Return the version for this family."""
- return "1.14alpha"
+ return '1.14'
def scriptpath(self, code):
"""Return the script path for this family."""
--
To view, visit https://gerrit.wikimedia.org/r/246173
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1bf854da4f3a49c00002a421c2be21b28aaf5390
Gerrit-PatchSet: 2
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: 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.
Change subject: [FEAT] cache: Separate commands
......................................................................
[FEAT] cache: Separate commands
Instead of having everything in one command and to play with `and` to only
execute part of the command, this is providing three separate commands to
filter for entries, output something depending on them and to do an action
afterwards.
The filter command only needs to return a boolean for an entry. The output
command can either return None to suppress the default output, similar to
before. If it returns anything else it'll print that result. And at the moment
only the delete action is supported and that as an option and not using code
like the other two.
Additionally it supports to only define a function name and it'll call it
automatically with the entry as the first positional parameter.
It adds two utility output functions to easier see what each cache entry is
actually doing.
Change-Id: I7b8fc283555a6d35719e47d28ff1becfbd07baf7
---
M scripts/maintenance/cache.py
1 file changed, 93 insertions(+), 24 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/maintenance/cache.py b/scripts/maintenance/cache.py
index 8aa15b0..d87f543 100755
--- a/scripts/maintenance/cache.py
+++ b/scripts/maintenance/cache.py
@@ -5,29 +5,43 @@
Syntax:
- python pwb.py cache [-password] [-delete] [-c "..."] [dir ...]
+ python pwb.py cache [-password] [-delete] [-c "..."] [-o "..."] [dir ...]
If no directory are specified, it will detect the API caches.
If no command is specified, it will print the filename of all entries.
If only -delete is specified, it will delete all entries.
-The option '-c' must be followed by a command in python syntax.
+-delete Delete each command filtered. If that option is set the
+ default output will be nothing.
+
+-c Filter command in python syntax. It must evaulate to True to
+ output anything.
+
+-o Output command which is output when the filter evaluated to
+ True. If it returns None it won't output anything.
Example commands:
Print the filename of any entry with 'wikidata' in the key:
- entry if "wikidata" in entry._uniquedescriptionstr() else None
+ -c "wikidata" in entry._uniquedescriptionstr()
Customised output if the site code is 'ar':
- entry.site.code == "ar" and print("%s" % entry._uniquedescriptionstr())
+ -c entry.site.code == "ar"
+ -o uniquedesc(entry)
Or the state of the login
- entry.site._loginstatus == LoginStatus.NOT_ATTEMPTED and \
-print("%s" % entry._uniquedescriptionstr())
- These functions can be used as a command:
+ -c entry.site._loginstatus == LoginStatus.NOT_ATTEMPTED
+ -o uniquedesc(entry)
+
+ If the function only uses one parameter for the entry it can be omitted:
+
+ -c has_password
+ -o uniquedesc
+
+Available filter commands:
has_password(entry)
is_logout(entry)
empty_response(entry)
@@ -39,9 +53,13 @@
There are helper functions which can be part of a command:
older_than(entry, interval)
newer_than(entry, interval)
+
+Available output commands:
+
+ uniquedesc(entry)
"""
#
-# (C) Pywikibot team, 2014
+# (C) Pywikibot team, 2014-2015
#
# Distributed under the terms of the MIT license.
#
@@ -182,7 +200,8 @@
os.remove(self._cachefile_path())
-def process_entries(cache_path, func, use_accesstime=None):
+def process_entries(cache_path, func, use_accesstime=None, output_func=None,
+ action_func=None):
"""
Check the contents of the cache.
@@ -251,8 +270,33 @@
pywikibot.exception(e, tb=True)
continue
- func(entry)
+ if func is None or func(entry):
+ if output_func or action_func is None:
+ if output_func is None:
+ output = entry
+ else:
+ output = output_func(entry)
+ if output is not None:
+ pywikibot.output(output)
+ if action_func:
+ action_func(entry)
+
+def _parse_command(command, name):
+ obj = globals().get(command)
+ if callable(obj):
+ return obj
+ else:
+ try:
+ return eval('lambda entry: ' + command)
+ except:
+ pywikibot.exception()
+ pywikibot.error(
+ 'Cannot compile {0} command: {1}'.format(name, command))
+ return None
+
+
+# Filter commands
def has_password(entry):
"""Entry has a password in the entry."""
@@ -306,15 +350,33 @@
return entry
+# Output commands
+
+def uniquedesc(entry):
+ """Return the unique description string."""
+ return entry._uniquedescriptionstr()
+
+
+def parameters(entry):
+ """Return a pretty formatted parameters list."""
+ lines = ''
+ for key, items in sorted(entry._params.items()):
+ lines += '{0}={1}\n'.format(key, ', '.join(items))
+ return lines
+
+
def main():
local_args = pywikibot.handleArgs()
cache_paths = None
delete = False
command = None
+ output = None
for arg in local_args:
if command == '':
command = arg
+ elif output == '':
+ output = arg
elif arg == '-delete':
delete = True
elif arg == '-password':
@@ -324,13 +386,16 @@
pywikibot.error('Only one command may be executed.')
exit(1)
command = ''
+ elif arg == '-o':
+ if output:
+ pywikibot.error('Only one output may be defined.')
+ exit(1)
+ output = ''
else:
if not cache_paths:
cache_paths = [arg]
else:
cache_paths.append(arg)
-
- func = None
if not cache_paths:
cache_paths = ['apicache', 'tests/apicache']
@@ -346,26 +411,30 @@
os.path.join(os.path.expanduser('~/.pywikibot'), 'apicache')]
if delete:
- action_func = lambda entry: entry._delete()
+ action_func = CacheEntry._delete
else:
- action_func = lambda entry: pywikibot.output(entry)
+ action_func = None
+
+ if output:
+ output_func = _parse_command(output, 'output')
+ if output_func is None:
+ return False
+ else:
+ output_func = None
if command:
- try:
- command_func = eval('lambda entry: ' + command)
- except:
- pywikibot.exception()
- pywikibot.error(u'Can not compile command: %s' % command)
- exit(1)
-
- func = lambda entry: command_func(entry) and action_func(entry)
+ filter_func = _parse_command(command, 'filter')
+ if filter_func is None:
+ return False
else:
- func = action_func
+ filter_func = None
for cache_path in cache_paths:
if len(cache_paths) > 1:
pywikibot.output(u'Processing %s' % cache_path)
- process_entries(cache_path, func)
+ process_entries(cache_path, filter_func, output_func=output_func,
+ action_func=action_func)
+
if __name__ == '__main__':
main()
--
To view, visit https://gerrit.wikimedia.org/r/247482
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7b8fc283555a6d35719e47d28ff1becfbd07baf7
Gerrit-PatchSet: 2
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: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [FEAT] listpages: Put the generated list on a wiki
......................................................................
[FEAT] listpages: Put the generated list on a wiki
This adds options to put the generated list on a wiki.
Change-Id: I1293919e9e9187c47730c07a04216abf4d882d3f
---
M scripts/listpages.py
1 file changed, 37 insertions(+), 2 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/listpages.py b/scripts/listpages.py
index d2dc095..d519835 100755
--- a/scripts/listpages.py
+++ b/scripts/listpages.py
@@ -50,6 +50,15 @@
valid python encoding: utf-8, etc.).
If not specified, it defaults to config.textfile_encoding.
+-put: Save the list to the defined page of the wiki. By default it does not
+ overwrite an exisiting page.
+
+-overwrite Overwrite the page if it exists. Can only by applied with -put.
+
+-summary: The summary text when the page is written. If it's one word just
+ containing letters, dashes and underscores it uses that as a
+ translation key.
+
Custom format can be applied to the following items extrapolated from a
page object:
@@ -83,10 +92,11 @@
__version__ = '$Id$'
#
+import re
import os
import pywikibot
-from pywikibot import config2 as config
+from pywikibot import config2 as config, i18n
from pywikibot.pagegenerators import GeneratorFactory, parameterHelp
docuReplacements = {'¶ms;': parameterHelp}
@@ -172,6 +182,9 @@
page_get = False
base_dir = None
encoding = config.textfile_encoding
+ page_target = None
+ overwrite = False
+ summary = 'listpages-save-list'
# Process global args and prepare generator args parser
local_args = pywikibot.handle_args(args)
@@ -191,6 +204,12 @@
base_dir = arg.partition(':')[2] or '.'
elif arg.startswith('-encode:'):
encoding = arg.partition(':')[2]
+ elif arg.startswith('-put:'):
+ page_target = arg.partition(':')[2]
+ elif arg.startswith('-overwrite'):
+ overwrite = True
+ elif arg.startswith('-summary:'):
+ summary = arg.partition(':')[2]
else:
genFactory.handleArg(arg)
@@ -214,13 +233,26 @@
% base_dir)
base_dir = None
+ if page_target:
+ site = pywikibot.Site()
+ page_target = pywikibot.Page(site, page_target)
+ if not overwrite and page_target.exists():
+ pywikibot.bot.suggest_help(
+ additional_text='Page "{0}" already exists.'.format(
+ page_target.title()))
+ return False
+ if re.match('^[a-z_-]+$', summary):
+ summary = i18n.twtranslate(site, summary)
+
gen = genFactory.getCombinedGenerator()
if gen:
i = 0
+ output_list = []
for i, page in enumerate(gen, start=1):
if not notitle:
page_fmt = Formatter(page, outputlang)
- pywikibot.stdout(page_fmt.output(num=i, fmt=fmt))
+ output_list += [page_fmt.output(num=i, fmt=fmt)]
+ pywikibot.stdout(output_list[-1])
if page_get:
try:
pywikibot.output(page.text, toStdout=True)
@@ -232,6 +264,9 @@
with open(filename, mode='wb') as f:
f.write(page.text.encode(encoding))
pywikibot.output(u"%i page(s) found" % i)
+ if page_target:
+ page_target.text = '\n'.join(output_list)
+ page_target.save(summary=summary)
return True
else:
pywikibot.bot.suggest_help(missing_generator=True)
--
To view, visit https://gerrit.wikimedia.org/r/241283
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1293919e9e9187c47730c07a04216abf4d882d3f
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: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] Yield interwiki URLs separately
......................................................................
[IMPROV] Yield interwiki URLs separately
Instead of returning one list with all URLs it can yield one URL at a time.
This way it's possible to only query the article path if nothing else matched
first.
This also adds a parameter to avoid manually skipping the first entry which
isn't actually a suffix for an article URL.
Change-Id: Idd20f0757856299d2ae21608bb29d12c3e4cae11
---
M pywikibot/cosmetic_changes.py
M pywikibot/site.py
2 files changed, 9 insertions(+), 8 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index 3010ef3..c27f9bc 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -703,8 +703,8 @@
exceptions = ['nowiki', 'comment', 'math', 'pre', 'source',
'startspace']
# link to the wiki working on
- # Do not use the first entry as it is not actually a prefix
- for suffix in self.site._interwiki_urls()[1:]:
+ # Only use suffixes for article paths
+ for suffix in self.site._interwiki_urls(True):
http_url = self.site.base_url(suffix, 'http')
if self.site.protocol() == 'http':
https_url = None
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 16d3e99..c6381b5 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -917,12 +917,13 @@
return [lang for lang in self.languages()
if self.namespaces.lookup_normalized_name(lang) is None]
- def _interwiki_urls(self):
- site_paths = [self.path()] * 3
- site_paths[1] += '/'
- site_paths[2] += '?title='
- site_paths += [self.article_path]
- return site_paths
+ def _interwiki_urls(self, only_article_suffixes=False):
+ base_path = self.path()
+ if not only_article_suffixes:
+ yield base_path
+ yield base_path + '/'
+ yield base_path + '?title='
+ yield self.article_path
def interwiki(self, prefix):
"""
--
To view, visit https://gerrit.wikimedia.org/r/247557
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idd20f0757856299d2ae21608bb29d12c3e4cae11
Gerrit-PatchSet: 2
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: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: WikibasePage.get: Do not pass *args into *props
......................................................................
WikibasePage.get: Do not pass *args into *props
It has been impossible to use ItemPage.get *args
since dae1509f, as a way to load specific props.
Loading specific props is mostly unnecessary, as
all props except 'sitelinks/urls' are enabled by default,
and 'sitelinks/urls' only provides urls which are
derived from the site and page title.
If *args was used, ItemPage.get then called
WikibasePage.get(force=force, *args)
WikibasePage.get's signature provided a default for force,
which meant any value in ItemPage.get *args would become
a var arg for WikibasePage.get, causing:
TypeError: get() got multiple values for keyword argument 'force'
Instead raise NotImplementedError when *args or **kwargs contain
a value.
Continues 5cee93bb.
Bug: T115780
Change-Id: I95c86b5b67bede3ca9d19beb479a9649e5ea699e
---
M pywikibot/page.py
M tests/wikibase_tests.py
2 files changed, 55 insertions(+), 8 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index d284e2c..7207a49 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -337,7 +337,9 @@
"""Return True if title of this Page is in the autoFormat dictionary."""
return self.autoFormat()[0] is not None
- @deprecated_args(throttle=None, change_edit_time=None)
+ @deprecated_args(throttle=None,
+ change_edit_time=None,
+ expandtemplates=None)
def get(self, force=False, get_redirect=False, sysop=False):
"""Return the wiki-text of the page.
@@ -3279,15 +3281,20 @@
@param force: override caching
@type force: bool
- @param args: may be used to specify custom props.
+ @raise NotImplementedError: a value in args or kwargs
"""
+ if args or kwargs:
+ raise NotImplementedError(
+ '{0}.get does not implement var args: {1!r} and {2!r}'.format(
+ self.__class__, args, kwargs))
+
lazy_loading_id = not hasattr(self, 'id') and hasattr(self, '_site')
if force or not hasattr(self, '_content'):
identification = self._defined_by()
if not identification:
raise pywikibot.NoPage(self)
- data = self.repo.loadcontent(identification, *args)
+ data = self.repo.loadcontent(identification)
item_index = list(data.keys())[0]
if lazy_loading_id or item_index != '-1':
self.id = item_index
@@ -3712,9 +3719,9 @@
@param get_redirect: return the item content, do not follow the
redirect, do not raise an exception.
@type get_redirect: bool
- @param args: values of props
+ @raise NotImplementedError: a value in args or kwargs
"""
- data = super(ItemPage, self).get(force=force, *args, **kwargs)
+ data = super(ItemPage, self).get(force, *args, **kwargs)
if self.isRedirectPage() and not get_redirect:
raise pywikibot.IsRedirectPage(self)
@@ -4021,15 +4028,20 @@
u"'%s' is not an property page title" % title)
Property.__init__(self, source, self.id)
- def get(self, force=False, *args):
+ def get(self, force=False, *args, **kwargs):
"""
Fetch the property entity, and cache it.
@param force: override caching
- @param args: values of props
+ @type force: bool
+ @raise NotImplementedError: a value in args or kwargs
"""
+ if args or kwargs:
+ raise NotImplementedError(
+ 'PropertyPage.get only implements "force".')
+
if force or not hasattr(self, '_content'):
- WikibasePage.get(self, force=force, *args)
+ WikibasePage.get(self, force)
self._type = self._content['datatype']
def newClaim(self, *args, **kwargs):
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index 9521f0e..1678c3b 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -24,6 +24,7 @@
unittest, TestCase,
WikidataTestCase,
DeprecationTestCase,
+ DefaultWikibaseClientTestCase,
)
from tests.basepage_tests import (
@@ -628,6 +629,40 @@
self._test_no_wikitext()
+class TestDryPageGetNotImplemented(DefaultWikibaseClientTestCase,
+ DeprecationTestCase):
+
+ """Test not implement get arguments of WikibasePage classes."""
+
+ dry = True
+
+ def test_base_get_args(self):
+ """Test WikibasePage.get() with sysop argument."""
+ item = WikibasePage(self.repo, 'Q1')
+ # avoid loading anything
+ item._content = {}
+ self.assertRaises(NotImplementedError,
+ item.get, force=True, sysop=True)
+ self.assertRaises(NotImplementedError,
+ item.get, force=False, sysop=True)
+ self.assertRaises(NotImplementedError,
+ item.get, force=False, sysop=False)
+ self.assertRaises(NotImplementedError,
+ item.get, sysop=True)
+
+ def test_item_get_args(self):
+ """Test ItemPage.get() with sysop argument."""
+ item = pywikibot.ItemPage(self.repo, 'Q1')
+ item._content = {}
+ self.assertRaises(NotImplementedError, item.get, sysop=True)
+
+ def test_property_get_args(self):
+ """Test PropertyPage.get() with sysop argument."""
+ pp = pywikibot.PropertyPage(self.repo, 'P1')
+ pp._content = {}
+ self.assertRaises(NotImplementedError, pp.get, sysop=True)
+
+
class TestLinks(WikidataTestCase):
"""Test cases to test links stored in Wikidata.
--
To view, visit https://gerrit.wikimedia.org/r/216535
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I95c86b5b67bede3ca9d19beb479a9649e5ea699e
Gerrit-PatchSet: 6
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: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] login: Inform about unsupported -pass
......................................................................
[IMPROV] login: Inform about unsupported -pass
The `-pass` parameter is not supported yet so inform the user that defining one
is not actually using that password.
Bug: T102477
Change-Id: I072481cbeb3b089d796a739d2af348f9a26d2dca
---
M scripts/login.py
1 file changed, 4 insertions(+), 0 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/login.py b/scripts/login.py
index a88dff3..f156817 100755
--- a/scripts/login.py
+++ b/scripts/login.py
@@ -148,6 +148,10 @@
pywikibot.bot.suggest_help(unknown_parameters=unknown_args)
return False
+ if password is not None:
+ pywikibot.warning('The -pass argument is not implemented yet. See: '
+ 'https://phabricator.wikimedia.org/T102477')
+
if logall:
if sysop and not oauth:
namedict = config.sysopnames
--
To view, visit https://gerrit.wikimedia.org/r/247039
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I072481cbeb3b089d796a739d2af348f9a26d2dca
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: jenkins-bot <>