jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/670260 )
Change subject: [IMPR] Always take 'maxarticlesize' into account when saving
......................................................................
[IMPR] Always take 'maxarticlesize' into account when saving
- always check whether threads exceeds maxarticlesize even if thread
counter is used
- always use positional argument for DiscussionPage.feed_thread()
- limit 'maxarchivesize' parameter to 'maxarticlesize'
Bug: T276937
Change-Id: Ibfe600bcaa15fc83cedc35aaeb9eb765db977417
---
M scripts/archivebot.py
1 file changed, 26 insertions(+), 7 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 4bf4923..dccbb1e 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -103,6 +103,7 @@
from hashlib import md5
from math import ceil
from typing import Any, Optional, Pattern
+from warnings import warn
import pywikibot
@@ -462,18 +463,21 @@
pywikibot.output('{} thread(s) found on {}'
.format(len(self.threads), self))
- def is_full(self, max_archive_size=(250 * 1024, 'B')) -> bool:
+ def is_full(self, max_archive_size: Size) -> bool:
"""Check whether archive size exceeded."""
- if max_archive_size[1] == 'B':
- if self.size() >= max_archive_size[0]:
- self.full = True # xxx: this is one-way flag
- elif max_archive_size[1] == 'T':
- if len(self.threads) >= max_archive_size[0]:
+ size, unit = max_archive_size
+ if self.size() > self.archiver.maxsize:
+ self.full = True # xxx: this is one-way flag
+ elif unit == 'B':
+ if self.size() >= size:
+ self.full = True
+ elif unit == 'T':
+ if len(self.threads) >= size:
self.full = True
return self.full
def feed_thread(self, thread: DiscussionThread,
- max_archive_size=(250 * 1024, 'B')) -> bool:
+ max_archive_size: Size) -> bool:
"""Append a new thread to the archive."""
self.threads.append(thread)
self.archived_threads += 1
@@ -546,6 +550,13 @@
for n, (long, short) in enumerate(self.site.months_names, start=1):
self.month_num2orig_names[n] = {'long': long, 'short':
short}
+ # read maxarticlesize
+ try:
+ # keep a gap of 1 KB not to block later changes
+ self.maxsize = self.site.siteinfo['maxarticlesize'] - 1024
+ except KeyError: # mw < 1.28
+ self.maxsize = 2096128 # 2 MB - 1 KB gap
+
def get_attr(self, attr, default='') -> Any:
"""Get an archiver attribute."""
return self.attributes.get(attr, [default])[0]
@@ -554,6 +565,14 @@
"""Set an archiver attribute."""
if attr == 'archive':
value = value.replace('_', ' ')
+ elif attr == 'maxarchivesize':
+ size, unit = str2size(value)
+ if unit == 'B':
+ if size > self.maxsize:
+ value = '{} K'.format(self.maxsize // 1024)
+ warn('Siteinfo "maxarticlesize" exceeded. Decreasing
'
+ '"maxarchivesize" to ' + value,
+ ResourceWarning, stacklevel=2)
self.attributes[attr] = [value, out]
def saveables(self) -> List[str]:
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/670260
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: Ibfe600bcaa15fc83cedc35aaeb9eb765db977417
Gerrit-Change-Number: 670260
Gerrit-PatchSet: 7
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Whym <whym(a)whym.org>
Gerrit-MessageType: merged