jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/481121 )
Change subject: atexit: Stop polluting stdout with sys.last_type
......................................................................
atexit: Stop polluting stdout with sys.last_type
Some people (eg. me) use more of pywikibot as a library, and in some
uses, like text stream processors, stdio pollution is simply not
tolerable.
Besides, sys.last_type should already be given, at exit time, by
sys.excepthook, to stderr. There is no reason whatsoever the cause
of exit should be duplicated to stdout when it's already in stderr.
In the extreme case that a user actually rely on this bug feature
(I can't imagine why but it's possible, given this code has existed
for so long that I finally hit some use case that can't tolerate
this anymore), it's very easy for them to register their own atexit
handler; on the other hand, it's very hard for me to silent this
atexit handler without directly removing the line.
This is so bad that we even had to create an exception for T001 in
tox.ini without any explanation why this print must exist in the
first place.
Oh and in case anyone wonders, this print was added almost 5 years
ago in 4b09153, and in that diff it looks more like for debugging
or testing of that patch rather than something critical.
Considering that the logged messages at exit may be the same (except
the log level of 'Closing network session.'), the exception type is
now logged in a more meaningful message in critical log level and
the original 'Closing network session.' is now always info level,
since it is the exception, not the network session being closed,
that is of interest to the user.
Change-Id: I83ce680f7e4eeb2e18fcfc60db70e88a8c668538
---
M pywikibot/comms/http.py
M tox.ini
2 files changed, 3 insertions(+), 7 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 893942e..fc9b369 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -119,14 +119,11 @@
# Prepare flush on quit
def _flush():
+ log('Closing network session.')
session.close()
- message = 'Closing network session.'
+
if hasattr(sys, 'last_type'):
- # we quit because of an exception
- print(sys.last_type)
- critical(message)
- else:
- log(message)
+ critical('Exiting due to uncaught exception {}'.format(sys.last_type))
log('Network session closed.')
diff --git a/tox.ini b/tox.ini
index 68da0e9..506146b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -150,7 +150,6 @@
pywikibot/_wbtypes.py: N802
pywikibot/backports.py: N802
pywikibot/bot.py: N802
- pywikibot/comms/http.py : T001
pywikibot/compat/catlib.py : N803
pywikibot/compat/query.py: N802
pywikibot/cosmetic_changes.py : N803, N806, N802
--
To view, visit https://gerrit.wikimedia.org/r/481121
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I83ce680f7e4eeb2e18fcfc60db70e88a8c668538
Gerrit-Change-Number: 481121
Gerrit-PatchSet: 3
Gerrit-Owner: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/446695 )
Change subject: newitem.py: disable touching pages for non autoconfirmed
......................................................................
newitem.py: disable touching pages for non autoconfirmed
Touching pages triggers edits on pages, that can hit throttle
rates and captachas.
The default behavior is to touch only pages linked to newly
created items. Now touch system will be disabled completely
if user is not autoconfirmed, to avoid interruptions.
It's still possible to force touching pages by using -touch
option.
Note that nothing is implemented yet to allow non autoconfirmed
to touch only pages linked to newly created items, it's only
binary in this case.
Bug: T199936
Change-Id: Ib536542049ae16be0bd62d911522fad91acaeac4
---
M scripts/newitem.py
1 file changed, 19 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/newitem.py b/scripts/newitem.py
index c3c3f6b..a2f3595 100755
--- a/scripts/newitem.py
+++ b/scripts/newitem.py
@@ -16,6 +16,8 @@
created.
-touch Do a null edit on every page which has a wikibase item.
+ Be careful, this option can trigger edit rates or captachas
+ if your account is not autoconfirmed.
"""
#
@@ -27,6 +29,7 @@
from __future__ import absolute_import, division, unicode_literals
from datetime import timedelta
+from textwrap import fill
import pywikibot
from pywikibot import pagegenerators, WikidataBot
@@ -46,7 +49,8 @@
'always': True,
'lastedit': 7,
'pageage': 21,
- 'touch': False,
+ 'touch': 'newly', # Can be False, newly (pages linked to newly
+ # created items) or True (touch all pages)
})
super(NewItemRobot, self).__init__(**kwargs)
@@ -68,6 +72,7 @@
@staticmethod
def _touch_page(page):
try:
+ pywikibot.output('Doing a null edit on the page.')
page.touch()
except (NoCreateError, NoPage):
pywikibot.error('Page {0} does not exist.'.format(
@@ -80,7 +85,7 @@
page.title(as_link=True)))
def _callback(self, page, exc):
- if exc is None:
+ if exc is None and self.getOption('touch'):
self._touch_page(page)
def treat_page_and_item(self, page, item):
@@ -88,8 +93,7 @@
if item and item.exists():
pywikibot.output('{0} already has an item: {1}.'
.format(page, item))
- if self.getOption('touch'):
- pywikibot.output('Doing a null edit on the page.')
+ if self.getOption('touch') is True:
self._touch_page(page)
return
@@ -152,6 +156,17 @@
return False
bot = NewItemRobot(generator, **options)
+ user = pywikibot.User(bot.site, bot.site.username)
+ if bot.getOption('touch') == 'newly' \
+ and 'autoconfirmed' not in user.groups():
+ pywikibot.warning(fill(
+ 'You are logged in as {}, an account that is '
+ 'not in the autoconfirmed group on {}. Script '
+ 'will not touch pages linked to newly created '
+ 'items to avoid triggering edit rates or '
+ 'captachas. Use -touch param to force this.'
+ .format(user.username, bot.site.sitename)))
+ bot.options['touch'] = False
bot.run()
return True
--
To view, visit https://gerrit.wikimedia.org/r/446695
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib536542049ae16be0bd62d911522fad91acaeac4
Gerrit-Change-Number: 446695
Gerrit-PatchSet: 7
Gerrit-Owner: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: Bugreporter <bugreporter1(a)sina.com>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/480099 )
Change subject: [IMPR] Make Timestamp.fromtimestampformat() more robust
......................................................................
[IMPR] Make Timestamp.fromtimestampformat() more robust
- Also convert mediawiki timestamp to Timestamp if
year, month and day are given only
- Tests added
- Update welcome.py accordingly
Change-Id: I1e3e88d88a971db4d9d73bee6d245f046d78427c
---
M pywikibot/__init__.py
M scripts/welcome.py
M tests/timestamp_tests.py
3 files changed, 20 insertions(+), 7 deletions(-)
Approvals:
Zhuyifei1999: Looks good to me, but someone else must approve
Framawiki: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index fb07bcd..899710a 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -210,6 +210,8 @@
# to create a clone.
if isinstance(ts, cls):
return ts.clone()
+ if len(ts) == 8: # year, month and day are given only
+ ts += '000'
return cls.strptime(ts, cls.mediawikiTSFormat)
def isoformat(self, sep='T'):
diff --git a/scripts/welcome.py b/scripts/welcome.py
index 68bd0cc..d192cc1 100755
--- a/scripts/welcome.py
+++ b/scripts/welcome.py
@@ -54,7 +54,7 @@
to give interactive users a chance to welcome the
new users (default: now)
Timezone is the server timezone, GMT for Wikimedia
- TIME format : yyyymmddhhmmss
+ TIME format : yyyymmddhhmmss or yyyymmdd
-timeoffset[:#] Skip the latest new users, accounts newer than
# minutes
@@ -172,6 +172,7 @@
import locale
import re
import sys
+from textwrap import fill
import time
from random import choice
@@ -935,16 +936,17 @@
if not val:
val = pywikibot.input(
'Which time offset for new users would you like to use? '
- '(yyyymmddhhmmss)')
+ '(yyyymmddhhmmss or yyyymmdd)')
try:
globalvar.offset = pywikibot.Timestamp.fromtimestampformat(val)
except ValueError:
# upon request, we could check for software version here
- raise ValueError(
+ raise ValueError(fill(
'Mediawiki has changed, -offset:# is not supported '
- 'anymore, but -offset:TIMESTAMP is, assuming TIMESTAMP '
- 'is yyyymmddhhmmss. -timeoffset is now also supported. '
- 'Please read this script source header for documentation.')
+ 'anymore, but -offset:TIMESTAMP is, assuming TIMESTAMP is '
+ 'yyyymmddhhmmss or yyyymmdd. -timeoffset is now also '
+ 'supported. Please read this script source header for '
+ 'documentation.'))
elif arg == '-file':
globalvar.randomSign = True
globalvar.signFileName = val or pywikibot.input(
diff --git a/tests/timestamp_tests.py b/tests/timestamp_tests.py
index 022a975..9cd4ed2 100644
--- a/tests/timestamp_tests.py
+++ b/tests/timestamp_tests.py
@@ -80,7 +80,7 @@
Timestamp.mediawikiTSFormat)
def test_mediawiki_format(self):
- """Test conversion from and to timestamp format."""
+ """Test conversion from and to Timestamp format."""
t1 = Timestamp.utcnow()
if not t1.microsecond: # T191827: ensure microsecond is not 0
t1 = t1.replace(microsecond=1000)
@@ -93,6 +93,15 @@
self.assertEqual(t1, t2)
self.assertEqual(ts1, ts2)
+ def test_short_mediawiki_format(self):
+ """Test short mw timestamp conversion from and to Timestamp format."""
+ t1 = Timestamp(2018, 12, 17)
+ t2 = Timestamp.fromtimestampformat('20181217') # short timestamp
+ ts1 = t1.totimestampformat()
+ ts2 = t2.totimestampformat()
+ self.assertEqual(t1, t2)
+ self.assertEqual(ts1, ts2)
+
def test_add_timedelta(self):
"""Test addin a timedelta to a Timestamp."""
t1 = Timestamp.utcnow()
--
To view, visit https://gerrit.wikimedia.org/r/480099
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I1e3e88d88a971db4d9d73bee6d245f046d78427c
Gerrit-Change-Number: 480099
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)