Build Update for wikimedia/pywikibot-core
-------------------------------------
Build: #3608
Status: Errored
Duration: 30 minutes and 36 seconds
Commit: 7341ca8 (master)
Author: Mpaa
Message: replace.py: add get_inside_exception to ReplacementListEntry
ReplacementListEntry inherits from ReplacementBase, it it does not
inherit get_inside_exception from Replacement.
Bug: T144697
Change-Id: Ibcee8691ceae2ec2c2c3678960527c14c55fb142
View the changeset: https://github.com/wikimedia/pywikibot-core/compare/81dd970b3526...7341ca86…
View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/157474513
--
You can configure recipients for build notifications in your .travis.yml file. See https://docs.travis-ci.com/user/notifications
jenkins-bot has submitted this change and it was merged.
Change subject: [IMPR] Simplify returnOlderTime()
......................................................................
[IMPR] Simplify returnOlderTime()
- rename returnOlderTime to important_image because the method does
return the most important image i.e. the most used or oldest
but not any time information
- return a FilePage object instead a title
- remove obsolete timeListGiven as data is included in listGiven
- use Page object in listGiven instead of the title
- use enumerate for counting
- use max() function to find the oldest image
- rename num_older for better readability
- add some doc for readability
- use FilePage from important_image later in the script
- use its title method instead of throw parts together
- also use title method for dup_page to collect the titles
- remove trivial doc strings
Change-Id: I9022c31d957f9afd67408de96184b4d769862472
---
M scripts/checkimages.py
1 file changed, 47 insertions(+), 52 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index 02e9a0b..375fa33 100755
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -807,35 +807,31 @@
for element in self.load(pageHiddenText):
self.hiddentemplates.add(pywikibot.Page(self.site, element))
- def returnOlderTime(self, listGiven, timeListGiven):
- """Get some time and return the oldest of them."""
- num = 0
- num_older = None
- max_usage = 0
- for element in listGiven:
- imageName = element[1]
- imagePage = pywikibot.FilePage(self.site, imageName)
- imageUsage = [page for page in imagePage.usingPages()]
- if len(imageUsage) > 0 and len(imageUsage) > max_usage:
- max_usage = len(imageUsage)
- num_older = num
- num += 1
+ def important_image(self, listGiven):
+ """
+ Get tuples of image and time, return the most used or oldest image.
- if num_older:
- return listGiven[num_older][1]
+ @param listGiven: a list of tuples which hold seconds and FilePage
+ @type listGiven: list
+ @return: the most used or oldest image
+ @rtype: FilePage
+ """
+ # find the most used image
+ inx_found = None # index of found image
+ max_usage = 0 # hold max amount of using pages
+ for num, element in enumerate(listGiven):
+ image = element[1]
+ image_used = len([page for page in image.usingPages()])
+ if image_used > max_usage:
+ max_usage = image_used
+ inx_found = num
- for element in listGiven:
- time = element[0]
- imageName = element[1]
- not_the_oldest = False
+ if inx_found is not None:
+ return listGiven[inx_found][1]
- for time_selected in timeListGiven:
- if time > time_selected:
- not_the_oldest = True
- break
-
- if not not_the_oldest:
- return imageName
+ # find the oldest image
+ sec, image = max(listGiven, key=lambda element: element[0])
+ return image
@deprecated('Page.revision_count()')
def countEdits(self, pagename, userlist):
@@ -928,7 +924,6 @@
'count': len(duplicates) - 1}))
if dupText and dupRegex:
time_image_list = []
- time_list = []
for dup_page in duplicates:
if (dup_page.title(asUrl=True) != self.image.title(asUrl=True) or
@@ -939,10 +934,8 @@
continue
data = self.timestamp.timetuple()
data_seconds = time.mktime(data)
- time_image_list.append([data_seconds, dup_page.title()])
- time_list.append(data_seconds)
- older_image = self.returnOlderTime(time_image_list, time_list)
- Page_older_image = pywikibot.FilePage(self.site, older_image)
+ time_image_list.append([data_seconds, dup_page])
+ Page_older_image = self.important_image(time_image_list)
older_page_text = Page_older_image.text
# And if the images are more than two?
string = ''
@@ -950,43 +943,42 @@
for dup_page in duplicates:
if dup_page == Page_older_image:
- # the older image, not report also this as duplicate
+ # the most used or oldest image
+ # not report also this as duplicate
continue
try:
DupPageText = dup_page.text
except pywikibot.NoPage:
- continue # The page doesn't exists
+ continue
- duplicate = dup_page.title()
if not (re.findall(dupRegex, DupPageText) or
re.findall(dupRegex, older_page_text)):
pywikibot.output(
u'%s is a duplicate and has to be tagged...'
- % duplicate)
- images_to_tag_list.append(duplicate)
- string += u"*[[:%s%s]]\n" % (self.image_namespace,
- duplicate)
+ % dup_page)
+ images_to_tag_list.append(dup_page.title())
+ string += '* {0}\n'.format(
+ dup_page.title(asLink=True, textlink=True))
else:
pywikibot.output(
u"Already put the dupe-template in the files's page"
u" or in the dupe's page. Skip.")
return # Ok - Let's continue the checking phase
- older_image_ns = u'%s%s' % (self.image_namespace, older_image)
-
# true if the image are not to be tagged as dupes
only_report = False
# put only one image or the whole list according to the request
if u'__images__' in dupText:
- text_for_the_report = re.sub(r'__images__',
- r'\n%s*[[:%s]]\n'
- % (string, older_image_ns),
- dupText)
+ text_for_the_report = dupText.replace(
+ '__images__',
+ '\n{0}* {1}\n'.format(
+ string,
+ Page_older_image.title(asLink=True, textlink=True)))
else:
- text_for_the_report = re.sub(r'__image__',
- r'%s' % older_image_ns,
- dupText)
+ text_for_the_report = dupText.replace(
+ '__image__',
+ Page_older_image.title(asLink=True, textlink=True))
# Two iteration: report the "problem" to the user only once
# (the last)
@@ -1021,10 +1013,13 @@
not dupTalkText:
only_report = True
else:
- self.report(text_for_the_report, images_to_tag_list[-1],
- dupTalkText % (older_image_ns, string),
- dupTalkHead, commTalk=dupComment_talk,
- commImage=dupComment_image, unver=True)
+ self.report(
+ text_for_the_report, images_to_tag_list[-1],
+ dupTalkText
+ % (Page_older_image.title(withNamespace=True),
+ string),
+ dupTalkHead, commTalk=dupComment_talk,
+ commImage=dupComment_image, unver=True)
if self.duplicatesReport or only_report:
if only_report:
@@ -1046,7 +1041,7 @@
if not result:
return True # If Errors, exit (but continue the check)
- if older_image != self.imageName:
+ if Page_older_image.title() != self.imageName:
# The image is a duplicate, it will be deleted. So skip the
# check-part, useless
return
--
To view, visit https://gerrit.wikimedia.org/r/281612
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9022c31d957f9afd67408de96184b4d769862472
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <Ladsgroup(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
Build Update for wikimedia/pywikibot-core
-------------------------------------
Build: #3606
Status: Errored
Duration: 29 minutes and 34 seconds
Commit: 34abac3 (master)
Author: xqt
Message: [bugfix] omit mode 600 warning for non-unix platforms
- mode 600 is availlable for unix platforms only.
Therefor re-read the changes and inform the user.
Bug: T144157
Change-Id: I1bfac31cee201dbfe5b595fb7606663ec13f54f4
View the changeset: https://github.com/wikimedia/pywikibot-core/compare/cac2a99bede7...34abac3b…
View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/157323793
--
You can configure recipients for build notifications in your .travis.yml file. See https://docs.travis-ci.com/user/notifications
Build Update for wikimedia/pywikibot-core
-------------------------------------
Build: #3604
Status: Errored
Duration: 28 minutes and 46 seconds
Commit: 2e63e23 (master)
Author: xqt
Message: [bugfix] Bot class arguments for constructor
Bot class arguments for constructor should be called as keyword argument
Bot class handles 'site' and ' always' as keyword arguments. In replace.py
instantiating the bot uses postional argument which breaks this rule and
derived bots may be break if not all (positional) arguments are given.
- instantiate ReplaceRobot with keyword arguments for 'always' and 'site'
handled by bot class to allow other bots to use this special bot.
- catch them with **kwargs
- remove unused and deprecated acceptall variable
- change parameter description for ReplaceRobot constructor, markup for epydoc
- move __init__ doc to class because doc strings of hidden methods aren't
shown in epydoc's documentation.
- this also solves the 2nd warning issue of https://gerrit.wikimedia.org/r/#/c/266321/
Bug: T125046
Bug: T125049
Change-Id: I23570783fda9f497a6f57aaa8f5e17895534af50
View the changeset: https://github.com/wikimedia/pywikibot-core/compare/352d9881bb76...2e63e235…
View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/157299307
--
You can configure recipients for build notifications in your .travis.yml file. See https://docs.travis-ci.com/user/notifications
jenkins-bot has submitted this change and it was merged.
Change subject: [bugfix] Bot class arguments for constructor
......................................................................
[bugfix] Bot class arguments for constructor
Bot class arguments for constructor should be called as keyword argument
Bot class handles 'site' and ' always' as keyword arguments. In replace.py
instantiating the bot uses postional argument which breaks this rule and
derived bots may be break if not all (positional) arguments are given.
- instantiate ReplaceRobot with keyword arguments for 'always' and 'site'
handled by bot class to allow other bots to use this special bot.
- catch them with **kwargs
- remove unused and deprecated acceptall variable
- change parameter description for ReplaceRobot constructor, markup for epydoc
- move __init__ doc to class because doc strings of hidden methods aren't
shown in epydoc's documentation.
- this also solves the 2nd warning issue of https://gerrit.wikimedia.org/r/#/c/266321/
Bug: T125046
Bug: T125049
Change-Id: I23570783fda9f497a6f57aaa8f5e17895534af50
---
M scripts/replace.py
1 file changed, 51 insertions(+), 47 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/replace.py b/scripts/replace.py
index 48fd15d..e03d935 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -128,7 +128,7 @@
"""
#
# (C) Daniel Herding, 2004-2012
-# (C) Pywikibot team, 2004-2015
+# (C) Pywikibot team, 2004-2016
#
# Distributed under the terms of the MIT license.
#
@@ -494,53 +494,58 @@
class ReplaceRobot(Bot):
- """A bot that can do text replacements."""
+ """A bot that can do text replacements.
+
+ @param generator: generator that yields Page objects
+ @type generator: generator
+ @param replacements: a list of Replacement instances or sequences of
+ length 2 with the original text (as a compiled regular expression)
+ and replacement text (as a string).
+ @type replacements: list
+ @param exceptions: a dictionary which defines when not to change an
+ occurrence. This dictionary can have these keys:
+
+ title
+ A list of regular expressions. All pages with titles that
+ are matched by one of these regular expressions are skipped.
+ text-contains
+ A list of regular expressions. All pages with text that
+ contains a part which is matched by one of these regular
+ expressions are skipped.
+ inside
+ A list of regular expressions. All occurrences are skipped which
+ lie within a text region which is matched by one of these
+ regular expressions.
+ inside-tags
+ A list of strings. These strings must be keys from the
+ exceptionRegexes dictionary in textlib.replaceExcept().
+
+ @type exceptions: dict
+ @param allowoverlap: when matches overlap, all of them are replaced.
+ @type allowoverlap: bool
+ @param recursive: Recurse replacement as long as possible.
+ @type recursice: bool
+ @warning: Be careful, this might lead to an infinite loop.
+ @param addedCat: category to be added to every page touched
+ @type addedCat: pywikibot.Category or str or None
+ @param sleep: slow down between processing multiple regexes
+ @type sleep: int
+ @param summary: Set the summary message text bypassing the default
+ @type summary: str
+ @keyword always: the user won't be prompted before changes are made
+ @type keyword: bool
+ @keyword site: Site the bot is working on.
+ @warning: site parameter should be passed to constructor.
+ Otherwise the bot takes the current site and warns the operator
+ about the missing site
+ """
@deprecated_args(acceptall='always')
def __init__(self, generator, replacements, exceptions={},
- always=False, allowoverlap=False, recursive=False,
- addedCat=None, sleep=None, summary='', site=None, **kwargs):
- """
- Constructor.
-
- Arguments:
- * generator - A generator that yields Page objects.
- * replacements - A list of Replacement instances or sequences of
- length 2 with the original text (as a compiled
- regular expression) and replacement text (as a
- string).
- * exceptions - A dictionary which defines when not to change an
- occurrence. See below.
- * always - If True, the user won't be prompted before changes
- are made.
- * allowoverlap - If True, when matches overlap, all of them are
- replaced.
- * addedCat - If set to a value, add this category to every page
- touched.
- It can be a string or a Category object.
-
- Structure of the exceptions dictionary:
- This dictionary can have these keys:
-
- title
- A list of regular expressions. All pages with titles that
- are matched by one of these regular expressions are skipped.
- text-contains
- A list of regular expressions. All pages with text that
- contains a part which is matched by one of these regular
- expressions are skipped.
- inside
- A list of regular expressions. All occurrences are skipped which
- lie within a text region which is matched by one of these
- regular expressions.
- inside-tags
- A list of strings. These strings must be keys from the
- exceptionRegexes dictionary in textlib.replaceExcept().
-
- """
+ allowoverlap=False, recursive=False, addedCat=None,
+ sleep=None, summary='', **kwargs):
+ """Constructor."""
super(ReplaceRobot, self).__init__(generator=generator,
- always=always,
- site=site,
**kwargs)
for i, replacement in enumerate(replacements):
@@ -554,7 +559,6 @@
replacement[1])
self.replacements = replacements
self.exceptions = exceptions
- self.acceptall = always # deprecated
self.allowoverlap = allowoverlap
self.recursive = recursive
@@ -1130,9 +1134,9 @@
return False
preloadingGen = pagegenerators.PreloadingGenerator(gen)
- bot = ReplaceRobot(preloadingGen, replacements, exceptions, acceptall,
+ bot = ReplaceRobot(preloadingGen, replacements, exceptions,
allowoverlap, recursive, add_cat, sleep, edit_summary,
- site)
+ always=acceptall, site=site)
site.login()
bot.run()
--
To view, visit https://gerrit.wikimedia.org/r/266998
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I23570783fda9f497a6f57aaa8f5e17895534af50
Gerrit-PatchSet: 9
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: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>