Revision: 5290 Author: russblau Date: 2008-05-01 16:18:50 +0000 (Thu, 01 May 2008)
Log Message: ----------- Use logging instead of pywikibot.output for all progress-related messages; use absolute import
Modified Paths: -------------- branches/rewrite/pywikibot/login.py branches/rewrite/pywikibot/page.py branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/login.py =================================================================== --- branches/rewrite/pywikibot/login.py 2008-05-01 15:15:46 UTC (rev 5289) +++ branches/rewrite/pywikibot/login.py 2008-05-01 16:18:50 UTC (rev 5290) @@ -169,7 +169,7 @@ if match: id = match.group('id') if not config.solve_captcha: - raise pywikibot.CaptchaError(id) + raise CaptchaError(id) url = self.site.protocol() + '://' + self.site.hostname() + self.site.captcha_image_address(id) answer = wikipedia.ui.askForCaptcha(url) return self.getCookie(remember = remember, captchaId = id, captchaAnswer = answer) @@ -227,17 +227,17 @@
# self.password = self.password.encode(self.site.encoding())
- pywikibot.output(u"Logging in to %s as %s" % (self.site, self.username)) + logging.info(u"Logging in to %s as %s" % (self.site, self.username)) cookiedata = self.getCookie() if cookiedata: self.storecookiedata(cookiedata) - pywikibot.output(u"Should be logged in now") + logging.info(u"Should be logged in now") # Show a warning according to the local bot policy if not self.botAllowed(): - pywikibot.output(u'*** Your username is not listed on [[%s]].\n*** Please make sure you are allowed to use the robot before actually using it!' % botList[self.site.family.name][self.site.lang]) + logging.error(u'*** Your username is not listed on [[%s]].\n*** Please make sure you are allowed to use the robot before actually using it!' % botList[self.site.family.name][self.site.lang]) return True else: - pywikibot.output(u"Login failed. Wrong password or CAPTCHA answer?") + logging.error(u"Login failed. Wrong password or CAPTCHA answer?") if retry: self.password = None return self.login(retry = True) @@ -276,7 +276,7 @@ for lang in namedict[familyName].iterkeys(): site = pywikibot.getSite(code=lang, fam=familyName) if not forceLogin and site.loggedInAs(sysop = sysop) != None: - pywikibot.output(u'Already logged in on %s' % site) + logging.info(u'Already logged in on %s' % site) else: loginMan = LoginManager(password, sysop = sysop, site = site) loginMan.login()
Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2008-05-01 15:15:46 UTC (rev 5289) +++ branches/rewrite/pywikibot/page.py 2008-05-01 16:18:50 UTC (rev 5290) @@ -735,7 +735,7 @@ logging.debug( u"Page.move: throttle option is deprecated.") if reason is None: - pywikibot.output(u'Moving %s to [[%s]].' + logging.info(u'Moving %s to [[%s]].' % (self.title(asLink=True), newtitle)) reason = pywikibot.input(u'Please enter a reason for the move:') return self.site().move(self, newtitle, reason, @@ -755,7 +755,7 @@ logging.debug( u"Page.delete: throttle option is deprecated.") if reason is None: - pywikibot.output(u'Deleting %s.' % (self.title(asLink=True))) + logging.info(u'Deleting %s.' % (self.title(asLink=True))) reason = pywikibot.input(u'Please enter a reason for the deletion:') answer = u'y' if prompt and not hasattr(self.site(), '_noDeletePrompt'): @@ -833,7 +833,7 @@ logging.debug( u"Page.undelete: throttle option is deprecated.") if comment is None: - pywikibot.output(u'Preparing to undelete %s.' + logging.info(u'Preparing to undelete %s.' % (self.title(asLink=True))) comment = pywikibot.input( u'Please enter a reason for the undeletion:') @@ -863,7 +863,7 @@ un = u'un' else: un = u'' - pywikibot.output(u'Preparing to %sprotect %s.' + logging.info(u'Preparing to %sprotect %s.' % (un, self.title(asLink=True))) reason = pywikibot.input(u'Please enter a reason for the action:') if unprotect: @@ -1158,11 +1158,11 @@ catname = self.site().category_namespace() + ':' + catname targetCat = Category(self.site(), catname) if targetCat.exists(): - pywikibot.output('Target page %s already exists!' + logging.warn('Target page %s already exists!' % targetCat.title()) return False else: - pywikibot.output('Moving text from %s to %s.' + logging.info('Moving text from %s to %s.' % (self.title(), targetCat.title())) authors = ', '.join(self.contributingUsers()) creationSummary = pywikibot.translate( @@ -1194,11 +1194,11 @@ catname = self.site().category_namespace() + ':' + catname targetCat = Category(self.site(), catname) if targetCat.exists(): - pywikibot.output('Target page %s already exists!' + logging.warn('Target page %s already exists!' % targetCat.title()) return False else: - pywikibot.output('Moving text from %s to %s.' + logging.info('Moving text from %s to %s.' % (self.title(), targetCat.title())) authors = ', '.join(self.contributingUsers()) creationSummary = pywikibot.translate(
Modified: branches/rewrite/pywikibot/site.py =================================================================== --- branches/rewrite/pywikibot/site.py 2008-05-01 15:15:46 UTC (rev 5289) +++ branches/rewrite/pywikibot/site.py 2008-05-01 16:18:50 UTC (rev 5290) @@ -13,7 +13,7 @@ import pywikibot from pywikibot.throttle import Throttle from pywikibot.data import api -from exceptions import * +from pywikibot.exceptions import * import config
import logging @@ -49,15 +49,13 @@ exec "import %s_family as myfamily" % fam except ImportError: if fatal: - output(u"""\ + logging.exception(u"""\ Error importing the %s family. This probably means the family does not exist. Also check your configuration file.""" % fam) - import traceback - traceback.print_stack() sys.exit(1) else: - raise ValueError("Family %s does not exist" % repr(fam)) + raise Error("Family %s does not exist" % fam) return myfamily.Family()