jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/610076 )
Change subject: [4.0] Update maintenance scripts to pwb4
......................................................................
[4.0] Update maintenance scripts to pwb4
Change-Id: I51cb727cf6a39b6e7c37985ebb20202cd8977b88
---
M scripts/maintenance/cache.py
M scripts/maintenance/colors.py
M scripts/maintenance/compat2core.py
M scripts/maintenance/download_dump.py
M scripts/maintenance/make_i18n_dict.py
M scripts/maintenance/wikimedia_sites.py
6 files changed, 22 insertions(+), 58 deletions(-)
Approvals:
Zhuyifei1999: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/maintenance/cache.py b/scripts/maintenance/cache.py
index e771756..a59aa33 100755
--- a/scripts/maintenance/cache.py
+++ b/scripts/maintenance/cache.py
@@ -69,8 +69,6 @@
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
import datetime
import hashlib
import os
@@ -324,34 +322,31 @@
obj = globals().get(command)
if callable(obj):
return obj
- else:
- try:
- return eval('lambda entry: ' + command)
- except Exception:
- pywikibot.exception()
- pywikibot.error(
- 'Cannot compile {0} command: {1}'.format(name, command))
- return None
+
+ try:
+ return eval('lambda entry: ' + command)
+ except Exception:
+ pywikibot.exception()
+ pywikibot.error(
+ 'Cannot compile {0} command: {1}'.format(name, command))
+ return None
# Filter commands
def has_password(entry):
"""Entry has a password in the entry."""
- if 'lgpassword' in entry._uniquedescriptionstr():
- return entry
+ return entry if 'lgpassword' in entry._uniquedescriptionstr() else None
def is_logout(entry):
"""Entry is a logout entry."""
- if not entry._data and 'logout' in entry.key:
- return entry
+ return entry if not entry._data and 'logout' in entry.key else None
def empty_response(entry):
"""Entry has no data."""
- if not entry._data and 'logout' not in entry.key:
- return entry
+ return entry if not entry._data and 'logout' not in entry.key else None
def not_accessed(entry):
@@ -367,18 +362,21 @@
"""Incorrect hash."""
if hashlib.sha256(entry.key.encode('utf-8')).hexdigest() != entry.filename:
return entry
+ return None
def older_than(entry, interval):
"""Find older entries."""
if entry._cachetime + interval < datetime.datetime.utcnow():
return entry
+ return None
def newer_than(entry, interval):
"""Find newer entries."""
if entry._cachetime + interval >= datetime.datetime.utcnow():
return entry
+ return None
def older_than_one_day(entry):
@@ -389,8 +387,7 @@
def recent(entry):
"""Find entries newer than on hour."""
- if newer_than(entry, datetime.timedelta(hours=1)):
- return entry
+ return entry if newer_than(entry, datetime.timedelta(hours=1)) else None
# Output commands
diff --git a/scripts/maintenance/colors.py b/scripts/maintenance/colors.py
index 28c3086..63d22a4 100644
--- a/scripts/maintenance/colors.py
+++ b/scripts/maintenance/colors.py
@@ -2,17 +2,15 @@
# -*- coding: utf-8 -*-
"""Utility to show pywikibot colors."""
#
-# (C) Pywikibot team, 2016-2018
+# (C) Pywikibot team, 2016-2020
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
import pywikibot
from pywikibot.tools.formatter import color_format
from pywikibot.tools import itergroup
-from pywikibot.userinterfaces.terminal_interface_base import colors as colors
+from pywikibot.userinterfaces.terminal_interface_base import colors
def main():
diff --git a/scripts/maintenance/compat2core.py
b/scripts/maintenance/compat2core.py
index cbcc451..05d4acf 100755
--- a/scripts/maintenance/compat2core.py
+++ b/scripts/maintenance/compat2core.py
@@ -30,8 +30,6 @@
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
import codecs
import os
import re
@@ -136,7 +134,7 @@
)
-class ConvertBot(object):
+class ConvertBot:
"""Script conversion bot."""
diff --git a/scripts/maintenance/download_dump.py
b/scripts/maintenance/download_dump.py
index 9f08fb7..ee5539a 100644
--- a/scripts/maintenance/download_dump.py
+++ b/scripts/maintenance/download_dump.py
@@ -14,40 +14,19 @@
"""
#
-# (C) Pywikibot team, 2017-2019
+# (C) Pywikibot team, 2017-2020
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
import binascii
import os.path
import sys
-from os import remove, symlink, urandom
-try:
- from os import replace
-except ImportError: # py2
- if sys.platform == 'win32':
- import os
-
- def replace(src, dst):
- """Rename a file or directory, overwriting the destination."""
- try:
- os.rename(src, dst)
- except OSError:
- remove(dst)
- os.rename(src, dst)
- else:
- from os import rename as replace
+from os import remove, replace, symlink, urandom
import pywikibot
from pywikibot import Bot
from pywikibot.comms.http import fetch
-from pywikibot.tools import PY2
-
-if PY2:
- from future_builtins import map
class DownloadDumpBot(Bot):
diff --git a/scripts/maintenance/make_i18n_dict.py
b/scripts/maintenance/make_i18n_dict.py
index 013e37e..8d8cf42 100755
--- a/scripts/maintenance/make_i18n_dict.py
+++ b/scripts/maintenance/make_i18n_dict.py
@@ -29,19 +29,15 @@
#
# Distributed under the terms of the MIT license.
#
-from __future__ import (absolute_import, division,
- print_function, unicode_literals)
-
import codecs
from importlib import import_module
import json
import os
from pywikibot import config
-from pywikibot.tools import PY2
-class i18nBot(object): # noqa: N801
+class i18nBot: # noqa: N801
"""I18n bot."""
@@ -78,8 +74,6 @@
keys.insert(0, 'en')
print('# -*- coding: utf-8 -*-')
- if PY2:
- print('from __future__ import unicode_literals')
print('msg = {')
for code in keys:
print(" '%s': {" % code)
diff --git a/scripts/maintenance/wikimedia_sites.py
b/scripts/maintenance/wikimedia_sites.py
index 20e7826..6a352ee 100755
--- a/scripts/maintenance/wikimedia_sites.py
+++ b/scripts/maintenance/wikimedia_sites.py
@@ -8,12 +8,10 @@
"""
#
-# (C) Pywikibot team, 2008-2018
+# (C) Pywikibot team, 2008-2020
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
import codecs
import re
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/610076
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: I51cb727cf6a39b6e7c37985ebb20202cd8977b88
Gerrit-Change-Number: 610076
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: Isaacandy <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Zhuyifei1999 <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits