jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/682925 )
Change subject: [tests] Fix TooManyRedirects failure for test_merriam_webster
......................................................................
[tests] Fix TooManyRedirects failure for test_merriam_webster
Catch requests.exceptions.TooManyRedirects exception as an
requested result if no Site can be created from this Url.
Bug: T281236
Change-Id: I65303f94a98319c4b028a3755bbd9072f643ff87
---
M tests/site_detect_tests.py
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
Damian: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/site_detect_tests.py b/tests/site_detect_tests.py
index 807d105..6e4d254 100644
--- a/tests/site_detect_tests.py
+++ b/tests/site_detect_tests.py
@@ -10,7 +10,7 @@
from http import HTTPStatus
from urllib.parse import urlparse
-from requests.exceptions import ConnectionError, Timeout
+from requests.exceptions import ConnectionError, Timeout, TooManyRedirects
import pywikibot
@@ -48,7 +48,7 @@
@raises AssertionError: Site under url is MediaWiki powered
"""
with self.assertRaises((AttributeError, ConnectionError, RuntimeError,
- ServerError, Timeout)) as e:
+ ServerError, Timeout, TooManyRedirects)) as e:
MWSite(url)
unittest_print('\nassertNoSite expected exception:\n{e!r}'
.format(e=e.exception))
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/682925
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: I65303f94a98319c4b028a3755bbd9072f643ff87
Gerrit-Change-Number: 682925
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Damian <atagar1(a)gmail.com>
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/+/681502 )
Change subject: [cleanup] Deprecate SelfCall classes
......................................................................
[cleanup] Deprecate SelfCall classes
These SelfCall classes were added in commit ce164aa so "site.namespaces()"
aliases to "site.namespaces". It doesn't explain why this desirable and
detracts from PEP20's 'there should be one way to do it' axiom.
SelfCall is used by BaseSite's sitename property and NamespacesDict.
NamespacesDict already deprecated its usage in 2015. Once referencing
them as functions is gone we can remove the SelfCall classes.
Bug: T281200
Change-Id: I17f5b16d3be899768bd576336478f790f4f7b4cd
---
M pywikibot/site/_namespace.py
M pywikibot/tools/__init__.py
M tests/basesite_tests.py
M tests/site_tests.py
4 files changed, 20 insertions(+), 10 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site/_namespace.py b/pywikibot/site/_namespace.py
index 8edcf5f..540ac6b 100644
--- a/pywikibot/site/_namespace.py
+++ b/pywikibot/site/_namespace.py
@@ -305,8 +305,6 @@
APISite was callable.
"""
- _own_desc = 'the namespaces property'
-
def __init__(self, namespaces):
"""Create new dict using the given namespaces."""
super().__init__()
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 13b7bff..3538673 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -1035,11 +1035,11 @@
def __call__(self):
"""Do nothing and just return itself."""
- if hasattr(self, '_own_desc'):
- issue_deprecation_warning('Calling {}'.format(self._own_desc),
- 'it directly',
- warning_class=FutureWarning,
- since='20150515')
+ issue_deprecation_warning('Referencing this attribute like a function',
+ 'it directly',
+ warning_class=FutureWarning,
+ since='20210420')
+
return self
diff --git a/tests/basesite_tests.py b/tests/basesite_tests.py
index 559020b..31a2245 100644
--- a/tests/basesite_tests.py
+++ b/tests/basesite_tests.py
@@ -8,8 +8,13 @@
import pywikibot
+from pywikibot.tools import suppress_warnings
+
from tests.aspects import DefaultSiteTestCase, TestCase, unittest
+WARN_SELF_CALL = (r'Referencing this attribute like a function '
+ r'is deprecated for .*; use it directly instead')
+
class TestBaseSiteProperties(TestCase):
@@ -81,9 +86,15 @@
self.assertIsInstance(mysite.lang, str)
self.assertEqual(mysite, pywikibot.Site(self.code, self.family))
self.assertIsInstance(mysite.user(), (str, type(None)))
- self.assertEqual(mysite.sitename(), '%s:%s' % (self.family, code))
+ self.assertEqual(mysite.sitename, '%s:%s' % (self.family, code))
self.assertIsInstance(mysite.linktrail(), str)
self.assertIsInstance(mysite.redirect(), str)
+
+ # sitename attribute could also be referenced like a function
+
+ with suppress_warnings(WARN_SELF_CALL, category=FutureWarning):
+ self.assertEqual(mysite.sitename(), '%s:%s' % (self.family, code))
+
try:
dabcat = mysite.disambcategory()
except pywikibot.Error as e:
diff --git a/tests/site_tests.py b/tests/site_tests.py
index b3362b5..971937e 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -100,8 +100,9 @@
"""Test that namespaces is callable and returns itself."""
site = self.get_site()
self.assertIs(site.namespaces(), site.namespaces)
- self.assertOneDeprecationParts('Calling the namespaces property',
- 'it directly')
+ self.assertOneDeprecationParts(
+ 'Referencing this attribute like a function',
+ 'it directly')
class TestSiteObject(DefaultSiteTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/681502
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: I17f5b16d3be899768bd576336478f790f4f7b4cd
Gerrit-Change-Number: 681502
Gerrit-PatchSet: 3
Gerrit-Owner: Damian <atagar1(a)gmail.com>
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/+/682220 )
Change subject: [doc] Update documentation
......................................................................
[doc] Update documentation
* windows --> Windows
* pywikibot --> Pywikibot
Change-Id: Icf140aa897dc2b10a2a328f574b57cf94e7e9bdc
---
M README.rst
M pywikibot/config2.py
M pywikibot/userinterfaces/win32_unicode.py
M pywikibot/version.py
M tests/tools_tests.py
5 files changed, 5 insertions(+), 5 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/README.rst b/README.rst
index f2eb8d4..4ebf00f 100644
--- a/README.rst
+++ b/README.rst
@@ -103,7 +103,7 @@
-------------------------------------------------------------------------------------------
-For more documentation on pywikibot see our `docs <https://doc.wikimedia.org/pywikibot/>`_.
+For more documentation on Pywikibot see our `docs <https://doc.wikimedia.org/pywikibot/>`_.
.. include:: pywikibot/DIRECTORIES.rst
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index f137fd1..3c5e45a 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -1040,7 +1040,7 @@
_ConfigurationDeprecationWarning)
# If we cannot auto-detect the console encoding (e.g. when piping data)
-# assume utf-8. On Linux, this will typically be correct; on windows,
+# assume utf-8. On Linux, this will typically be correct; on Windows,
# this can be an issue when piping through more. However, the behavior
# when redirecting to a file utf-8 is more reasonable.
diff --git a/pywikibot/userinterfaces/win32_unicode.py b/pywikibot/userinterfaces/win32_unicode.py
index 79bdb99..9654a87 100755
--- a/pywikibot/userinterfaces/win32_unicode.py
+++ b/pywikibot/userinterfaces/win32_unicode.py
@@ -3,7 +3,7 @@
# (C) Pywikibot team, 2012-2018
#
##############################################
-# Support for unicode in windows cmd.exe
+# Support for unicode in Windows cmd.exe
# Posted on Stack Overflow [1], available under CC-BY-SA 3.0 [2]
#
# Question: "Windows cmd encoding change causes Python crash" [3] by Alex [4],
diff --git a/pywikibot/version.py b/pywikibot/version.py
index a71772b..ef44279 100644
--- a/pywikibot/version.py
+++ b/pywikibot/version.py
@@ -248,7 +248,7 @@
try:
subprocess.Popen([cmd], stdout=subprocess.PIPE).communicate()
except OSError:
- # some windows git versions provide git.cmd instead of git.exe
+ # some Windows git versions provide git.cmd instead of git.exe
cmd = 'git.cmd'
with open(os.path.join(_program_dir, '.git/config'), 'r') as f:
diff --git a/tests/tools_tests.py b/tests/tools_tests.py
index a5da99d..e2c7e98 100644
--- a/tests/tools_tests.py
+++ b/tests/tools_tests.py
@@ -643,7 +643,7 @@
r"""Test calculator of sha of a file.
There are two possible hash values for each test. The second one is for
- files with windows line endings (\r\n).
+ files with Windows line endings (\r\n).
"""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/682220
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: Icf140aa897dc2b10a2a328f574b57cf94e7e9bdc
Gerrit-Change-Number: 682220
Gerrit-PatchSet: 12
Gerrit-Owner: Meno25 <meno25mail(a)gmail.com>
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/+/681782 )
Change subject: [bugfix] Fix nowcommons test failure
......................................................................
[bugfix] Fix nowcommons test failure
By moving the nowcommons script in commit fd16ca1ff it got unit test coverage.
Fixing its test failure...
% python -m tests.script_tests TestScriptSimulate
...
======================================================================
FAIL: test_nowcommons (tests.script_tests.TestScriptSimulate)
Test running nowcommons -simulate.
----------------------------------------------------------------------
Traceback (most recent call last):
File "pywikibot/tests/script_tests.py", line 243, in testScript
self.assertIn('Use -help for further information.',
AssertionError: 'Use -help for further information.' not found in ['No
transcluded files found for NowCommons.', '', '0 pages read', '0 pages
written', '0 pages skipped', 'Script terminated successfully.']
----------------------------------------------------------------------
Change-Id: If504d72e3e67a31b3fb3d32fcb36a17deb40752d
---
M tests/script_tests.py
1 file changed, 1 insertion(+), 0 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/script_tests.py b/tests/script_tests.py
index 4e7cb11..9572dc1 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -103,6 +103,7 @@
# script_input['interwiki'] above lists a title that should not exist
'interwiki': 'does not exist. Skipping.',
'login': 'Logged in on ',
+ 'nowcommons': 'No transcluded files found for NowCommons.',
'pagefromfile': 'Please enter the file name',
'parser_function_count': 'Hold on, this will need some time.',
'replace': 'Press Enter to use this automatic message',
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/681782
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: If504d72e3e67a31b3fb3d32fcb36a17deb40752d
Gerrit-Change-Number: 681782
Gerrit-PatchSet: 1
Gerrit-Owner: Damian <atagar1(a)gmail.com>
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/+/681641 )
Change subject: [doc] Minor update of documentation
......................................................................
[doc] Minor update of documentation
* doesn't has --> doesn't have
Change-Id: I2c5286b41681db3f8df1b6705c737d10ce7d7882
---
M scripts/category.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/category.py b/scripts/category.py
index 1b3f257..31823df 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -592,7 +592,7 @@
self.title_regex = title_regex
self.history = history
self.pagesonly = pagesonly
- # if that page doesn't has a Wikibase
+ # if that page doesn't have a Wikibase
self.wikibase = wikibase and self.site.has_data_repository
self.allow_split = allow_split
self.move_together = move_together
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/681641
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: I2c5286b41681db3f8df1b6705c737d10ce7d7882
Gerrit-Change-Number: 681641
Gerrit-PatchSet: 2
Gerrit-Owner: Meno25 <meno25mail(a)gmail.com>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
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/+/681164 )
Change subject: [doc] Update documentation
......................................................................
[doc] Update documentation
* wikipedia --> Wikipedia
* wikibase --> Wikibase
** See https://en.wikipedia.org/wiki/Wikibase
Change-Id: I4f8b19e7cb5e2750d597afaa6713bb1c420f5bec
---
M README.rst
M pywikibot/page/__init__.py
M pywikibot/pagegenerators.py
M pywikibot/site/_apisite.py
M scripts/category.py
M scripts/newitem.py
M scripts/redirect.py
7 files changed, 15 insertions(+), 15 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/README.rst b/README.rst
index 8872f7d..f2eb8d4 100644
--- a/README.rst
+++ b/README.rst
@@ -96,7 +96,7 @@
import pywikibot
site = pywikibot.Site('wikipedia:en')
- repo = site.data_repository() # the wikibase repository for given site
+ repo = site.data_repository() # the Wikibase repository for given site
page = repo.page_from_repository('Q91') # create a local page for the given item
item = pywikibot.ItemPage(repo, 'Q91') # a repository item
data = item.get() # get all item data from repository for this item
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 967864f..1abaef8 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -2175,15 +2175,15 @@
"""
Return the first best Claim for this page.
- Return the first 'preferred' ranked Claim specified by wikibase
+ Return the first 'preferred' ranked Claim specified by Wikibase
property or the first 'normal' one otherwise.
@param prop: property id, "P###"
- @return: Claim object given by wikibase property number
+ @return: Claim object given by Wikibase property number
for this page object.
@rtype: pywikibot.Claim or None
- @raises UnknownExtension: site has no wikibase extension
+ @raises UnknownExtension: site has no Wikibase extension
"""
def find_best_claim(claims):
"""Find the first best ranked claim."""
@@ -3841,9 +3841,9 @@
Return ID as title of the ItemPage.
If the ItemPage was lazy-loaded via ItemPage.fromPage, this method
- will fetch the wikibase item ID for the page, potentially raising
+ will fetch the Wikibase item ID for the page, potentially raising
NoPage with the page on the linked wiki if it does not exist, or
- does not have a corresponding wikibase item ID.
+ does not have a corresponding Wikibase item ID.
This method also refreshes the title if the id property was set.
i.e. item.id = 'Q60'
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index df8b3e5..618d2b6 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -2234,7 +2234,7 @@
def WikibaseItemFilterPageGenerator(generator, has_item: bool = True,
show_filtered: bool = False):
"""
- A wrapper generator used to exclude if page has a wikibase item or not.
+ A wrapper generator used to exclude if page has a Wikibase item or not.
@param generator: Generator to wrap.
@type generator: generator
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index 38e40f5..3f4e611 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -1015,17 +1015,17 @@
def page_from_repository(self, item):
"""
- Return a Page for this site object specified by wikibase item.
+ Return a Page for this site object specified by Wikibase item.
@param item: id number of item, "Q###",
@type item: str
- @return: Page, or Category object given by wikibase item number
+ @return: Page, or Category object given by Wikibase item number
for this site object.
@rtype: pywikibot.Page or None
- @raises pywikibot.exceptions.UnknownExtension: site has no wikibase
+ @raises pywikibot.exceptions.UnknownExtension: site has no Wikibase
extension
- @raises NotimplementedError: method not implemented for a wikibase site
+ @raises NotimplementedError: method not implemented for a Wikibase site
"""
if not self.has_data_repository:
raise UnknownExtension(
diff --git a/scripts/category.py b/scripts/category.py
index e9c4ddf..1b3f257 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -51,7 +51,7 @@
-hist - Creates a nice wikitable on the talk page of target category
that contains detailed page history of the source category.
-nodelete - Don't delete the old category after move.
- -nowb - Don't update the wikibase repository.
+ -nowb - Don't update the Wikibase repository.
-allowsplit - If that option is not set, it only moves the talk and main
page together.
-mvtogether - Only move the pages/subcategories of a category, if the
@@ -592,7 +592,7 @@
self.title_regex = title_regex
self.history = history
self.pagesonly = pagesonly
- # if that page doesn't has a wikibase
+ # if that page doesn't has a Wikibase
self.wikibase = wikibase and self.site.has_data_repository
self.allow_split = allow_split
self.move_together = move_together
diff --git a/scripts/newitem.py b/scripts/newitem.py
index b1fedb4..33d27e5 100755
--- a/scripts/newitem.py
+++ b/scripts/newitem.py
@@ -14,7 +14,7 @@
-pageage The minimum number of days that has passed since the page was
created.
--touch Do a null edit on every page which has a wikibase item.
+-touch Do a null edit on every page which has a Wikibase item.
Be careful, this option can trigger edit rates or captchas
if your account is not autoconfirmed.
diff --git a/scripts/redirect.py b/scripts/redirect.py
index fa95c4f..9c0b923 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -57,7 +57,7 @@
-sdtemplate:x Add the speedy deletion template string including brackets.
This enables overriding the default template via i18n or
- to enable speedy deletion for projects other than wikipedias.
+ to enable speedy deletion for projects other than Wikipedias.
-always Don't prompt you for each replacement.
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/681164
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: I4f8b19e7cb5e2750d597afaa6713bb1c420f5bec
Gerrit-Change-Number: 681164
Gerrit-PatchSet: 6
Gerrit-Owner: Meno25 <meno25mail(a)gmail.com>
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/+/680693 )
Change subject: [scripts] nowcommons.py and image.py to be restored back from archive
......................................................................
[scripts] nowcommons.py and image.py to be restored back from archive
other changes:
- some cosmetic changes in nowcommons.py were performed to pass CI
- copyright dates updated to 2021
Change-Id: I863c389beca59d999169c92e0990b4a130b28336
---
M docs/scripts/scripts.rst
M scripts/README.rst
R scripts/image.py
R scripts/nowcommons.py
4 files changed, 78 insertions(+), 69 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/scripts/scripts.rst b/docs/scripts/scripts.rst
index 9036b2e..90b7963 100644
--- a/docs/scripts/scripts.rst
+++ b/docs/scripts/scripts.rst
@@ -107,6 +107,11 @@
.. automodule:: scripts.illustrate_wikidata
+image script
+------------
+
+.. automodule:: scripts.image
+
imagetransfer script
--------------------
@@ -147,6 +152,11 @@
.. automodule:: scripts.noreferences
+nowcommons script
+-----------------
+
+.. automodule:: scripts.nowcommons
+
pagefromfile script
-------------------
diff --git a/scripts/README.rst b/scripts/README.rst
index efac973..801fedd 100644
--- a/scripts/README.rst
+++ b/scripts/README.rst
@@ -64,6 +64,8 @@
+------------------------+---------------------------------------------------------+
| illustrate_wikidata.py | Bot to add images to Wikidata items. |
+------------------------+---------------------------------------------------------+
+ | image.py | Script to replace transclusions of files |
+ +------------------------+---------------------------------------------------------+
| imagetransfer.py | Given a wiki page, check the interwiki links for |
| | images, and let the user choose among them for |
| | images to upload. |
@@ -88,6 +90,8 @@
| | although a <ref> tag is present, and in that case adds |
| | a new references section. |
+------------------------+---------------------------------------------------------+
+ | nowcommons.py | This bot can delete images with NowCommons template. |
+ +------------------------+---------------------------------------------------------+
| pagefromfile.py | This bot takes its input from a file that contains a |
| | number of pages to be put on the wiki. |
+------------------------+--+------------------------------------------------------+
@@ -179,9 +183,6 @@
| | with a template. |
+------------------------++--------------------------------------------------------+
| freebasemappingupload.py| Script to upload the mappings of Freebase to Wikidata. |
- +------------------------++--------------------------------------------------------+
- | image.py | This script can be used to change one image to another |
- | | or remove an image entirely. |
+------------------------+---------------------------------------------------------+
| imagecopy.py | Copies images from a Wikimedia wiki to Commons. |
+------------------------+---------------------------------------------------------+
@@ -209,8 +210,6 @@
| ndashredir.py | Creates hyphenated redirects to articles with n dash |
| | or m dash in their title. |
+------------------------+---------------------------------------------------------+
- | nowcommons.py | This bot can delete images with NowCommons template. |
- +------------------------+---------------------------------------------------------+
| piper.py | Pipes article text through external program(s) on |
| | STDIN and collects its STDOUT which is used as the |
| | new article text if it differs from the original. |
diff --git a/scripts/archive/image.py b/scripts/image.py
similarity index 99%
rename from scripts/archive/image.py
rename to scripts/image.py
index ff60fd4..aeb6f82 100755
--- a/scripts/archive/image.py
+++ b/scripts/image.py
@@ -37,7 +37,7 @@
"""
#
-# (C) Pywikibot team, 2013-2020
+# (C) Pywikibot team, 2013-2021
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/archive/nowcommons.py b/scripts/nowcommons.py
similarity index 72%
rename from scripts/archive/nowcommons.py
rename to scripts/nowcommons.py
index 39bf2e8..ab03ef0 100755
--- a/scripts/archive/nowcommons.py
+++ b/scripts/nowcommons.py
@@ -25,7 +25,7 @@
differ without asking for confirmation
-replaceloose Do loose replacements. This will replace all occurrences
- of the name of the image (and not just explicit image
+ of the name of the file (and not just explicit file
syntax). This should work to catch all instances of the
file, including where it is used as a template parameter
or in galleries. However, it can also make more mistakes.
@@ -46,7 +46,7 @@
will exit.
"""
#
-# (C) Pywikibot team, 2006-2020
+# (C) Pywikibot team, 2006-2021
#
# Distributed under the terms of the MIT license.
#
@@ -61,7 +61,7 @@
from scripts.image import ImageRobot as ImageBot
-nowCommons = {
+nowcommons = {
'_default': [
'NowCommons'
],
@@ -162,7 +162,7 @@
],
}
-namespaceInTemplate = [
+namespace_in_template = [
'en',
'ia',
'it',
@@ -198,18 +198,18 @@
self.summary = i18n.twtranslate(self.site,
'imagetransfer-nowcommons_notice')
- def ncTemplates(self):
+ def nc_templates_list(self):
"""Return nowcommons templates."""
- if self.site.lang in nowCommons:
- return nowCommons[self.site.lang]
- return nowCommons['_default']
+ if self.site.lang in nowcommons:
+ return nowcommons[self.site.lang]
+ return nowcommons['_default']
@property
def nc_templates(self):
"""A set of now commons template Page instances."""
if not hasattr(self, '_nc_templates'):
self._nc_templates = {pywikibot.Page(self.site, title, ns=10)
- for title in self.ncTemplates()}
+ for title in self.nc_templates_list()}
return self._nc_templates
@property
@@ -223,36 +223,36 @@
gen = pg.PreloadingGenerator(gen)
return gen
- def findFilenameOnCommons(self, localImagePage):
+ def find_file_on_commons(self, local_file_page):
"""Find filename on Commons."""
- for templateName, params in localImagePage.templatesWithParams():
- if templateName not in self.nc_templates:
+ for template_name, params in local_file_page.templatesWithParams():
+ if template_name not in self.nc_templates:
continue
if not params:
- filenameOnCommons = localImagePage.title(with_ns=False)
- elif self.site.lang in namespaceInTemplate:
+ file_on_commons = local_file_page.title(with_ns=False)
+ elif self.site.lang in namespace_in_template:
skip = False
- filenameOnCommons = None
+ file_on_commons = None
for par in params:
val = par.split('=')
if len(val) == 1 and not skip:
- filenameOnCommons = par[par.find(':') + 1:]
+ file_on_commons = par[par.find(':') + 1:]
break
if val[0].strip() == '1':
- filenameOnCommons = \
+ file_on_commons = \
val[1].strip()[val[1].strip().find(':') + 1:]
break
skip = True
- if not filenameOnCommons:
- filenameOnCommons = localImagePage.title(with_ns=False)
+ if not file_on_commons:
+ file_on_commons = local_file_page.title(with_ns=False)
else:
val = params[0].split('=')
if len(val) == 1:
- filenameOnCommons = params[0].strip()
+ file_on_commons = params[0].strip()
else:
- filenameOnCommons = val[1].strip()
- return filenameOnCommons
+ file_on_commons = val[1].strip()
+ return file_on_commons
def run(self):
"""Run the bot."""
@@ -262,36 +262,36 @@
for page in self.generator:
self.current_page = page
try:
- localImagePage = pywikibot.FilePage(self.site, page.title())
- if localImagePage.file_is_shared():
+ local_file_page = pywikibot.FilePage(self.site, page.title())
+ if local_file_page.file_is_shared():
pywikibot.output('File is already on Commons.')
continue
- sha1 = localImagePage.latest_file_info.sha1
- filenameOnCommons = self.findFilenameOnCommons(localImagePage)
- if not filenameOnCommons:
+ sha1 = local_file_page.latest_file_info.sha1
+ file_on_commons = self.find_file_on_commons(local_file_page)
+ if not file_on_commons:
pywikibot.output('NowCommons template not found.')
continue
- commonsImagePage = pywikibot.FilePage(commons, 'Image:'
- + filenameOnCommons)
- if (localImagePage.title(with_ns=False)
- != commonsImagePage.title(with_ns=False)):
- usingPages = list(localImagePage.usingPages())
- if usingPages and usingPages != [localImagePage]:
+ commons_file_page = pywikibot.FilePage(commons, 'File:'
+ + file_on_commons)
+ if (local_file_page.title(with_ns=False)
+ != commons_file_page.title(with_ns=False)):
+ using_pages = list(local_file_page.using_pages())
+ if using_pages and using_pages != [local_file_page]:
pywikibot.output(color_format(
'"{lightred}{0}{default}" '
'is still used in {1} pages.',
- localImagePage.title(with_ns=False),
- len(usingPages)))
+ local_file_page.title(with_ns=False),
+ len(using_pages)))
if self.opt.replace is True:
pywikibot.output(color_format(
'Replacing "{lightred}{0}{default}" by '
'"{lightgreen}{1}{default}\".',
- localImagePage.title(with_ns=False),
- commonsImagePage.title(with_ns=False)))
+ local_file_page.title(with_ns=False),
+ commons_file_page.title(with_ns=False)))
bot = ImageBot(
- pg.FileLinksGenerator(localImagePage),
- localImagePage.title(with_ns=False),
- commonsImagePage.title(with_ns=False),
+ pg.FileLinksGenerator(local_file_page),
+ local_file_page.title(with_ns=False),
+ commons_file_page.title(with_ns=False),
'', self.opt.replacealways,
self.opt.replaceloose)
bot.run()
@@ -299,20 +299,20 @@
# previous function won't work
is_used = bool(list(pywikibot.FilePage(
self.site,
- page.title()).usingPages(total=1)))
+ page.title()).using_pages(total=1)))
if is_used and self.opt.replaceloose:
bot = ImageBot(
pg.FileLinksGenerator(
- localImagePage),
- localImagePage.title(
+ local_file_page),
+ local_file_page.title(
with_ns=False, as_url=True),
- commonsImagePage.title(with_ns=False),
+ commons_file_page.title(with_ns=False),
'', self.opt.replacealways,
self.opt.replaceloose)
bot.run()
# refresh because we want the updated list
- usingPages = len(list(pywikibot.FilePage(
- self.site, page.title()).usingPages()))
+ using_pages = len(list(pywikibot.FilePage(
+ self.site, page.title()).using_pages()))
else:
pywikibot.output('Please change them manually.')
@@ -320,15 +320,15 @@
pywikibot.output(color_format(
'No page is using "{lightgreen}{0}{default}" '
'anymore.',
- localImagePage.title(with_ns=False)))
- commonsText = commonsImagePage.get()
+ local_file_page.title(with_ns=False)))
+ commons_text = commons_file_page.get()
if self.opt.replaceonly is False:
- if sha1 == commonsImagePage.latest_file_info.sha1:
+ if sha1 == commons_file_page.latest_file_info.sha1:
pywikibot.output(
- 'The image is identical to the one on Commons.')
- if len(localImagePage.get_file_history()) > 1:
+ 'The file is identical to the one on Commons.')
+ if len(local_file_page.get_file_history()) > 1:
pywikibot.output(
- 'This image has a version history. Please '
+ 'This file has a version history. Please '
'delete it manually after making sure that '
'the old versions are not worth keeping.')
continue
@@ -337,26 +337,26 @@
'\n\n>>>> Description on {lightpurple}%s'
'{default} <<<<\n')
pywikibot.output(format_str % page.title())
- pywikibot.output(localImagePage.get())
+ pywikibot.output(local_file_page.get())
pywikibot.output(format_str %
- commonsImagePage.title())
- pywikibot.output(commonsText)
+ commons_file_page.title())
+ pywikibot.output(commons_text)
if pywikibot.input_yn(
'Does the description on Commons contain '
'all required source and license\n'
'information?',
default=False, automatic_quit=False):
- localImagePage.delete(
- '{0} [[:commons:Image:{1}]]'
- .format(comment, filenameOnCommons),
+ local_file_page.delete(
+ '{0} [[:commons:File:{1}]]'
+ .format(comment, file_on_commons),
prompt=False)
else:
- localImagePage.delete(
- comment + ' [[:commons:Image:{0}]]'
- .format(filenameOnCommons),
+ local_file_page.delete(
+ comment + ' [[:commons:File:{0}]]'
+ .format(file_on_commons),
prompt=False)
else:
- pywikibot.output('The image is not identical to '
+ pywikibot.output('The file is not identical to '
'the one on Commons.')
except (pywikibot.NoPage, pywikibot.IsRedirectPage) as e:
pywikibot.output('{0}'.format(e[0]))
@@ -365,7 +365,7 @@
self._treat_counter += 1
if not self._treat_counter:
pywikibot.output('No transcluded files found for {0}.'
- .format(self.ncTemplates()[0]))
+ .format(self.nc_templates_list()[0]))
self.exit()
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/680693
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: I863c389beca59d999169c92e0990b4a130b28336
Gerrit-Change-Number: 680693
Gerrit-PatchSet: 12
Gerrit-Owner: Rubin <rubin.happy(a)gmail.com>
Gerrit-Assignee: Rubin <rubin.happy(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged