Revision: 6387
Author: russblau
Date: 2009-02-20 14:25:13 +0000 (Fri, 20 Feb 2009)
Log Message:
-----------
fix various output-related issues
Modified Paths:
--------------
branches/rewrite/pywikibot/__init__.py
branches/rewrite/pywikibot/bot.py
branches/rewrite/pywikibot/comms/http.py
branches/rewrite/pywikibot/data/api.py
branches/rewrite/pywikibot/login.py
branches/rewrite/pywikibot/scripts/touch.py
Modified: branches/rewrite/pywikibot/__init__.py
===================================================================
--- branches/rewrite/pywikibot/__init__.py 2009-02-20 07:53:28 UTC (rev 6386)
+++ branches/rewrite/pywikibot/__init__.py 2009-02-20 14:25:13 UTC (rev 6387)
@@ -92,8 +92,8 @@
key = '%s:%s:%s' % (fam, code, user)
if not key in _sites:
_sites[key] = __Site(code=code, fam=fam, user=user, sysop=sysop)
- pywikibot.output("Instantiating Site object '%(site)s'"
- % {'site': _sites[key]}, level=DEBUG)
+ logging.debug(u"Instantiating Site object '%(site)s'"
+ % {'site': _sites[key]})
return _sites[key]
getSite = Site # alias for backwards-compability
@@ -210,11 +210,11 @@
logger = logging.getLogger("wiki")
if not stopped:
- pywikibot.output("stopme() called", level=DEBUG)
+ logging.debug("stopme() called")
count = sum(1 for thd in threadpool if thd.isAlive())
if count:
- pywikibot.output("Waiting for about %(count)s pages to be saved."
- % locals())
+ pywikibot.output(u"Waiting for about %(count)s pages to be saved."
+ % locals())
for thd in threadpool:
if thd.isAlive():
thd.join()
@@ -222,7 +222,7 @@
# only need one drop() call because all throttles use the same global pid
try:
_sites[_sites.keys()[0]].throttle.drop()
- pywikibot.output("Dropped throttle(s).", level=VERBOSE)
+ pywikibot.output(u"Dropped throttle(s).", level=VERBOSE)
except IndexError:
pass
Modified: branches/rewrite/pywikibot/bot.py
===================================================================
--- branches/rewrite/pywikibot/bot.py 2009-02-20 07:53:28 UTC (rev 6386)
+++ branches/rewrite/pywikibot/bot.py 2009-02-20 14:25:13 UTC (rev 6387)
@@ -22,6 +22,7 @@
# logging levels
+logger = logging.getLogger("bot")
from logging import DEBUG, INFO, WARNING, ERROR, CRITICAL
STDOUT = 16
@@ -244,7 +245,6 @@
arg = _decodeArg(arg)
if arg == '-help':
do_help = True
- break
elif arg.startswith('-family:'):
config.family = arg[len("-family:") : ]
elif arg.startswith('-lang:'):
@@ -323,7 +323,7 @@
root_logger = logging.getLogger()
root_logger.handlers = [] # get rid of default handler
- root_logger.setLevel(VERBOSE) # all records except DEBUG go to logger
+ root_logger.setLevel(DEBUG+1) # all records except DEBUG go to logger
# configure default handler for VERBOSE and INFO levels
default_handler = TerminalHandler(strm=sys.stderr)
@@ -361,6 +361,7 @@
output_handler = TerminalHandler(strm=sys.stdout)
output_handler.setLevel(STDOUT)
output_handler.addFilter(MaxLevelFilter(STDOUT))
+ output_handler.setFormatter(logging.Formatter(fmt="%(message)s"))
root_logger.addHandler(output_handler)
# handler for levels WARNING and higher
@@ -380,7 +381,7 @@
if do_help:
showHelp()
sys.exit(0)
- pywikibot.output("handleArgs() completed.", level=DEBUG)
+ logger.debug(u"handleArgs() completed.")
return nonGlobalArgs
@@ -439,9 +440,10 @@
if hasattr(module, 'docuReplacements'):
for key, value in module.docuReplacements.iteritems():
helpText = helpText.replace(key, value.strip('\n\r'))
- pywikibot.output(helpText)
+ pywikibot.output(helpText, level=pywikibot.STDOUT) # output to STDOUT
except Exception:
if modname:
- pywikibot.output(u'Sorry, no help available for %s' % modname)
+ pywikibot.output(u'Sorry, no help available for %s' % modname,
+ level=pywikibot.STDOUT)
logging.exception('showHelp:')
- pywikibot.output(globalHelp)
+ pywikibot.output(globalHelp, level=pywikibot.STDOUT)
Modified: branches/rewrite/pywikibot/comms/http.py
===================================================================
--- branches/rewrite/pywikibot/comms/http.py 2009-02-20 07:53:28 UTC (rev 6386)
+++ branches/rewrite/pywikibot/comms/http.py 2009-02-20 14:25:13 UTC (rev 6387)
@@ -104,8 +104,8 @@
raise request.data
if request.data[0].status != 200:
- pywikibot.output("Http response status %(status)s"
- % {'status': request.data[0].status},
+ pywikibot.output(u"Http response status %(status)s"
+ % {'status': request.data[0].status},
level=pywikibot.WARNING)
return request.data[1]
Modified: branches/rewrite/pywikibot/data/api.py
===================================================================
--- branches/rewrite/pywikibot/data/api.py 2009-02-20 07:53:28 UTC (rev 6386)
+++ branches/rewrite/pywikibot/data/api.py 2009-02-20 14:25:13 UTC (rev 6387)
@@ -196,7 +196,7 @@
except Exception, e: #TODO: what exceptions can occur here?
pywikibot.output(traceback.format_exc(),
level=pywikibot.ERROR)
- pywikibot.output("%s, %s" % (uri, params),
+ pywikibot.output(u"%s, %s" % (uri, params),
level=pywikibot.VERBOSE)
self.wait()
continue
@@ -248,7 +248,8 @@
lag = lagpattern.search(info)
if lag:
pywikibot.output(
- "Pausing due to database lag: " + info)
+ u"Pausing due to database lag: " + info,
+ level=pywikibot.VERBOSE)
self.site.throttle.lag(int(lag.group("lag")))
continue
if code in (u'internal_api_error_DBConnectionError', ):
@@ -633,7 +634,7 @@
from pywikibot import Site
logger.setLevel(pywikibot.logging.DEBUG)
mysite = Site("en", "wikipedia")
- pywikibot.output("starting test....")
+ pywikibot.output(u"starting test....")
def _test():
import doctest
doctest.testmod()
Modified: branches/rewrite/pywikibot/login.py
===================================================================
--- branches/rewrite/pywikibot/login.py 2009-02-20 07:53:28 UTC (rev 6386)
+++ branches/rewrite/pywikibot/login.py 2009-02-20 14:25:13 UTC (rev 6387)
@@ -109,7 +109,7 @@
the policy on the respective wiki.
"""
- return True # DEBUG
+# return True # DEBUG
if self.site.family.name in botList \
and self.site.code in botList[self.site.family.name]:
botListPageTitle = botList[self.site.family.name][self.site.code]
@@ -194,7 +194,7 @@
try:
cookiedata = self.getCookie()
except pywikibot.data.api.APIError, e:
- pywikibot.output("Login failed (%s)." % e.code,
+ pywikibot.output(u"Login failed (%s)." % e.code,
level=pywikibot.ERROR)
if retry:
self.password = None
@@ -219,12 +219,12 @@
def showCaptchaWindow(self, url):
pass
-def main():
+def main(*args):
username = password = None
sysop = False
logall = False
forceLogin = False
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handleArgs(*args):
if arg.startswith("-pass"):
if len(arg) == 5:
password = pywikibot.input(u'Password for all accounts:',
Modified: branches/rewrite/pywikibot/scripts/touch.py
===================================================================
--- branches/rewrite/pywikibot/scripts/touch.py 2009-02-20 07:53:28 UTC (rev 6386)
+++ branches/rewrite/pywikibot/scripts/touch.py 2009-02-20 14:25:13 UTC (rev 6387)
@@ -39,12 +39,15 @@
text = page.get(get_redirect = self.touch_redirects)
page.save("Pywikibot touch script")
except pywikibot.NoPage:
- pywikibot.output("Page %s does not exist?!" % page.aslink())
+ pywikibot.output(u"Page %s does not exist?!" % page.aslink(),
+ level=pywikibot.ERROR)
except pywikibot.IsRedirectPage:
- pywikibot.output("Page %s is a redirect; skipping."
- % page.aslink())
+ pywikibot.output(u"Page %s is a redirect; skipping."
+ % page.aslink(),
+ level=pywikibot.WARNING)
except pywikibot.LockedPage:
- pywikibot.output("Page %s is locked?!" % page.aslink())
+ pywikibot.output(u"Page %s is locked?!" % page.aslink(),
+ level=pywikibot.ERROR)
def main(*args):