jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/370369 )
Change subject: [IMPR] Use context manager to acquire/release locks
......................................................................
[IMPR] Use context manager to acquire/release locks
Change-Id: I7e94fd8d86e4dec125cbaa7c625498ec892476e9
---
M pywikibot/throttle.py
1 file changed, 5 insertions(+), 18 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py
index 24d2266..71c0da8 100644
--- a/pywikibot/throttle.py
+++ b/pywikibot/throttle.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Mechanics to slow down wiki read and/or write rate."""
#
-# (C) Pywikibot team, 2008
+# (C) Pywikibot team, 2008-2017
#
# Distributed under the terms of the MIT license.
#
@@ -78,11 +78,10 @@
def checkMultiplicity(self):
"""Count running processes for site and set process_multiplicity."""
global pid
- self.lock.acquire()
mysite = self.mysite
pywikibot.debug(u"Checking multiplicity: pid = %(pid)s" % globals(),
_logger)
- try:
+ with self.lock:
processes = []
my_pid = pid or 1 # start at 1 if global pid not yet set
count = 1
@@ -139,13 +138,10 @@
pywikibot.log(
'Found {0} {1} processes running, including this one.'.format(
count, mysite))
- finally:
- self.lock.release()
def setDelays(self, delay=None, writedelay=None, absolute=False):
"""Set the nominal delays in seconds. Defaults to config values."""
- self.lock.acquire()
- try:
+ with self.lock:
if delay is None:
delay = self.mindelay
if writedelay is None:
@@ -158,8 +154,6 @@
self.maxdelay)
# Start the delay count now, not at the next check
self.last_read = self.last_write = time.time()
- finally:
- self.lock.release()
def getDelay(self, write=False):
"""Return the actual delay, accounting for multiple processes.
@@ -263,8 +257,7 @@
thread from writing to the same site until the wait expires.
"""
- self.lock.acquire()
- try:
+ with self.lock:
wait = self.waittime(write=write)
# Calculate the multiplicity of the next delay based on how
# big the request is that is being posted now.
@@ -279,8 +272,6 @@
self.last_write = time.time()
else:
self.last_read = time.time()
- finally:
- self.lock.release()
def lag(self, lagtime):
"""Seize the throttle lock due to server lag.
@@ -289,8 +280,7 @@
"""
started = time.time()
- self.lock.acquire()
- try:
+ with self.lock:
# start at 1/2 the current server lag time
# wait at least 5 seconds but not more than 120 seconds
delay = min(max(5, lagtime // 2), 120)
@@ -298,6 +288,3 @@
wait = delay - (time.time() - started)
self.wait(wait)
-
- finally:
- self.lock.release()
--
To view, visit https://gerrit.wikimedia.org/r/370369
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7e94fd8d86e4dec125cbaa7c625498ec892476e9
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/370166 )
Change subject: [DOC] core release is 3.0
......................................................................
[DOC] core release is 3.0
The current core release is 3.0 and the older 2.0 branch has been deleted.
Change-Id: Iea4599da6c52ee2dfdb5ea3a26ae9a8f2f439bb5
---
M README-conversion.txt
M README.rst
M pywikibot/bot.py
M pywikibot/i18n.py
M scripts/commonscat.py
M scripts/maintenance/compat2core.py
6 files changed, 12 insertions(+), 13 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/README-conversion.txt b/README-conversion.txt
index d2fd9ee..d89dec1 100644
--- a/README-conversion.txt
+++ b/README-conversion.txt
@@ -1,7 +1,7 @@
This is a guide to converting bot scripts from version 1 of the
-Pywikibot framework to version 2.
+Pywikibot framework to version 3.
-Most importantly, note that the version 2 framework *only* supports wikis
+Most importantly, note that the version 3 framework *only* supports wikis
using MediaWiki v.1.14 or higher software. If you need to access a wiki that
uses older software, you should continue using version 1 for this purpose.
@@ -150,5 +150,3 @@
now need only that the titles be wrapped in quotes, as:
python unlink.py "A title"
-
-# MORE TO COME #
diff --git a/README.rst b/README.rst
index 4294017..7858840 100644
--- a/README.rst
+++ b/README.rst
@@ -70,13 +70,13 @@
| pwb.py | Wrapper script to use Pywikibot in 'directory' mode |
+---------------------------+------------------------------------------------------+
| README-conversion.txt | Guide to converting bot scripts from version 1 |
- | | of the Pywikibot framework to version 2 |
+ | | of the Pywikibot framework to version 3 |
+---------------------------+------------------------------------------------------+
| README.rst | Short info string used by Pywikibot Nightlies |
+---------------------------+------------------------------------------------------+
| requirements.txt | PIP requirements file |
+---------------------------+------------------------------------------------------+
- | setup.py | Installer script for Pywikibot 2.0 framework |
+ | setup.py | Installer script for Pywikibot 3.0 framework |
+---------------------------+------------------------------------------------------+
| user-config.py.sample | Example user-config.py file for reference |
+---------------------------+------------------------------------------------------+
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 500fb5d..c2ba886 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -316,7 +316,7 @@
if not http or not hasattr(http, 'threads') or not len(http.threads):
return
- log(u'=== Pywikibot framework v2.0 -- Logging header ===')
+ log(u'=== Pywikibot framework v3.0 -- Logging header ===')
# script call
log(u'COMMAND: {0}'.format(sys.argv))
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 5eaf069..241a819 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -6,8 +6,8 @@
and for TranslateWiki-based translations.
By default messages are assumed to reside in a package called
-'scripts.i18n'. In pywikibot 2.0, that package is not packaged
-with pywikibot, and pywikibot 2.0 does not have a hard dependency
+'scripts.i18n'. In pywikibot 3.0, that package is not packaged
+with pywikibot, and pywikibot 3.0 does not have a hard dependency
on any i18n messages. However, there are three user input questions
in pagegenerators which will use i18 messages if they can be loaded.
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 63d8eef..e192065 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -378,7 +378,7 @@
def findCommonscatLink(self, page=None):
"""Find CommonsCat template on interwiki pages.
- In Pywikibot 2.0, page.interwiki() now returns Link objects,
+ In Pywikibot >=2.0, page.interwiki() now returns Link objects,
not Page objects
@rtype: unicode, name of a valid commons category
diff --git a/scripts/maintenance/compat2core.py b/scripts/maintenance/compat2core.py
index 6ec2fea..161baee 100755
--- a/scripts/maintenance/compat2core.py
+++ b/scripts/maintenance/compat2core.py
@@ -1,15 +1,16 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
-A helper script to convert compat 1.0 scripts to the new core 2.0 framework.
+A helper script to convert compat 1.0 scripts to the new core 3.0 framework.
NOTE: Please be aware that this script is not able to convert your codes
completely. It may support you with some automatic replacements and it gives
some warnings and hints for converting. Please refer to the converting guide
-README-conversion.txt in the core framework folder and check your codes finally.
+README-conversion.txt in the core framework folder and check your codes
+finally.
The scripts asks for the .py file and converts it to
-<scriptname>-core.py in the same directory. The following options are supported:
+<scriptname>-core.py in the same directory. The following option is supported:
- warnonly: Do not convert the source but show warning messages. This is good
to check already merged scripts.
--
To view, visit https://gerrit.wikimedia.org/r/370166
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iea4599da6c52ee2dfdb5ea3a26ae9a8f2f439bb5
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/365268 )
Change subject: Update pypi description
......................................................................
Update pypi description
README.rst does not contain a valid desciption for pypi because it also
contains root files and scripts but these files aren't shipped with the
pypi package. Use a new file "pypi_description.rst" for it.
Change-Id: I1b536ef30ce772124e0ae52472e5848b0e28867b
---
A pypi_description.rst
M setup.py
2 files changed, 90 insertions(+), 1 deletion(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pypi_description.rst b/pypi_description.rst
new file mode 100644
index 0000000..25af392
--- /dev/null
+++ b/pypi_description.rst
@@ -0,0 +1,89 @@
+Pywikibot
+=========
+
+The Pywikibot framework is a Python library that interfaces with the
+`MediaWiki API <https://www.mediawiki.org/wiki/Special:MyLanguage/API:Main_page>`_
+version 1.14 or higher.
+
+Also included are various general function scripts that can be adapted for
+different tasks.
+
+For further information about the library excluding scripts see
+the full `code documentation <https://doc.wikimedia.org/pywikibot/>`_.
+
+Quick start
+-----------
+
+::
+
+ git clone https://gerrit.wikimedia.org/r/pywikibot/core.git
+ cd core
+ git submodule update --init
+ python pwb.py script_name
+
+Or to install using PyPI (excluding scripts)
+::
+
+ pip install pywikibot --pre
+
+Our `installation
+guide <https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Pywikibot/Installa…>`_
+has more details for advanced usage.
+
+Basic Usage
+-----------
+
+If you wish to write your own script it's very easy to get started:
+
+::
+
+ import pywikibot
+ site = pywikibot.Site('en', 'wikipedia') # The site we want to run our bot on
+ page = pywikibot.Page(site, 'Wikipedia:Sandbox')
+ page.text = page.text.replace('foo', 'bar')
+ page.save('Replacing "foo" with "bar"') # Saves the page
+
+-------------------------------------------------------------------------------------------
+
+For more documentation on pywikibot see our `docs <https://doc.wikimedia.org/pywikibot/>`_.
+
+
+The contents of the package
+----------------------------
+
+ +----------------------------------------------------------------------------------+
+ | Directories |
+ +===========================+======================================================+
+ | pywikibot | Library routines, control files and global settings |
+ +---------------------------+------------------------------------------------------+
+ | pywikibot/comms | Communication layer |
+ +---------------------------+------------------------------------------------------+
+ | pywikibot/compat | Package to provide compatibility with compat scripts |
+ +---------------------------+------------------------------------------------------+
+ | pywikibot/data | Module with several layers for data access to wiki |
+ +---------------------------+------------------------------------------------------+
+ | pywikibot/families | wiki-specific information and settings |
+ +---------------------------+------------------------------------------------------+
+ | pywikibot/tools | Miscellaneous helper functions (not wiki-dependent) |
+ +---------------------------+------------------------------------------------------+
+ | pywikibot/userinterfaces | GUI and terminal interface |
+ +---------------------------+------------------------------------------------------+
+
+
+Required external programs
+---------------------------
+
+It may require the following programs to function properly:
+
+* `7za`: To extract 7z files
+
+Contributing
+------------
+
+Our code is maintained on Wikimedia's `Gerrit installation <https://gerrit.wikimedia.org/>`_,
+`learn <https://www.mediawiki.org/wiki/Special:MyLanguage/Developer_access>`_ how to get
+started.
+
+.. image:: https://secure.travis-ci.org/wikimedia/pywikibot-core.png?branch=master
+ :alt: Build Status
+ :target: https://travis-ci.org/wikimedia/pywikibot-core
diff --git a/setup.py b/setup.py
index 015a817..d78a7e2 100644
--- a/setup.py
+++ b/setup.py
@@ -208,7 +208,7 @@
name=name,
version=version,
description='Python MediaWiki Bot Framework',
- long_description=open('README.rst').read(),
+ long_description=open('pypi_description.rst').read(),
keywords=('pywikibot', 'python', 'mediawiki', 'bot', 'wiki', 'framework',
'wikimedia', 'wikipedia', 'pwb', 'pywikipedia', 'API'),
maintainer='The Pywikibot team',
--
To view, visit https://gerrit.wikimedia.org/r/365268
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1b536ef30ce772124e0ae52472e5848b0e28867b
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(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. ( https://gerrit.wikimedia.org/r/370213 )
Change subject: [bugfix] Filter bool, None and int types in the right way
......................................................................
[bugfix] Filter bool, None and int types in the right way
- some tests added
Bug: T172521
Change-Id: I9e47935272ca9d05b45de05dfbfe64a83ce54131
---
M pywikibot/comms/eventstreams.py
M tests/eventstreams_tests.py
2 files changed, 17 insertions(+), 2 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/eventstreams.py b/pywikibot/comms/eventstreams.py
index 2236481..240e260 100644
--- a/pywikibot/comms/eventstreams.py
+++ b/pywikibot/comms/eventstreams.py
@@ -171,11 +171,11 @@
# register pairs of keys and items as a filter function
for key, value in kwargs.items():
# append function for singletons
- if value in (True, False, None):
+ if isinstance(value, (bool, type(None))):
self.filter[ftype].append(lambda e: key in e and
e[key] is value)
# append function for a single value
- elif isinstance(value, StringTypes):
+ elif isinstance(value, (StringTypes, int)):
self.filter[ftype].append(lambda e: key in e and
e[key] == value)
# append function for an iterable as value
diff --git a/tests/eventstreams_tests.py b/tests/eventstreams_tests.py
index 8e440bc..4f4cdc3 100644
--- a/tests/eventstreams_tests.py
+++ b/tests/eventstreams_tests.py
@@ -179,6 +179,21 @@
self.es.register_filter(lambda x: True, ftype='none')
self.assertFalse(self.es.streamfilter(self.data))
+ def test_filter_false(self):
+ """Test EventStreams filter with assignment of True."""
+ self.es.register_filter(foo=False)
+ self.assertFalse(self.es.streamfilter(self.data))
+
+ def test_filter_true(self):
+ """Test EventStreams filter with assignment of False."""
+ self.es.register_filter(foo=True)
+ self.assertTrue(self.es.streamfilter(self.data))
+
+ def test_filter_value(self):
+ """Test EventStreams filter with assignment of a int value."""
+ self.es.register_filter(foo=10)
+ self.assertFalse(self.es.streamfilter(self.data))
+
def _test_filter(self, none_type, all_type, any_type, result):
"""Test a single fixed filter."""
self.es.filter = {'all': [], 'any': [], 'none': []}
--
To view, visit https://gerrit.wikimedia.org/r/370213
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9e47935272ca9d05b45de05dfbfe64a83ce54131
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Multichill <maarten(a)mdammers.nl>
Gerrit-Reviewer: Ottomata <aotto(a)wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/364475 )
Change subject: [IMPR] Enhance argument management in harvest_template.py
......................................................................
[IMPR] Enhance argument management in harvest_template.py
Now each param-property pair holds its OptionHandler where
options specific for this claim are stored. Additionally,
it's possible to apply an option to the bot which applies
the option to all claims. Each claim can override this option
if the input is correct (see the updated instructions).
The only available option is at the moment -islink, which
makes the feature added in I71f6857ca optional.
Bug: T64014
Bug: T72702
Bug: T87689
Change-Id: Ibc4a0f845fe88349d49b787b5f16b20eb650ef8e
---
M scripts/harvest_template.py
1 file changed, 127 insertions(+), 24 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index 4957e39..7e55cdd 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -3,12 +3,16 @@
r"""
Template harvesting script.
-Usage:
+Usage (see below for explanations and examples):
* python pwb.py harvest_template -transcludes:"..." \
- template_parameter PID [template_parameter PID]
+ [default optional arguments] \
+ template_parameter PID [local optional arguments] \
+ [template_parameter PID [local optional arguments]]
* python pwb.py harvest_template [generators] -template:"..." \
- template_parameter PID [template_parameter PID]
+ [default optional arguments] \
+ template_parameter PID [local optional arguments] \
+ [template_parameter PID [local optional arguments]]
This will work on all pages that transclude the template in the article
namespace
@@ -17,10 +21,41 @@
¶ms;
+The following command line parameters can be used to change the bot's behavior.
+If you specify them before all parameters, they are global and are applied to
+all param-property pairs. If you specify them after a param-property pair,
+they are local and are only applied to this pair. If you specify the same
+argument as both local and global, the local argument overrides the global one
+(see also examples).
+
+-islink Treat plain text values as links ("text" -> "[[text]]").
+
Examples:
- python pwb.py harvest_template -lang:nl -cat:Sisoridae -namespace:0 \
- -template:"Taxobox straalvinnige" orde P70 familie P71 geslacht P74
+ python pwb.py harvest_template -lang:en -family:wikipedia -namespace:0 \
+ -template:"Infobox person" image P18
+
+ will try to import existing images from "image" parameter of "Infobox
+ person" on English Wikipedia as Wikidata property "P18" (image).
+
+ python pwb.py harvest_template -lang:en -family:wikipedia -namespace:0 \
+ -template:"Infobox person" image P18 birth_place P19
+
+ will behave the same as the previous example and also try to import
+ [[links]] from "birth_place" parameter of the same template as Wikidata
+ property "P19" (place of birth).
+
+ python pwb.py harvest_template -lang:en -family:wikipedia -namespace:0 \
+ -template:"Infobox person" -islink birth_place P19 death_place P20
+
+ will import both "birth_place" and "death_place" params with -islink
+ modifier, ie. the bot will try to import values, even if it doesn't find
+ a [[link]].
+
+ python pwb.py harvest_template -lang:en -family:wikipedia -namespace:0 \
+ -template:"Infobox person" birth_place P19 -islink death_place P20
+
+ will do the same but only "birth_place" can be imported without a link.
"""
#
@@ -52,16 +87,26 @@
signal.signal(signal.SIGINT, _signal_handler)
import pywikibot
-from pywikibot import pagegenerators as pg, WikidataBot, textlib
+from pywikibot import pagegenerators as pg, textlib
+from pywikibot.bot import WikidataBot, OptionHandler
docuReplacements = {'¶ms;': pywikibot.pagegenerators.parameterHelp}
+
+
+class PropertyOptionHandler(OptionHandler):
+
+ """Class holding options for a param-property pair."""
+
+ availableOptions = {
+ 'islink': False,
+ }
class HarvestRobot(WikidataBot):
"""A bot to add Wikidata claims."""
- def __init__(self, generator, templateTitle, fields):
+ def __init__(self, generator, templateTitle, fields, **kwargs):
"""
Constructor.
@@ -71,13 +116,23 @@
@type templateTitle: str
@param fields: A dictionary of fields that are of use to us
@type fields: dict
+ @keyword islink: Whether non-linked values should be treated as links
+ @type islink: bool
"""
- self.availableOptions['always'] = True
- super(HarvestRobot, self).__init__()
+ self.availableOptions.update({
+ 'always': True,
+ 'islink': False,
+ })
+ super(HarvestRobot, self).__init__(**kwargs)
self.generator = generator
self.templateTitle = templateTitle.replace(u'_', u' ')
# TODO: Make it a list which also includes the redirects to the template
- self.fields = fields
+ self.fields = {}
+ for key, value in fields.items():
+ if isinstance(value, tuple):
+ self.fields[key] = value
+ else: # backwards compatibility
+ self.fields[key] = (value, PropertyOptionHandler())
self.cacheSources()
self.templateTitles = self.getTemplateSynonyms(self.templateTitle)
self.linkR = textlib.compileLinkR()
@@ -128,13 +183,27 @@
return linked_item
+ def _get_option_with_fallback(self, handler, option):
+ """
+ Compare bot's (global) and provided (local) options.
+
+ @see: L{pywikibot.bot.OptionHandler.getOption}
+
+ @rtype: bool
+ """
+ # TODO: only works with booleans
+ default = self.getOption(option)
+ local = handler.getOption(option)
+ return default is not local
+
def treat(self, page, item):
"""Process a single page/item."""
if willstop:
raise KeyboardInterrupt
self.current_page = page
item.get()
- if set(self.fields.values()) <= set(item.claims.keys()):
+ if set(val[0] for val in self.fields.values()) <= set(
+ item.claims.keys()):
pywikibot.output('%s item %s has claims for all properties. '
'Skipping.' % (page, item.title()))
return
@@ -160,8 +229,9 @@
# This field contains something useful for us
if field in self.fields:
+ prop, options = self.fields[field]
# Check if the property isn't already set
- claim = pywikibot.Claim(self.repo, self.fields[field])
+ claim = pywikibot.Claim(self.repo, prop)
if claim.getID() in item.get().get('claims'):
pywikibot.output(
'A claim for %s already exists. Skipping.'
@@ -176,7 +246,15 @@
if match:
link_text = match.group(1)
else:
- link_text = value
+ if self._get_option_with_fallback(
+ options, 'islink'):
+ link_text = value
+ else:
+ pywikibot.output(
+ '%s field %s value %s is not a '
+ 'wikilink. Skipping.'
+ % (claim.getID(), field, value))
+ continue
linked_item = self._template_link_target(
item, link_text)
@@ -226,13 +304,15 @@
@param args: command line arguments
@type args: list of unicode
"""
- commandline_arguments = []
- template_title = u''
+ template_title = None
# Process global args and prepare generator args parser
local_args = pywikibot.handle_args(args)
gen = pg.GeneratorFactory()
+ current_args = []
+ fields = {}
+ options = {}
for arg in local_args:
if arg.startswith('-template'):
if len(arg) == 9:
@@ -244,26 +324,49 @@
if arg.startswith(u'-transcludes:'):
template_title = arg[13:]
else:
- commandline_arguments.append(arg)
+ optional = arg.startswith('-')
+ complete = len(current_args) == 3
+ if optional:
+ needs_second = len(current_args) == 1
+ if needs_second:
+ break # will stop below
+
+ arg, sep, value = arg[1:].partition(':')
+ if len(current_args) == 0:
+ assert not fields
+ options[arg] = value or True
+ else:
+ assert complete
+ current_args[2][arg] = value or True
+ else:
+ if complete:
+ handler = PropertyOptionHandler(**current_args[2])
+ fields[current_args[0]] = (current_args[1], handler)
+ current_args.clear()
+ else:
+ current_args.append(arg)
+ if len(current_args) == 2:
+ current_args.append({})
+
+ # handle leftover
+ if len(current_args) == 3:
+ handler = PropertyOptionHandler(**current_args[2])
+ fields[current_args[0]] = (current_args[1], handler)
+ elif len(current_args) == 1:
+ pywikibot.error('Incomplete command line param-property pair.')
+ return False
if not template_title:
pywikibot.error(
'Please specify either -template or -transcludes argument')
return
- if len(commandline_arguments) % 2:
- raise ValueError # or something.
- fields = {}
-
- for i in range(0, len(commandline_arguments), 2):
- fields[commandline_arguments[i]] = commandline_arguments[i + 1]
-
generator = gen.getCombinedGenerator(preload=True)
if not generator:
gen.handleArg(u'-transcludes:' + template_title)
generator = gen.getCombinedGenerator(preload=True)
- bot = HarvestRobot(generator, template_title, fields)
+ bot = HarvestRobot(generator, template_title, fields, **options)
bot.run()
--
To view, visit https://gerrit.wikimedia.org/r/364475
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibc4a0f845fe88349d49b787b5f16b20eb650ef8e
Gerrit-PatchSet: 9
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: JAn Dudík <jan.dudik(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Multichill <maarten(a)mdammers.nl>
Gerrit-Reviewer: XXN <dan10real(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/370223 )
Change subject: [DOC] Include license from parent folder
......................................................................
[DOC] Include license from parent folder
Change-Id: I821b9ca6124acfad2d18a0b75bef9f8d7ac9abcd
---
M docs/licenses.rst
1 file changed, 1 insertion(+), 22 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/licenses.rst b/docs/licenses.rst
index c973eb1..02a921a 100644
--- a/docs/licenses.rst
+++ b/docs/licenses.rst
@@ -11,28 +11,7 @@
-----------
The framework is available under the MIT license:
-Copyright (c) 2004-2013 Pywikibot team
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
+.. include:: ../LICENSE
.. _CC-BY-SA 3.0: http://creativecommons.org/licenses/by-sa/3.0/
--
To view, visit https://gerrit.wikimedia.org/r/370223
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I821b9ca6124acfad2d18a0b75bef9f8d7ac9abcd
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>