jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/626415 )
Change subject: [bugfix] Fix path for stable release in version.getversion()
......................................................................
[bugfix] Fix path for stable release in version.getversion()
- stable release is a branch now and not a tag anymore. Fix this path
in getversion()
- Always try to get any online hash even the previous call fails
- show the branch (currently master/stable) instead of just "ok"
- Don't break if local hsh cannot be loaded
- This can be expanded for future tags like "4.4", "4.5", "5.0"
Bug: T262558
Change-Id: Ic81923eb9bc1c8637051354d2fc7102eadcef24b
---
M pywikibot/version.py
1 file changed, 17 insertions(+), 9 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/version.py b/pywikibot/version.py
index 5764bd4..a0d5eb0 100644
--- a/pywikibot/version.py
+++ b/pywikibot/version.py
@@ -55,23 +55,31 @@
return None
-def getversion(online=True):
+def getversion(online: bool = True) -> str:
"""Return a pywikibot version string.
- @param online: (optional) Include information obtained online
+ @param online: Include information obtained online
"""
+ branches = {
+ 'master': 'branches/master',
+ 'stable': 'branches/stable',
+ }
data = dict(getversiondict()) # copy dict to prevent changes in 'cache'
data['cmp_ver'] = 'n/a'
+ local_hsh = data.get('hsh', '')
+ hsh = {}
if online:
- with suppress(Exception):
- hsh3 = getversion_onlinerepo('tags/stable')
- hsh2 = getversion_onlinerepo()
- hsh1 = data['hsh']
- data['cmp_ver'] = 'UNKNOWN' if not hsh1 else (
- 'OUTDATED' if hsh1 not in (hsh2, hsh3) else 'ok')
+ if not local_hsh:
+ data['cmp_ver'] = 'UNKNOWN'
+ else:
+ for branch, path in branches.items():
+ with suppress(Exception):
+ hsh[getversion_onlinerepo(path)] = branch
+ if hsh:
+ data['cmp_ver'] = hsh.get(local_hsh, 'OUTDATED')
- data['hsh'] = data['hsh'][:7] # make short hash from full hash
+ data['hsh'] = local_hsh[:7] # make short hash from full hash
return '{tag} ({hsh}, {rev}, {date}, {cmp_ver})'.format_map(data)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/626415
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: Ic81923eb9bc1c8637051354d2fc7102eadcef24b
Gerrit-Change-Number: 626415
Gerrit-PatchSet: 3
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-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/615470 )
Change subject: [4.0] Simplify LoggingFormatter
......................................................................
[4.0] Simplify LoggingFormatter
- Python 3 Formatter is always unicode and encoding is no longer used.
Remove initializer of _logging.Formatter and just add line feed at
the end of the formatException.
- Remove bot.LoggingFormatter and use the tools.LoggingFormatter
directly
- remove Python 2 code parts in _Logging
- update RotatingFileHandler.doRollover from Python 3 using rotate
and rotation_filename
Change-Id: Ia8a10cf5ffc0ac1f6e11e8c3cb5dfcf99162bd0d
---
M pywikibot/bot.py
M pywikibot/tools/_logging.py
2 files changed, 41 insertions(+), 69 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 4f87b3a..e1f9db3 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -124,10 +124,7 @@
from pywikibot.tools import (
deprecated, deprecate_arg, deprecated_args, issue_deprecation_warning,
)
-from pywikibot.tools._logging import (
- LoggingFormatter as _LoggingFormatter,
- RotatingFileHandler,
-)
+from pywikibot.tools._logging import LoggingFormatter, RotatingFileHandler
from pywikibot.tools.formatter import color_format
@@ -214,15 +211,6 @@
self.stop = stop
-class LoggingFormatter(_LoggingFormatter):
-
- """Logging formatter that uses config.console_encoding."""
-
- def __init__(self, fmt=None, datefmt=None):
- """Initializer setting underlying encoding to console_encoding."""
- super().__init__(fmt, datefmt, config.console_encoding)
-
-
# Initialize the handlers and formatters for the logging system.
#
# This relies on the global variable 'ui' which is a UserInterface object
diff --git a/pywikibot/tools/_logging.py b/pywikibot/tools/_logging.py
index 37ee3d3..3c42d14 100644
--- a/pywikibot/tools/_logging.py
+++ b/pywikibot/tools/_logging.py
@@ -1,17 +1,13 @@
# -*- coding: utf-8 -*-
"""Logging tools."""
#
-# (C) Pywikibot team, 2009-2018
+# (C) Pywikibot team, 2009-2020
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
import logging
import os
-from pywikibot.tools import PY2
-
# Logging module configuration
class RotatingFileHandler(logging.handlers.RotatingFileHandler):
@@ -19,51 +15,62 @@
"""Modified RotatingFileHandler supporting unlimited amount of backups."""
def doRollover(self):
- """
- Modified naming system for logging files.
+ """Modified naming system for logging files.
- Overwrites the default Rollover renaming by inserting the count number
- between file name root and extension. If backupCount is >= 1, the
- system will successively create new files with the same pathname as the
- base file, but with inserting ".1", ".2" etc. in front of the filename
- suffix. For example, with a backupCount of 5 and a base file name of
- "app.log", you would get "app.log", "app.1.log", "app.2.log", ...
- through to "app.5.log". The file being written to is always "app.log" -
- when it gets filled up, it is closed and renamed to "app.1.log", and if
- files "app.1.log", "app.2.log" etc. already exist, then they are
- renamed to "app.2.log", "app.3.log" etc. respectively.
+ Overwrites the default Rollover renaming by inserting the count
+ number between file name root and extension. If backupCount is
+ >= 1, the system will successively create new files with the
+ same pathname as the base file, but with inserting ".1", ".2"
+ etc. in front of the filename suffix. For example, with a
+ backupCount of 5 and a base file name of "app.log", you would
+ get "app.log", "app.1.log", "app.2.log", ... through to
+ "app.5.log". The file being written to is always "app.log" -
+ when it gets filled up, it is closed and renamed to "app.1.log",
+ and if files "app.1.log", "app.2.log" etc. already exist, then
+ they are renamed to "app.2.log", "app.3.log" etc. respectively.
+
If backupCount is == -1 do not rotate but create new numbered
- filenames. The newest file has the highest number except some older
- numbered files where deleted and the bot was restarted. In this case
- the ordering starts from the lowest available (unused) number.
+ filenames. The newest file has the highest number except some
+ older numbered files where deleted and the bot was restarted.
+ In this case the ordering starts from the lowest available
+ (unused) number.
"""
+ fmt = '{}.{}{}'
+
if self.stream:
self.stream.close()
self.stream = None
+
root, ext = os.path.splitext(self.baseFilename)
+
if self.backupCount > 0:
for i in range(self.backupCount - 1, 0, -1):
- sfn = '%s.%d%s' % (root, i, ext)
- dfn = '%s.%d%s' % (root, i + 1, ext)
+ sfn = self.rotation_filename(fmt.format(root, i, ext))
+ dfn = self.rotation_filename(fmt.format(root, i + 1, ext))
if os.path.exists(sfn):
if os.path.exists(dfn):
os.remove(dfn)
os.rename(sfn, dfn)
- dfn = '%s.1%s' % (root, ext)
+ dfn = self.rotation_filename(fmt.format(root, 1, ext))
if os.path.exists(dfn):
os.remove(dfn)
- os.rename(self.baseFilename, dfn)
+ self.rotate(self.baseFilename, dfn)
+
elif self.backupCount == -1:
- if not hasattr(self, '_lastNo'):
- self._lastNo = 1
+ if not hasattr(self, '_last_no'):
+ self._last_no = 1
while True:
- fn = '%s.%d%s' % (root, self._lastNo, ext)
- self._lastNo += 1
+ fn = self.rotation_filename(fmt.format(root, self._last_no,
+ ext))
+ self._last_no += 1
if not os.path.exists(fn):
break
- os.rename(self.baseFilename, fn)
+ self.rotate(self.baseFilename, fn)
+
self.mode = 'w'
- self.stream = self._open()
+
+ if not self.delay:
+ self.stream = self._open()
def format(self, record):
"""Strip trailing newlines before outputting text to file."""
@@ -81,8 +88,7 @@
record.args = (msg,)
- text = super().format(record)
- return text.rstrip()
+ return super().format(record).rstrip()
class LoggingFormatter(logging.Formatter):
@@ -92,30 +98,8 @@
This formatter *ignores* the 'newline' key of the LogRecord, because
every record written to a file must end with a newline, regardless of
whether the output to the user's console does.
-
"""
- def __init__(self, fmt=None, datefmt=None, encoding=None):
- """Initializer with additional encoding parameter."""
- super().__init__(fmt, datefmt)
- self._encoding = encoding
-
def formatException(self, ei):
- r"""
- Convert exception trace to unicode if necessary.
-
- Make sure that the exception trace is converted to unicode.
-
- L{exceptions.Error} traces are encoded in our console encoding, which
- is needed for plainly printing them. However, when logging them
- using logging.exception, the Python logging module will try to use
- these traces, and it will fail if they are console encoded strings.
-
- Formatter.formatException also strips the trailing \n, which we need.
- """
- exception_string = super().formatException(ei)
-
- if PY2 and isinstance(exception_string, bytes):
- return exception_string.decode(self._encoding) + '\n'
- else:
- return exception_string + '\n'
+ """Format and return the specified exception with newline."""
+ return super().formatException(ei) + '\n'
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/615470
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: Ia8a10cf5ffc0ac1f6e11e8c3cb5dfcf99162bd0d
Gerrit-Change-Number: 615470
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/618279 )
Change subject: [cleanup] Remove deprecated ui functions with FutureWarning
......................................................................
[cleanup] Remove deprecated ui functions with FutureWarning
Change-Id: I63582ed1589d211a3f2b6b89b0938090972caa33
---
M pywikibot/__init__.py
M pywikibot/bot.py
M pywikibot/userinterfaces/terminal_interface_base.py
M pywikibot/userinterfaces/terminal_interface_win32.py
4 files changed, 2 insertions(+), 65 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 2e99c51..0a9dac4 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -23,7 +23,7 @@
from pywikibot._wbtypes import WbRepresentation as _WbRepresentation
from pywikibot.bot import (
- input, input_choice, input_yn, inputChoice, handle_args, showHelp, ui,
+ input, input_choice, input_yn, handle_args, showHelp, ui,
calledModuleName, Bot, CurrentPageBot, WikidataBot,
# the following are flagged as deprecated on usage
handleArgs,
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 1dd2c69..2c7c838 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -63,7 +63,7 @@
'VERBOSE', 'critical', 'debug', 'error', 'exception', 'log', 'warning',
'output', 'stdout', 'LoggingFormatter', 'RotatingFileHandler',
'init_handlers', 'writelogheader',
- 'input', 'input_choice', 'input_yn', 'inputChoice', 'input_list_choice',
+ 'input', 'input_choice', 'input_yn', 'input_list_choice',
'Option', 'StandardOption', 'NestedOption', 'IntegerOption',
'ContextOption', 'ListOption', 'ShowingListOption', 'MultipleChoiceList',
'ShowingMultipleChoiceList', 'OutputProxyOption',
@@ -492,30 +492,6 @@
automatic_quit=automatic_quit, force=force)
-@deprecated('input_choice', since='20140825', future_warning=True)
-def inputChoice(question, answers, hotkeys, default=None):
- """Ask the user a question with several options, return the user's choice.
-
- DEPRECATED: Use L{input_choice} instead!
-
- The user's input will be case-insensitive, so the hotkeys should be
- distinctive case-insensitively.
-
- @param question: a string that will be shown to the user. Don't add a
- space after the question mark/colon, this method will do this for you.
- @type question: basestring
- @param answers: a list of strings that represent the options.
- @type answers: list of basestring
- @param hotkeys: a list of one-letter strings, one for each answer.
- @param default: an element of hotkeys, or None. The default choice that
- will be returned when the user just presses Enter.
- @return: a one-letter string in lowercase.
- @rtype: str
- """
- return input_choice(question, zip(answers, hotkeys), default=default,
- automatic_quit=False)
-
-
def input_yn(question, default=None, automatic_quit=True, force=False):
"""
Ask the user a yes/no question and return the answer as a bool.
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py
index b3502b2..4c29233 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -17,7 +17,6 @@
from pywikibot.bot import VERBOSE, INFO, STDOUT, INPUT, WARNING
from pywikibot.bot_choice import (ChoiceException, Option, OutputOption,
QuitKeyboardInterrupt, StandardOption)
-from pywikibot.tools import deprecated
from pywikibot.userinterfaces import transliteration
@@ -381,22 +380,6 @@
return index
return answer
- @deprecated('input_choice', since='20140825', future_warning=True)
- def inputChoice(self, question, options, hotkeys, default=None):
- """
- Ask the user a question with a predefined list of acceptable answers.
-
- DEPRECATED: Use L{input_choice} instead!
-
- Directly calls L{input_choice} with the options and hotkeys zipped
- into a tuple list. It always returns the hotkeys and throws no
- L{QuitKeyboardInterrupt} if quit was selected.
- """
- return self.input_choice(question=question, options=zip(options,
- hotkeys),
- default=default, return_shortcut=True,
- automatic_quit=False)
-
def input_list_choice(self, question, answers, default=None, force=False):
"""Ask the user to select one entry from a list of entries."""
message = question
diff --git a/pywikibot/userinterfaces/terminal_interface_win32.py b/pywikibot/userinterfaces/terminal_interface_win32.py
index 3482ada..7696eaa 100755
--- a/pywikibot/userinterfaces/terminal_interface_win32.py
+++ b/pywikibot/userinterfaces/terminal_interface_win32.py
@@ -7,7 +7,6 @@
#
import ctypes
-from pywikibot.tools import ModuleDeprecationWrapper
from pywikibot.userinterfaces import terminal_interface_base, win32_unicode
windowsColors = {
@@ -31,16 +30,6 @@
}
-class Win32BaseUI(terminal_interface_base.UI):
-
- """DEPRECATED. User interface for Win32 terminals."""
-
- def __init__(self):
- """Initializer."""
- super().__init__()
- self.encoding = 'ascii'
-
-
class Win32UI(terminal_interface_base.UI):
"""User interface for Win32 terminals."""
@@ -74,14 +63,3 @@
if '\x1a' in data:
raise EOFError()
return data.strip()
-
-
-Win32CtypesUI = Win32UI
-
-wrapper = ModuleDeprecationWrapper(__name__)
-wrapper._add_deprecated_attr('Win32CtypesUI',
- replacement_name='Win32UI',
- since='20190217', future_warning=True)
-wrapper._add_deprecated_attr('Win32BaseUI',
- replacement_name='Win32UI',
- since='20190217', future_warning=True)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/618279
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: I63582ed1589d211a3f2b6b89b0938090972caa33
Gerrit-Change-Number: 618279
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged