http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10022
Revision: 10022 Author: xqt Date: 2012-03-17 17:54:57 +0000 (Sat, 17 Mar 2012) Log Message: ----------- -folder parameter that specifies the log file path (feature request bug #3504335)
Modified Paths: -------------- trunk/pywikipedia/splitwarning.py
Modified: trunk/pywikipedia/splitwarning.py =================================================================== --- trunk/pywikipedia/splitwarning.py 2012-03-17 17:29:58 UTC (rev 10021) +++ trunk/pywikipedia/splitwarning.py 2012-03-17 17:54:57 UTC (rev 10022) @@ -1,8 +1,14 @@ # -*- coding: utf-8 -*- -"""Splits a interwiki.log file into chunks of warnings separated by language""" +"""Splits a interwiki.log file into chunks of warnings separated by language. + +The following parameter is supported: + +-folder: The target folder to save warning files, if given. Otherwise + use the /logs/ folder. +""" # # (C) Rob W.W. Hooft, 2003 -# (C) Pywikipedia bot team, 2004-2011 +# (C) Pywikipedia bot team, 2004-2012 # # Distributed under the terms of the MIT license. # @@ -13,28 +19,39 @@ import codecs import re
-pywikibot.stopme() # No need to have me on the stack - I don't contact the wiki -files={} -count={} +def splitwarning(folder): + files={} + count={}
-# TODO: Variable log filename -fn = pywikibot.config.datafilepath("logs", "interwiki.log") -logFile = codecs.open(fn, 'r', 'utf-8') -rWarning = re.compile('WARNING: (?P<family>.+?): [[(?P<code>.+?):.*') -for line in logFile: - m = rWarning.match(line) - if m: - family = m.group('family') - code = m.group('code') - if code in pywikibot.getSite().languages(): - if not code in files: - files[code] = codecs.open( - pywikibot.config.datafilepath('logs', - 'warning-%s-%s.log' % (family, code)), - 'w', 'utf-8') - count[code] = 0 - files[code].write(line) - count[code] += 1 -for code in files.keys(): - print '*%s (%d)' % (code, count[code]) + # TODO: Variable log filename + fn = pywikibot.config.datafilepath("logs", "interwiki.log") + logFile = codecs.open(fn, 'r', 'utf-8') + rWarning = re.compile('WARNING: (?P<family>.+?): [[(?P<code>.+?):.*') + for line in logFile: + m = rWarning.match(line) + if m: + family = m.group('family') + code = m.group('code') + if code in pywikibot.getSite().languages(): + if not code in files: + files[code] = codecs.open( + pywikibot.config.datafilepath( + folder, 'warning-%s-%s.log' % (family, code)), + 'w', 'utf-8') + count[code] = 0 + files[code].write(line) + count[code] += 1 + for code in files.keys(): + print '* %s (%d)' % (code, count[code])
+def main(*args): + folder = 'logs' + for arg in pywikibot.handleArgs(*args): + if arg.startswith("-folder"): + folder = arg[len('-folder:'):] + splitwarning(folder) + +if __name__ == "__main__": + # No need to have me on the stack - I don't contact the wiki + pywikibot.stopme() + main()
pywikipedia-svn@lists.wikimedia.org