jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
IMPR: replace codecs.open with pathlib.Path in pywikibot/bot.py

Bug: T395187
Change-Id: Ib0d72e56c76524399b1c0a6444c975fa01e7bbb3
---
M pywikibot/bot.py
1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 8a369a6..adb70e1 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -109,7 +109,6 @@
)

import atexit
-import codecs
import configparser
import json
import logging
@@ -122,7 +121,6 @@
import webbrowser
from collections import Counter
from collections.abc import Container, Generator
-from contextlib import closing
from functools import wraps
from importlib import import_module
from pathlib import Path
@@ -965,15 +963,11 @@
modname = calledModuleName()
# put quotation marks around all parameters
args = [modname] + [f'"{s}"' for s in pywikibot.argvu[1:]]
- command_log_filename = config.datafilepath('logs', 'commands.log')
- try:
- command_log_file = codecs.open(command_log_filename, 'a', 'utf-8')
- except OSError:
- command_log_file = codecs.open(command_log_filename, 'w', 'utf-8')
+ iso_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())

- with closing(command_log_file):
- # add a timestamp in ISO 8601 formulation
- iso_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
+ command_log = Path(config.datafilepath('logs', 'commands.log'))
+ mode = 'a' if command_log.exists() else 'w'
+ with command_log.open(mode, encoding='utf-8') as command_log_file:
command_log_file.write('{} r{} Python {} '
.format(iso_date,
version.getversiondict()['rev'],

To view, visit change 1149829. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ib0d72e56c76524399b1c0a6444c975fa01e7bbb3
Gerrit-Change-Number: 1149829
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot