jenkins-bot merged this change.

View Change

Approvals: Dvorapa: Looks good to me, approved jenkins-bot: Verified
[IMPR] uuse contextlib.closing to close the command_log_file

Change-Id: I62368ee6920eadce0b8b276cb77b31ae84b7be78
---
M pywikibot/bot.py
1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 4ded96c..1dc7855 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -87,7 +87,6 @@

import codecs
import datetime
-from importlib import import_module
import json
import logging
import logging.handlers
@@ -95,9 +94,13 @@
import sys
import time
import warnings
-from warnings import warn
import webbrowser

+from contextlib import closing
+from importlib import import_module
+from textwrap import fill
+from warnings import warn
+
try:
import configparser
except ImportError: # PY2
@@ -108,7 +111,6 @@
except ImportError: # PY2
from pathlib2 import Path

-from textwrap import fill

import pywikibot
from pywikibot import config2 as config
@@ -1008,14 +1010,15 @@
command_log_file = codecs.open(command_log_filename, 'a', 'utf-8')
except IOError:
command_log_file = codecs.open(command_log_filename, 'w', 'utf-8')
- # add a timestamp in ISO 8601 formulation
- iso_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
- command_log_file.write('%s r%s Python %s '
- % (iso_date, version.getversiondict()['rev'],
- sys.version.split()[0]))
- s = ' '.join(args)
- command_log_file.write(s + os.linesep)
- command_log_file.close()
+
+ 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_file.write('{} r{} Python {} '
+ .format(iso_date,
+ version.getversiondict()['rev'],
+ sys.version.split()[0]))
+ command_log_file.write(' '.join(args) + os.linesep)


def open_webbrowser(page):

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I62368ee6920eadce0b8b276cb77b31ae84b7be78
Gerrit-Change-Number: 605860
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: jenkins-bot (75)