http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11386
Revision: 11386 Author: drtrigon Date: 2013-04-18 22:51:02 +0000 (Thu, 18 Apr 2013) Log Message: ----------- new feature; log file header (from trunk)
Modified Paths: -------------- branches/rewrite/pywikibot/bot.py branches/rewrite/scripts/script_wui.py
Modified: branches/rewrite/pywikibot/bot.py =================================================================== --- branches/rewrite/pywikibot/bot.py 2013-04-18 22:46:55 UTC (rev 11385) +++ branches/rewrite/pywikibot/bot.py 2013-04-18 22:51:02 UTC (rev 11386) @@ -30,6 +30,7 @@
import pywikibot from pywikibot import config +from pywikibot import version
# User interface initialization @@ -223,9 +224,44 @@ debuglogger.setLevel(DEBUG) debuglogger.addHandler(file_handler)
+ writelogheader(root_logger) + _handlers_initialized = True
+def writelogheader(logger): + """ + Save additional version, system and status info to the logfile in use, + so that the user can look it up later to track errors or report bugs. + """ + logoutput(u'=== Pywikipediabot framework v2.0 -- Logging header ===') + + # script call + logoutput(u'COMMAND: %s' % unicode(sys.argv)) + + # new framework release/revision? + site = pywikibot.getSite() + logoutput(u'VERSION: %s' % unicode((version.getversion().strip(' ()'), + version.getversion_onlinerepo(), + site.live_version()))) + + # system + if hasattr(os, 'uname'): + logoutput(u'SYSTEM: %s' % unicode(os.uname())) + + # imported modules + #logoutput(u'MODULES:') + #for item in sys.modules.keys(): + # ver = version.getfileversion('%s.py' % item) + # if ver and (ver[0] == u'$'): + # logoutput(u' %s' % ver) + + # messages on bot discussion page? + logoutput(u'MESSAGES: %s' % ('unanswered' if site.messages() else 'none')) + + logoutput(u'=== ' * 14) + + # User output/logging functions
# Six output functions are defined. Each requires a unicode or string
Modified: branches/rewrite/scripts/script_wui.py =================================================================== --- branches/rewrite/scripts/script_wui.py 2013-04-18 22:46:55 UTC (rev 11385) +++ branches/rewrite/scripts/script_wui.py 2013-04-18 22:51:02 UTC (rev 11386) @@ -57,7 +57,7 @@ # --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- # __version__ = '$Id$' -__framework_rev__ = '11097' # check: http://de.wikipedia.org/wiki/Hilfe:MediaWiki/Versionen +__framework_rev__ = '11384' # check: http://de.wikipedia.org/wiki/Hilfe:MediaWiki/Versionen __release_ver__ = '1.5' # increase minor (1.x) at re-merges with framework __release_rev__ = '%i' # @@ -80,13 +80,6 @@ from pywikibot import version
-# logging of framework info (may be this should be done without importing, just opening) -infolist = [ 'pywikibot/__init__.py', 'pywikibot/config2.py', # framework - 'pywikibot/data/api.py', # - 'pywikibot/bot.py', 'pywikibot/botirc.py', # - __version__, # - 'scripts/clean_sandbox.py', ] # - bot_config = { 'BotName': pywikibot.config.usernames[pywikibot.config.family][pywikibot.config.mylang],
# protected !!! ('CSS' or other semi-protected page is essential here) @@ -118,6 +111,12 @@
pywikibot.botirc.IRCBot.__init__(self, *arg)
+ ## modification of timezone to be in sync with wiki + #os.environ['TZ'] = 'Europe/Amsterdam' + #time.tzset() + #pywikibot.output(u'Setting process TimeZone (TZ): %s' % str(time.tzname)) # ('CET', 'CEST') + #pywikibot.output(u'') + # init environment with minimal changes (try to do as less as possible) # - Lua - pywikibot.output(u'** Redirecting Lua print in order to catch it') @@ -299,63 +298,11 @@ raise
def output_verinfo(): - global __release_rev__ - # script call pywikibot.output(u'SCRIPT CALL:') pywikibot.output(u' ' + u' '.join(sys.argv)) pywikibot.output(u'')
- # logging of release/framework info - pywikibot.output(u'RELEASE/FRAMEWORK VERSION:') - for item in infolist: - ver = version.getfileversion(item) - pywikibot.output(u' %s' % (item if ver is None else ver)) - pywikibot.output(u'') - - # new release/framework revision? (JIRA: DRTRIGON-131) - pywikibot.output(u'LATEST RELEASE/FRAMEWORK REVISION:') - # local release revision? - __release_rev__ %= int(version.getversion_svn(pywikibot.config.datafilepath('.'))[1]) - match = version.getversion_onlinerepo('http://svn.toolserver.org/svnroot/drtrigon/') - if match: - release_rev = int(match) - info = version.cmp_ver(release_rev, int(__release_rev__)) - pywikibot.output(u' Directory revision - release: %s (%s %s)' % (release_rev, info, __release_rev__)) - else: - pywikibot.output(u' WARNING: could not retrieve release information!') - # framework revision? - __framework_rev = int(__framework_rev__) - match = version.getversion_onlinerepo() - if match: - framework_rev = int(match) - info = version.cmp_ver(framework_rev, __framework_rev, 100) - pywikibot.output(u' Directory revision - framework: %s (%s %s)' % (framework_rev, info, __framework_rev__)) - else: - pywikibot.output(u' WARNING: could not retrieve framework information!') - pywikibot.output(u'') - - # mediawiki software version? - pywikibot.output(u'MEDIAWIKI VERSION:') - pywikibot.output(u' Actual revision: %s' % str(pywikibot.getSite().live_version(force=True))) - pywikibot.output(u'') - -# # processing of messages on bot discussion page -# if pywikibot.getSite().messages(): -# pywikibot.output(u'====== new messages on bot discussion page (last few lines) ======') -# messages_page = pywikibot.Page(pywikibot.getSite(), u'User:DrTrigonBot').toggleTalkPage() -# messagesforbot = messages_page.get(get_redirect=True) -# pywikibot.output( u'\n'.join(messagesforbot.splitlines()[-10:]) ) -# pywikibot.output(u'==================================================================') -# # purge/reset messages (remove this message from queue) by "viewing" it -# pywikibot.getSite().getUrl( os.path.join('/wiki', messages_page.urlname()) ) - - # modification of timezone to be in sync with wiki - os.environ['TZ'] = 'Europe/Amsterdam' - time.tzset() - pywikibot.output(u'Setting process TimeZone (TZ): %s' % str(time.tzname)) # ('CET', 'CEST') - pywikibot.output(u'') - if __name__ == "__main__": # # verbosely output version info of all involved scripts # # PROBLEM: correct place, but output not logged here, thus moved to 'main()' -> improve logging!! (look e.g. at botirc.py)