jenkins-bot has submitted this change and it was merged.
Change subject: BUGFIX: fix for https://gerrit.wikimedia.org/r/#/c/148923/
......................................................................
BUGFIX: fix for https://gerrit.wikimedia.org/r/#/c/148923/
always variable is not previously declared
Change-Id: Ief2600ac6f320eb77511ebd35046df58f045eccc
---
M scripts/cosmetic_changes.py
1 file changed, 3 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py
index 8f916a2..34a2d4f 100755
--- a/scripts/cosmetic_changes.py
+++ b/scripts/cosmetic_changes.py
@@ -912,7 +912,8 @@
if 'comment' not in options or not options['comment']:
# Load default summary message.
- options['comment'] = i18n.twtranslate(site, 'cosmetic_changes-standalone')
+ options['comment'] = i18n.twtranslate(site,
+ 'cosmetic_changes-standalone')
if pageTitle:
gen = iter([pywikibot.Page(pywikibot.Link(t, site)) for t in pageTitle])
if not gen:
@@ -920,7 +921,7 @@
if not gen:
pywikibot.showHelp()
else:
- if not always:
+ if not options.get('always'):
answer = pywikibot.inputChoice(
warning + '\nDo you really want to continue?',
['yes', 'no'], ['y', 'n'], 'n')
--
To view, visit https://gerrit.wikimedia.org/r/149627
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ief2600ac6f320eb77511ebd35046df58f045eccc
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: standardize nowcommons.py
......................................................................
standardize nowcommons.py
- NowCommonsDeleteBot extends pywikibot.Bot
- pass options to the bot class constructor
instead of using global variables
- BREAKING: the '-autonomous' argument has been replaced
with the standard '-always'; the former is provisionally
retained for backwards compatibility
- replaced NowCommonsDeleteBot.urlname() with Page.title(asUrl=True)
- the argument parsing has been optimized
- replaced ImagePage.fileIsOnCommons() with ImagePage.fileIsShared()
- pywikibot.inputChoice() always returns the short variant, lowercase
Change-Id: I1cc6b5734237d143c8100f3c26c20d78c36924c6
---
M scripts/nowcommons.py
1 file changed, 48 insertions(+), 57 deletions(-)
Approvals:
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py
index ca91c9d..260dcfd 100644
--- a/scripts/nowcommons.py
+++ b/scripts/nowcommons.py
@@ -13,27 +13,27 @@
this script to work properly.
This script understands various command-line arguments:
- -autonomous: run automatically, do not ask any questions. All files
+ -always run automatically, do not ask any questions. All files
that qualify for deletion are deleted. Reduced screen
output.
- -replace: replace links if the files are equal and the file names
+ -replace replace links if the files are equal and the file names
differ
- -replacealways: replace links if the files are equal and the file names
+ -replacealways replace links if the files are equal and the file names
differ without asking for confirmation
- -replaceloose: Do loose replacements. This will replace all occurences
+ -replaceloose Do loose replacements. This will replace all occurences
of the name of the image (and not just explicit image
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.
- -replaceonly: Use this if you do not have a local sysop account, but do
+ -replaceonly Use this if you do not have a local sysop account, but do
wish to replace links from the NowCommons template.
- -hash: Use the hash to identify the images that are the same. It
+ -hash Use the hash to identify the images that are the same. It
doesn't work always, so the bot opens two tabs to let to
the user to check if the images are equal or not.
@@ -49,7 +49,7 @@
# (C) Wikipedian, 2006-2007
# (C) Siebrand Mazeland, 2007-2008
# (C) xqt, 2010-2014
-# (C) Pywikibot team, 2006-2013
+# (C) Pywikibot team, 2006-2014
#
# Distributed under the terms of the MIT license.
#
@@ -61,7 +61,7 @@
import webbrowser
import urllib
import pywikibot
-from pywikibot import i18n
+from pywikibot import i18n, Bot
from pywikibot import pagegenerators as pg
import image
from imagetransfer import nowCommonsMessage
@@ -181,8 +181,17 @@
}
-class NowCommonsDeleteBot:
- def __init__(self):
+class NowCommonsDeleteBot(Bot):
+ def __init__(self, **kwargs):
+ self.availableOptions.update({
+ 'replace': False,
+ 'replacealways': False,
+ 'replaceloose': False,
+ 'replaceonly': False,
+ 'use_hash': False,
+ })
+ super(NowCommonsDeleteBot, self).__init__(**kwargs)
+
self.site = pywikibot.Site()
if repr(self.site) == 'commons:commons':
sys.exit('Do not run this bot on Commons!')
@@ -240,7 +249,7 @@
choice = pywikibot.inputChoice(
u'Are the two images equal?',
['Yes', 'No'], ['y', 'N'], 'N')
- if choice.lower() in ['y', 'yes']:
+ if choice == 'y':
yield [image_local, image_commons]
else:
continue
@@ -295,16 +304,6 @@
filenameOnCommons = val[1].strip()
return filenameOnCommons
- # Function stolen from wikipedia.py and modified. Really needed?
- def urlname(self, talk_page):
- """The name of the page this Page refers to, in a form suitable for the
- URL of the page.
-
- """
- title = talk_page.replace(" ", "_")
- encodedTitle = title.encode(self.site.encoding())
- return urllib.quote(encodedTitle)
-
def run(self):
commons = pywikibot.Site('commons', 'commons')
comment = i18n.translate(self.site, nowCommonsMessage, fallback=True)
@@ -322,7 +321,7 @@
% page.title())
try:
localImagePage = pywikibot.ImagePage(self.site, page.title())
- if localImagePage.fileIsOnCommons():
+ if localImagePage.fileIsShared():
pywikibot.output(u'File is already on Commons.')
continue
md5 = localImagePage.getFileMd5Sum()
@@ -348,7 +347,7 @@
u'\"\03{lightred}%s\03{default}\" is still used in %i pages.'
% (localImagePage.title(withNamespace=False),
len(usingPages)))
- if replace is True:
+ if self.getOption('replace') is True:
pywikibot.output(
u'Replacing \"\03{lightred}%s\03{default}\" by \
\"\03{lightgreen}%s\03{default}\".'
@@ -358,22 +357,23 @@
pg.FileLinksGenerator(localImagePage),
localImagePage.title(withNamespace=False),
commonsImagePage.title(withNamespace=False),
- '', replacealways, replaceloose)
+ '', self.getOption('replacealways'),
+ self.getOption('replaceloose'))
oImageRobot.run()
# If the image is used with the urlname the
# previous function won't work
if len(list(pywikibot.ImagePage(self.site,
page.title()).usingPages())) > 0 and \
- replaceloose:
+ self.getOption('replaceloose'):
oImageRobot = image.ImageRobot(
pg.FileLinksGenerator(
localImagePage),
- self.urlname(
- localImagePage.title(
- withNamespace=False)),
+ localImagePage.title(
+ withNamespace=False, asUrl=True),
commonsImagePage.title(
withNamespace=False),
- '', replacealways, replaceloose)
+ '', self.getOption('replacealways'),
+ self.getOption('replaceloose'))
oImageRobot.run()
# refresh because we want the updated list
usingPages = len(list(pywikibot.ImagePage(
@@ -393,7 +393,7 @@
u'No page is using \"\03{lightgreen}%s\03{default}\" anymore.'
% localImagePage.title(withNamespace=False))
commonsText = commonsImagePage.get()
- if replaceonly is False:
+ if self.getOption('replaceonly') is False:
if md5 == commonsImagePage.getFileMd5Sum():
pywikibot.output(
u'The image is identical to the one on Commons.')
@@ -403,7 +403,7 @@
delete it manually after making sure that the \
old versions are not worth keeping.""")
continue
- if autonomous is False:
+ if self.getOption('always') is False:
pywikibot.output(
u'\n\n>>>> Description on \03{lightpurple}%s\03{default} <<<<\n'
% page.title())
@@ -416,10 +416,10 @@
on Commons contain all required source and license\n'
u'information?',
['yes', 'no'], ['y', 'N'], 'N')
- if choice.lower() in ['y', 'yes']:
+ if choice == 'y':
localImagePage.delete(
- comment + ' [[:commons:Image:%s]]'
- % filenameOnCommons, prompt=False)
+ '%s [[:commons:Image:%s]]'
+ % (comment, filenameOnCommons), prompt=False)
else:
localImagePage.delete(
comment + ' [[:commons:Image:%s]]'
@@ -433,31 +433,22 @@
def main():
- global autonomous
- global replace, replacealways, replaceloose, replaceonly
- global use_hash
- autonomous = False
- replace = False
- replacealways = False
- replaceloose = False
- replaceonly = False
- use_hash = False
+ options = {}
for arg in pywikibot.handleArgs():
- if arg == '-autonomous':
- autonomous = True
- if arg == '-replace':
- replace = True
- if arg == '-replacealways':
- replace = True
- replacealways = True
- if arg == '-replaceloose':
- replaceloose = True
- if arg == '-replaceonly':
- replaceonly = True
- if arg == '-hash':
- use_hash = True
- bot = NowCommonsDeleteBot()
+ if arg.startswith('-') and \
+ arg[1:] in ('always', 'replace', 'replaceloose', 'replaceonly'):
+ options[arg[1:]] = True
+ elif arg == '-replacealways':
+ options['replace'] = True
+ options['replacealways'] = True
+ elif arg == '-hash':
+ options['use_hash'] = True
+ elif arg == '-autonomous':
+ pywikibot.warning(u"The '-autonomous' argument is DEPRECATED,"
+ u" use '-always' instead.")
+ options['always'] = True
+ bot = NowCommonsDeleteBot(**options)
bot.run()
if __name__ == "__main__":
--
To view, visit https://gerrit.wikimedia.org/r/149060
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1cc6b5734237d143c8100f3c26c20d78c36924c6
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)openmailbox.org>
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: Multichill <maarten(a)mdammers.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: convert non-string items to Category objects in textlib.categoryFormat()
......................................................................
convert non-string items to Category objects in textlib.categoryFormat()
Ib0701600a300b2435ac8f2c3b8a55c89faf2c2fe introduced the use of
the .aslink() method instead of .title() to support the sortKey.
However, aslink() on Page objects works differently,
so we convert them to Categories to ensure that the correct
version of aslink() is called.
If I4e7e67ec855d366fcf90005481093de64e5465c1 is merged,
simple strings could also be passed through Category(),
with the proper 'source' argument.
IMPORTANT BUGFIX:
preserve Category-specific properties (like sortKey)
when passing the object back to the constructor
bug: 68564
Change-Id: I3a343e42ce9b9562dfaad5d2d7737dc3ebe3c369
---
M pywikibot/page.py
M pywikibot/textlib.py
2 files changed, 7 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index c6473bc..826b7dd 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -99,7 +99,10 @@
self._revisions = {}
elif isinstance(source, Page):
# copy all of source's attributes to this object
- self.__dict__ = source.__dict__
+ # without overwriting non-None values
+ self.__dict__.update((k, v) for k, v in source.__dict__.items()
+ if k not in self.__dict__ or
+ self.__dict__[k] is None)
if title:
# overwrite title
self._link = Link(title, source=source.site,
@@ -1892,11 +1895,11 @@
All parameters are the same as for Page() constructor.
"""
+ self.sortKey = sortKey
Page.__init__(self, source, title, ns=14)
if self.namespace() != 14:
raise ValueError(u"'%s' is not in the category namespace!"
% title)
- self.sortKey = sortKey
@deprecate_arg("forceInterwiki", None)
@deprecate_arg("textlink", None)
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index f9a06b0..14dc668 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -848,7 +848,8 @@
else:
catLinks = ['[[Category:%s]]' % category for category in categories]
else:
- catLinks = [category.aslink() for category in categories]
+ catLinks = [pywikibot.Category(category).aslink()
+ for category in categories]
if insite.category_on_one_line():
sep = ' '
--
To view, visit https://gerrit.wikimedia.org/r/149455
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3a343e42ce9b9562dfaad5d2d7737dc3ebe3c369
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: Russell Blau <russblau(a)imapmail.org>
Gerrit-Reviewer: jenkins-bot <>