Revision: 7985 Author: russblau Date: 2010-03-10 15:45:02 +0000 (Wed, 10 Mar 2010)
Log Message: ----------- Replace logger.debug() statements with pywikibot.output(); needed to allow -debug flag to work, but breaks per-component debug (-debug:wiki). Further work in this area still needed.
Modified Paths: -------------- branches/rewrite/pywikibot/__init__.py branches/rewrite/pywikibot/comms/http.py branches/rewrite/pywikibot/comms/threadedhttp.py branches/rewrite/pywikibot/login.py branches/rewrite/pywikibot/site.py branches/rewrite/pywikibot/throttle.py
Modified: branches/rewrite/pywikibot/__init__.py =================================================================== --- branches/rewrite/pywikibot/__init__.py 2010-03-09 19:07:34 UTC (rev 7984) +++ branches/rewrite/pywikibot/__init__.py 2010-03-10 15:45:02 UTC (rev 7985) @@ -165,8 +165,9 @@ key = '%s:%s:%s' % (fam, code, user) if not key in _sites: _sites[key] = __Site(code=code, fam=fam, user=user, sysop=sysop) - logger.debug(u"Instantiating Site object '%(site)s'" - % {'site': _sites[key]}) + pywikibot.output(u"Instantiating Site object '%(site)s'" + % {'site': _sites[key]}, + level=pywikibot.DEBUG) return _sites[key]
getSite = Site # alias for backwards-compability @@ -283,7 +284,8 @@ logger = logging.getLogger("pywiki.wiki")
if not stopped: - logger.debug("stopme() called") + pywikibot.output(u"stopme() called", + level=pywikibot.DEBUG) count = sum(1 for thd in threadpool if thd.isAlive()) if count: pywikibot.output(u"Waiting for about %(count)s pages to be saved."
Modified: branches/rewrite/pywikibot/comms/http.py =================================================================== --- branches/rewrite/pywikibot/comms/http.py 2010-03-09 19:07:34 UTC (rev 7984) +++ branches/rewrite/pywikibot/comms/http.py 2010-03-10 15:45:02 UTC (rev 7985) @@ -50,9 +50,11 @@ try: cookie_jar.load() except (IOError, cookielib.LoadError): - logger.debug("Loading cookies failed.") + pywikibot.output(u"Loading cookies failed.", + level=pywikibot.DEBUG) else: - logger.debug("Loaded cookies from file.") + pywikibot.output(u"Loaded cookies from file.", + level=pywikibot.DEBUG)
# Build up HttpProcessors @@ -72,7 +74,8 @@ level=pywikibot.VERBOSE) for i in threads: i.join() - logger.debug('All threads finished.') + pywikibot.output(u"All threads finished.", + level=pywikibot.VERBOSE) atexit.register(_flush)
# export cookie_jar to global namespace
Modified: branches/rewrite/pywikibot/comms/threadedhttp.py =================================================================== --- branches/rewrite/pywikibot/comms/threadedhttp.py 2010-03-09 19:07:34 UTC (rev 7984) +++ branches/rewrite/pywikibot/comms/threadedhttp.py 2010-03-10 15:45:02 UTC (rev 7985) @@ -58,7 +58,8 @@ The pool drops excessive connections added.
""" - logger.debug("Creating connection pool.") + pywikibot.output(u"Creating connection pool.", + level=pywikibot.DEBUG) self.connections = {} self.lock = threading.Lock() self.maxnum = maxnum @@ -67,8 +68,9 @@ """Destructor to close all connections in the pool.""" self.lock.acquire() try: - logger.debug("Closing connection pool (%s connections)" - % len(self.connections)) + pywikibot.output(u"Closing connection pool (%s connections)" + % len(self.connections), + level=pywikibot.DEBUG) for key in self.connections: for connection in self.connections[key]: connection.close() @@ -91,8 +93,9 @@ try: if identifier in self.connections: if len(self.connections[identifier]) > 0: - logger.debug("Retrieved connection from '%s' pool." - % identifier) + pywikibot.output(u"Retrieved connection from '%s' pool." + % identifier, + level=pywikibot.DEBUG) return self.connections[identifier].pop() return None finally: @@ -111,8 +114,9 @@ self.connections[identifier] = []
if len(self.connections[identifier]) == self.maxnum: - logger.debug('closing %s connection %r' - % (identifier, connection)) + pywikibot.output(u"closing %s connection %r" + % (identifier, connection), + level=pywikibot.DEBUG) connection.close() del connection else: @@ -206,9 +210,11 @@ # Redirect hack: we want to regulate redirects follow_redirects = self.follow_redirects self.follow_redirects = False - logger.debug('%r' % ( - (uri.replace("%7C","|"), - method, body, headers, max_redirects, connection_type),)) + pywikibot.output(u"%r" % ( + (uri.replace("%7C","|"), method, body, + headers, max_redirects, + connection_type),), + level=pywikibot.DEBUG) try: (response, content) = httplib2.Http.request( self, uri, method, body, headers, @@ -264,8 +270,9 @@ location) if authority == None: response['location'] = httplib2.urlparse.urljoin(uri, location) - logger.debug('Relative redirect: changed [%s] to [%s]' - % (location, response['location'])) + pywikibot.output(u"Relative redirect: changed [%s] to [%s]" + % (location, response['location']), + level=pywikibot.DEBUG) if response.status == 301 and method in ["GET", "HEAD"]: response['-x-permanent-redirect-url'] = response['location'] if "content-location" not in response: @@ -330,11 +337,13 @@ def run(self): # The Queue item is expected to either an HttpRequest object # or None (to shut down the thread) - logger.debug('Thread started, waiting for requests.') + pywikibot.output(u"Thread started, waiting for requests.", + level=pywikibot.DEBUG) while (True): item = self.queue.get() if item is None: - logger.debug('Shutting down thread.') + pywikibot.output(u"Shutting down thread.", + level=pywikibot.DEBUG) return try: item.data = self.http.request(*item.args, **item.kwargs)
Modified: branches/rewrite/pywikibot/login.py =================================================================== --- branches/rewrite/pywikibot/login.py 2010-03-09 19:07:34 UTC (rev 7984) +++ branches/rewrite/pywikibot/login.py 2010-03-10 15:45:02 UTC (rev 7985) @@ -143,7 +143,8 @@ """ # THIS IS OVERRIDDEN IN data/api.py filename = config.datafilepath('pywikibot.lwp') - logger.debug(u"Storing cookies to %s" % filename) + pywikibot.output(u"Storing cookies to %s" % filename, + level=pywikibot.DEBUG) f = open(filename, 'w') f.write(data) f.close()
Modified: branches/rewrite/pywikibot/site.py =================================================================== --- branches/rewrite/pywikibot/site.py 2010-03-09 19:07:34 UTC (rev 7984) +++ branches/rewrite/pywikibot/site.py 2010-03-10 15:45:02 UTC (rev 7985) @@ -761,8 +761,9 @@
def isBlocked(self, sysop=False): """Deprecated synonym for is_blocked""" - logger.debug( - "Site method 'isBlocked' should be changed to 'is_blocked'") + pywikibot.output( + u"Site method 'isBlocked' should be changed to 'is_blocked'", + level=pywikibot.DEBUG) return self.is_blocked(sysop)
def checkBlocks(self, sysop = False): @@ -1113,7 +1114,8 @@ % (len(cache), self) ) for pagedata in rvgen: - logger.debug("Preloading %s" % pagedata) + pywikibot.output(u"Preloading %s" % pagedata, + level=pywikibot.DEBUG) try: if pagedata['title'] not in cache: pywikibot.output( @@ -1123,9 +1125,12 @@ ) continue except KeyError: - logger.debug("No 'title' in %s" % pagedata) - logger.debug("pageids=%s" % pageids) - logger.debug("titles=%s" % cache.keys()) + pywikibot.output(u"No 'title' in %s" % pagedata, + level=pywikibot.DEBUG) + pywikibot.output(u"pageids=%s" % pageids, + level=pywikibot.DEBUG) + pywikibot.output(u"titles=%s" % cache.keys(), + level=pywikibot.DEBUG) continue page = cache[pagedata['title']] api.update_page(page, pagedata) @@ -1150,7 +1155,8 @@ % (page.title(withSection=False, asLink=True), item['title'])) api.update_page(page, item) - logger.debug(str(item)) + pywikibot.output(unicode(item), + level=pywikibot.DEBUG) return item[tokentype + "token"]
# following group of methods map more-or-less directly to API queries @@ -1555,8 +1561,9 @@ if not isinstance(namespace, int): raise Error("allpages: only one namespace permitted.") if includeredirects is not None: - logger.debug( -"allpages: 'includeRedirects' argument is deprecated; use 'filterredirs'.") + pywikibot.output( +u"allpages: 'includeRedirects' argument is deprecated; use 'filterredirs'.", + level=pywikibot.DEBUG) if includeredirects: if includeredirects == "only": filterredirs = True @@ -2241,12 +2248,14 @@ while True: try: result = req.submit() - logger.debug("editpage response: %s" % result) + pywikibot.output(u"editpage response: %s" % result, + level=pywikibot.DEBUG) except api.APIError, err: self.unlock_page(page) if err.code.endswith("anon") and self.logged_in(): - logger.debug( -"editpage: received '%s' even though bot is logged in" % err.code) + pywikibot.output( +u"editpage: received '%s' even though bot is logged in" % err.code, + level=pywikibot.DEBUG) errdata = { 'site': self, 'title': page.title(withSection=False), @@ -2263,8 +2272,10 @@ raise LockedPage(errdata['title']) if err.code in self._ep_errors: raise Error(self._ep_errors[err.code] % errdata) - logger.debug("editpage: Unexpected error code '%s' received." - % err.code) + pywikibot.output( + u"editpage: Unexpected error code '%s' received." + % err.code, + level=pywikibot.DEBUG) raise assert ("edit" in result and "result" in result["edit"]), result if result["edit"]["result"] == "Success": @@ -2375,11 +2386,13 @@ req['noredirect'] = "" try: result = req.submit() - logger.debug("movepage response: %s" % result) + pywikibot.output(u"movepage response: %s" % result, + level=pywikibot.DEBUG) except api.APIError, err: if err.code.endswith("anon") and self.logged_in(): - logger.debug( -"movepage: received '%s' even though bot is logged in" % err.code) + pywikibot.output( +u"movepage: received '%s' even though bot is logged in" % err.code, + level=pywikibot.DEBUG) errdata = { 'site': self, 'oldtitle': oldtitle, @@ -2390,8 +2403,9 @@ } if err.code in self._mv_errors: raise Error(self._mv_errors[err.code] % errdata) - logger.debug("movepage: Unexpected error code '%s' received." - % err.code) + pywikibot.output(u"movepage: Unexpected error code '%s' received." + % err.code, + level=pywikibot.DEBUG) raise finally: self.unlock_page(page) @@ -2461,8 +2475,9 @@ } if err.code in self._rb_errors: raise Error(self._rb_errors[err.code] % errdata) - logger.debug("rollback: Unexpected error code '%s' received." - % err.code) + pywikibot.output(u"rollback: Unexpected error code '%s' received." + % err.code, + level=pywikibot.DEBUG) raise finally: self.unlock_page(page) @@ -2508,8 +2523,9 @@ } if err.code in self._dl_errors: raise Error(self._dl_errors[err.code] % errdata) - logger.debug("delete: Unexpected error code '%s' received." - % err.code) + pywikibot.output(u"delete: Unexpected error code '%s' received." + % err.code, + level=pywikibot.DEBUG) raise finally: self.unlock_page(page)
Modified: branches/rewrite/pywikibot/throttle.py =================================================================== --- branches/rewrite/pywikibot/throttle.py 2010-03-09 19:07:34 UTC (rev 7984) +++ branches/rewrite/pywikibot/throttle.py 2010-03-10 15:45:02 UTC (rev 7985) @@ -66,7 +66,8 @@ global pid self.lock.acquire() mysite = self.mysite - logger.debug("Checking multiplicity: pid = %(pid)s" % globals()) + pywikibot.output(u"Checking multiplicity: pid = %(pid)s" % globals(), + level=pywikibot.DEBUG) try: processes = [] my_pid = pid or 1 # start at 1 if global pid not yet set
pywikipedia-svn@lists.wikimedia.org