jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1017512?usp=email )
Change subject: [doc] update ROADMAP.rst
......................................................................
[doc] update ROADMAP.rst
Change-Id: I992550ef6b9b82e3819a48b44599485c42bc2b0a
---
M ROADMAP.rst
1 file changed, 17 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ROADMAP.rst b/ROADMAP.rst
index b00b932..850f0a3 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,7 +1,14 @@
Current release
---------------
-* (no changes yet)
+* File title of :class:`specialbots.UploadRobot` must have a valid file extension (:phab:`T345786`)
+* Add a :attr:`post_processor<specialbots.UploadRobot.post_processor>` attribute to :class:`specialbots.UploadRobot`
+ which can be called after each upload (:phab:`T359766`)
+* Avoid using :meth:`pywikibot.handle_args` in private scripts;
+ use :mod:`pwb<pywikibot.scripts.wrapper>` wrapper instead (:phab:`T359766`)
+* Show upload count with :class:`specialbots.UploadRobot`
+* Use the same ``iiprop`` properties in :class:`data.api.PageGenerator` as in
+ :meth:`APISite.loadimageinfo<pywikibot.site._apisite.APISite.loadimageinfo>` (:phab:`T360093`)
Deprecations
------------
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1017512?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I992550ef6b9b82e3819a48b44599485c42bc2b0a
Gerrit-Change-Number: 1017512
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1015994?usp=email )
Change subject: [fix] file title must have a valid file extension
......................................................................
[fix] file title must have a valid file extension
An invalid file extension will lead to a ValueError.
Skip the current file or retry to enter a valid filename.
Bug: T345786
Change-Id: Ie95c837156d893e2e8faa6eaac96fc95a63531a8
---
M pywikibot/specialbots/_upload.py
1 file changed, 20 insertions(+), 7 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/specialbots/_upload.py b/pywikibot/specialbots/_upload.py
index ce8bd29..0aad35d 100644
--- a/pywikibot/specialbots/_upload.py
+++ b/pywikibot/specialbots/_upload.py
@@ -3,7 +3,7 @@
Do not import classes directly from here but from specialbots.
"""
#
-# (C) Pywikibot team, 2003-2023
+# (C) Pywikibot team, 2003-2024
#
# Distributed under the terms of the MIT license.
#
@@ -270,13 +270,13 @@
if self.opt.always:
pywikibot.info('File format is not one of [{}]'
.format(' '.join(allowed_formats)))
- continue
- if not pywikibot.input_yn(
- 'File format is not one of [{}], but {!r}. Continue?'
- .format(' '.join(allowed_formats), ext),
- default=False):
- continue
+ elif pywikibot.input_yn(
+ 'File format is not one of [{}], but {!r}. Skip?'
+ .format(' '.join(allowed_formats), ext)):
+ return None
+
+ continue
potential_file_page = pywikibot.FilePage(self.target_site,
filename)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1015994?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ie95c837156d893e2e8faa6eaac96fc95a63531a8
Gerrit-Change-Number: 1015994
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1017109?usp=email )
Change subject: [doc] update UploadRobot documentation
......................................................................
[doc] update UploadRobot documentation
Change-Id: I07a428bf4476214179a5ea5d9981755b1d9e94fb
---
M pywikibot/specialbots/_upload.py
1 file changed, 14 insertions(+), 8 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/specialbots/_upload.py b/pywikibot/specialbots/_upload.py
index 9c217db..128d9bd 100644
--- a/pywikibot/specialbots/_upload.py
+++ b/pywikibot/specialbots/_upload.py
@@ -31,10 +31,10 @@
"""Upload bot."""
post_processor: Callable[[str, str | None], None] | None = None
- """If this attribute is set to a callable, the :meth:`run` method calls it
- after upload. The parameter passed to the callable is the origin *file_url*
- passed to the :meth:`upload` method and the filename returned from that
- method. It can be used like this:
+ """If this attribute is set to a callable, the :meth:`run` method
+ calls it after upload. The parameters passed to the callable is the
+ origin *file_url* passed to the :meth:`upload` method and the
+ *filename* returned from that method. It can be used like this:
.. code:: python
@@ -70,7 +70,6 @@
.. versionchanged:: 6.2
asynchronous upload is used if *asynchronous* parameter is set
-
.. versionchanged:: 6.4
*force_if_shared* parameter was added
@@ -78,7 +77,6 @@
to local files.
:param description: Description of file for its page. If multiple files
are uploading the same description is used for every file.
- :type description: str
:param use_filename: Specify title of the file's page. If multiple
files are uploading it asks to change the name for second, third,
etc. files, otherwise the last file will overwrite the other.
@@ -104,11 +102,10 @@
:param force_if_shared: Upload the file even if it's currently
shared to the target site (e.g. when moving from Commons to another
wiki)
- :keyword always: Disables any input, requires that either
+ :keyword bool always: Disables any input, requires that either
ignore_warning or aborts are set to True and that the
description is also set. It overwrites verify_description to
False and keep_filename to True.
- :type always: bool
"""
super().__init__(**kwargs)
if self.opt.always:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1017109?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I07a428bf4476214179a5ea5d9981755b1d9e94fb
Gerrit-Change-Number: 1017109
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1015990?usp=email )
Change subject: [IMPR} Add a post_processing attribute to UploadRobot
......................................................................
[IMPR} Add a post_processing attribute to UploadRobot
If this attribute is set to a callable, the run method calls it
after upload. The parameter passed to the callable is the origin file_url
passed to the upload method and the filename returned from that method.
- use this feature with imagetransfer and use bot.run() mehtod instead
of bot.upload_file()
Bug: T360837
Change-Id: I4a9c6182a87a601ce770ebb5e84c8898d2a4563d
---
M pywikibot/specialbots/_upload.py
M scripts/imagetransfer.py
M tests/uploadbot_tests.py
3 files changed, 75 insertions(+), 29 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/specialbots/_upload.py b/pywikibot/specialbots/_upload.py
index ce8bd29..e34f601 100644
--- a/pywikibot/specialbots/_upload.py
+++ b/pywikibot/specialbots/_upload.py
@@ -3,7 +3,7 @@
Do not import classes directly from here but from specialbots.
"""
#
-# (C) Pywikibot team, 2003-2023
+# (C) Pywikibot team, 2003-2024
#
# Distributed under the terms of the MIT license.
#
@@ -21,6 +21,7 @@
import pywikibot
import pywikibot.comms.http as http
from pywikibot import config
+from pywikibot.backports import Callable
from pywikibot.bot import BaseBot, QuitKeyboardInterrupt
from pywikibot.exceptions import APIError, FatalServerError, NoPageError
@@ -29,6 +30,27 @@
"""Upload bot."""
+ post_processor: Callable[[str, str | None], None] | None = None
+ """If this attribute is set to a callable, the :meth:`run` method calls it
+ after upload. The parameter passed to the callable is the origin *file_url*
+ passed to the :meth:`upload` method and the filename returned from that
+ method. It can be used like this:
+
+ .. code:: python
+
+ def summarize(old: str, new: str | None) -> None:
+ if new is None:
+ print(f'{old} was ignored')
+ else:
+ print(f'{old} was uploaded as {new}')
+
+ bot = UploadRobot('Myfile.bmp')
+ bot.post_processor = summarize
+ bot.run()
+
+ .. versionadded:: 9.1
+ """
+
def __init__(self, url: list[str] | str, *,
url_encoding=None,
description: str = '',
@@ -464,6 +486,8 @@
self.counter['read'] += 1
if filename:
self.counter['upload'] += 1
+ if callable(self.post_processor):
+ self.post_processor(file_url, filename)
except QuitKeyboardInterrupt:
pywikibot.info(f'\nUser quit {type(self).__name__} bot run...')
except KeyboardInterrupt:
diff --git a/scripts/imagetransfer.py b/scripts/imagetransfer.py
index eb4bf8c..7cf4836 100755
--- a/scripts/imagetransfer.py
+++ b/scripts/imagetransfer.py
@@ -37,7 +37,7 @@
¶ms;
"""
#
-# (C) Pywikibot team, 2004-2022
+# (C) Pywikibot team, 2004-2024
#
# Distributed under the terms of the MIT license.
#
@@ -201,6 +201,34 @@
:return: the filename which was used to upload the image
"""
+ def delete_source(old_filename, target_filename):
+ """Delete source image or tag nowCommons template to it.
+
+ This function is called when upload to Commons was
+ successful.
+ """
+ if not target_filename \
+ or self.opt.target.sitename != 'commons:commons':
+ return
+
+ reason = i18n.twtranslate(sourceSite,
+ 'imagetransfer-nowcommons_notice')
+ # try to delete the original image if we have a sysop account
+ if sourceSite.has_right('delete') \
+ and sourceImagePage.delete(reason):
+ return
+
+ if sourceSite.lang in nowCommonsTemplate \
+ and sourceSite.family.name in config.usernames \
+ and sourceSite.lang in config.usernames[sourceSite.family.name]:
+ # add the nowCommons template.
+ pywikibot.info('Adding nowCommons template to '
+ + sourceImagePage.title())
+ sourceImagePage.put(sourceImagePage.get() + '\n\n'
+ + nowCommonsTemplate[sourceSite.code]
+ % target_filename,
+ summary=reason)
+
sourceSite = sourceImagePage.site
pywikibot.info(
'\n>>> Transfer {source} from {source.site} to {target}\n'
@@ -246,32 +274,8 @@
force_if_shared=self.opt.force_if_shared,
asynchronous=self.opt.asynchronous,
chunk_size=self.opt.chunk_size)
-
- # try to upload
- if bot.skip_run():
- return
- target_filename = bot.upload_file(url)
-
- if target_filename \
- and self.opt.target.sitename == 'commons:commons':
- # upload to Commons was successful
- reason = i18n.twtranslate(sourceSite,
- 'imagetransfer-nowcommons_notice')
- # try to delete the original image if we have a sysop account
- if sourceSite.has_right('delete') \
- and sourceImagePage.delete(reason):
- return
- if sourceSite.lang in nowCommonsTemplate \
- and sourceSite.family.name in config.usernames \
- and sourceSite.lang in \
- config.usernames[sourceSite.family.name]:
- # add the nowCommons template.
- pywikibot.info('Adding nowCommons template to '
- + sourceImagePage.title())
- sourceImagePage.put(sourceImagePage.get() + '\n\n'
- + nowCommonsTemplate[sourceSite.lang]
- % target_filename,
- summary=reason)
+ bot.post_processor = delete_source
+ bot.run()
def show_image_list(self, imagelist) -> None:
"""Print image list."""
diff --git a/tests/uploadbot_tests.py b/tests/uploadbot_tests.py
index 4bc255f..7bffec2 100755
--- a/tests/uploadbot_tests.py
+++ b/tests/uploadbot_tests.py
@@ -5,7 +5,7 @@
These tests write to the wiki.
"""
#
-# (C) Pywikibot team, 2014-2022
+# (C) Pywikibot team, 2014-2024
#
# Distributed under the terms of the MIT license.
#
@@ -83,6 +83,7 @@
self.assertTrue(bot._handle_warning('any warning')) # ignore_warning
self.assertTrue(bot.ignore_on_warn('any warning')) # ignore_warning
self.assertFalse(bot.abort_on_warn('any warning')) # aborts
+ self.assertIsNone(bot.post_processor)
if __name__ == '__main__':
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1015990?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I4a9c6182a87a601ce770ebb5e84c8898d2a4563d
Gerrit-Change-Number: 1015990
Gerrit-PatchSet: 7
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1016793?usp=email )
Change subject: [doc] Add admoniton and hint for pywikibot.handle_args() usage
......................................................................
[doc] Add admoniton and hint for pywikibot.handle_args() usage
Bug: T359766
Change-Id: Idf3d76406590dd0a39cc08dd47c39d45c6b32c60
---
M pywikibot/bot.py
M pywikibot/scripts/wrapper.py
2 files changed, 35 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 04606a0..935886d 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -672,6 +672,26 @@
['-myoption']
>>> for arg in local_args: pass # do whatever is wanted with local_args
+ .. caution::
+ Global options might be introduced without warning period. It is
+ up to developers to verify that global options do not interfere
+ with local script options of private scripts.
+
+ .. tip::
+ Avoid using this method in your private scripts and use the
+ :mod:`pwb<pywikibot.scripts.wrapper>` wrapper instead. In
+ directory mode::
+
+ python pwb.py <global options> <name_of_script> <local options>
+
+ With installed site package::
+
+ pwb <global options> <name_of_script> <local options>
+
+ .. note:: the :mod:`pwb<pywikibot.scripts.wrapper>` wrapper can
+ be used even if the `handle_args` method is used within the
+ script.
+
.. versionchanged:: 5.2
*-site* global option was added
.. versionchanged:: 7.1
diff --git a/pywikibot/scripts/wrapper.py b/pywikibot/scripts/wrapper.py
index ba63b8d..32eaa8f 100755
--- a/pywikibot/scripts/wrapper.py
+++ b/pywikibot/scripts/wrapper.py
@@ -30,12 +30,14 @@
python pwb.py -lang:de bot_tests -v
+.. seealso:: :mod:`pwb` entry point
.. versionchanged:: 7.0
- pwb wrapper was added to the Python site package lib
+ pwb wrapper was added to the Python site package lib.
.. versionchanged:: 7.7
- pwb wrapper is able to set ``PYWIKIBOT_TEST_...`` environment variables
+ pwb wrapper is able to set ``PYWIKIBOT_TEST_...`` environment variables,
+ see :ref:`Environment variables`.
.. versionchanged:: 8.0
- renamed to wrapper.py
+ renamed to wrapper.py.
"""
#
# (C) Pywikibot team, 2012-2024
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1016793?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Idf3d76406590dd0a39cc08dd47c39d45c6b32c60
Gerrit-Change-Number: 1016793
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1016331?usp=email )
Change subject: [doc] Update documentation for BasePage.get() and BasePage.text
......................................................................
[doc] Update documentation for BasePage.get() and BasePage.text
The argument of IsRedirectPageError is the page itself since Pywikibot
core release. With compat release it was the redirect target page.
The reason for this change in core release is documented in
rPWBC1585a990e3d1:
"... getting the redirect target requires an additional API request
... Knowing that we have a redirect page without knowing its target
is sometimes enough."
Bug: T361531
Change-Id: I07f9ff7b270d561020fdf72c999df3641e3eda18
---
M pywikibot/page/_basepage.py
1 file changed, 66 insertions(+), 14 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/_basepage.py b/pywikibot/page/_basepage.py
index 6af8970..8eaeeb0 100644
--- a/pywikibot/page/_basepage.py
+++ b/pywikibot/page/_basepage.py
@@ -358,19 +358,31 @@
"""Return the wiki-text of the page.
This will retrieve the page from the server if it has not been
- retrieved yet, or if force is True. This can raise the following
- exceptions that should be caught by the calling code:
+ retrieved yet, or if force is True. Exceptions should be caught
+ by the calling code.
- :exception pywikibot.exceptions.NoPageError: The page does not exist
- :exception pywikibot.exceptions.IsRedirectPageError: The page is a
- redirect. The argument of the exception is the title of the page
- it redirects to.
- :exception pywikibot.exceptions.SectionError: The section does not
- exist on a page with a # link
+ **Example:**
- :param force: reload all page attributes, including errors.
- :param get_redirect: return the redirect text, do not follow the
- redirect, do not raise an exception.
+ >>> import pywikibot
+ >>> site = pywikibot.Site('mediawiki')
+ >>> page = pywikibot.Page(site, 'Pywikibot')
+ >>> page.get(get_redirect=True)
+ '#REDIRECT[[Manual:Pywikibot]]'
+ >>> page.get()
+ Traceback (most recent call last):
+ ...
+ pywikibot.exceptions.IsRedirectPageError: ... is a redirect page.
+
+ .. seealso:: :attr:`text` property
+
+ :param force: reload all page attributes, including errors.
+ :param get_redirect: return the redirect text, do not follow the
+ redirect, do not raise an exception.
+
+ :raises NoPageError: The page does not exist.
+ :raises IsRedirectPageError: The page is a redirect.
+ :raises SectionError: The section does not exist on a page with
+ a # link.
"""
if force:
del self.latest_revision_id
@@ -519,8 +531,29 @@
@property
def text(self) -> str:
- """
- Return the current (edited) wikitext, loading it if necessary.
+ """Return the current (edited) wikitext, loading it if necessary.
+
+ This property should be prefered over :meth:`get`. If the page
+ does not exist, an empty string will be returned. For a redirect
+ it returns the redirect page content and does not raise an
+ :exc:`exceptions.IsRedirectPageError` exception.
+
+ **Example:**
+
+ >>> import pywikibot
+ >>> site = pywikibot.Site('mediawiki')
+ >>> page = pywikibot.Page(site, 'Pywikibot')
+ >>> page.text
+ '#REDIRECT[[Manual:Pywikibot]]'
+ >>> page.text = 'PWB Framework'
+ >>> page.text
+ 'PWB Framework'
+ >>> page.text = None # reload from wiki
+ >>> page.text
+ '#REDIRECT[[Manual:Pywikibot]]'
+ >>> del page.text # other way to reload from wiki
+
+ To save the modified text :meth:`save` is one possible method.
:return: text of the page
"""
@@ -534,7 +567,7 @@
return ''
@text.setter
- def text(self, value: str | None):
+ def text(self, value: str | None) -> None:
"""Update the current (edited) wikitext.
:param value: New value or None
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1016331?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I07f9ff7b270d561020fdf72c999df3641e3eda18
Gerrit-Change-Number: 1016331
Gerrit-PatchSet: 8
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: RoySmith <roy(a)panix.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged