jenkins-bot has submitted this change and it was merged.
Change subject: Adding commands.log generating function in core.
......................................................................
Adding commands.log generating function in core.
The compat version contains history of all command which were used for
running bot. It is useful when we want to run some more complicated
command again.There is no such log in core branch. As such I have added
this enhancement as part of Pywikibot:Compat to Core Migration.
Bug:T69724
Change-Id: I8e18c07f1b06569ff29cd8cab3900d515c187f1b
---
M pywikibot/bot.py
1 file changed, 27 insertions(+), 0 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index be83074..3a5ea91 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -13,6 +13,7 @@
# Note: all output goes thru python std library "logging" module
+import codecs
import datetime
import json
import logging
@@ -20,6 +21,7 @@
import os
import re
import sys
+import time
import warnings
import webbrowser
@@ -774,6 +776,7 @@
config.usernames[config.family][config.mylang] = username
init_handlers()
+ writeToCommandLogFile()
if config.verbose_output:
# Please don't change the regular expression here unless you really
@@ -889,6 +892,30 @@
pywikibot.stdout(globalHelp)
+def writeToCommandLogFile():
+ """
+ Save name of the called module along with all parameters to
logs/commands.log.
+
+ This can be used by user later to track errors or report bugs.
+ """
+ modname = calledModuleName()
+ # put quotation marks around all parameters
+ args = [modname] + [u'"%s"' % 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 IOError:
+ command_log_file = codecs.open(command_log_filename, 'w', 'utf-8')
+ # add a timestamp in ISO 8601 formulation
+ isoDate = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
+ command_log_file.write('%s r%s Python %s '
+ % (isoDate, version.getversiondict()['rev'],
+ sys.version.split()[0]))
+ s = u' '.join(args)
+ command_log_file.write(s + os.linesep)
+ command_log_file.close()
+
+
def open_webbrowser(page):
"""Open the web browser displaying the page and wait for input."""
from pywikibot import i18n
--
To view, visit https://gerrit.wikimedia.org/r/198547
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8e18c07f1b06569ff29cd8cab3900d515c187f1b
Gerrit-PatchSet: 8
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Prianka <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits