Revision: 6185 Author: russblau Date: 2008-12-22 17:04:08 +0000 (Mon, 22 Dec 2008)
Log Message: ----------- documentation cleanup and logger ids
Modified Paths: -------------- branches/rewrite/pywikibot/README-conversion.txt branches/rewrite/pywikibot/bot.py branches/rewrite/pywikibot/comms/http.py branches/rewrite/pywikibot/comms/threadedhttp.py branches/rewrite/pywikibot/data/api.py branches/rewrite/pywikibot/family.py branches/rewrite/pywikibot/login.py branches/rewrite/pywikibot/page.py branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/README-conversion.txt =================================================================== --- branches/rewrite/pywikibot/README-conversion.txt 2008-12-22 15:42:59 UTC (rev 6184) +++ branches/rewrite/pywikibot/README-conversion.txt 2008-12-22 17:04:08 UTC (rev 6185) @@ -2,14 +2,17 @@ Pywikipediabot framework to version 2.
Most importantly, note that the version 2 framework *only* supports wikis -using MediaWiki v.1.12 or higher software. If you need to access a wiki that +using MediaWiki v.1.14 or higher software. If you need to access a wiki that uses older software, you should continue using version 1 for this purpose.
-The "root" namespace used in the project has changed from "wikipedia" +The root namespace used in the project has changed from "wikipedia" to "pywikibot". References to wikipedia need to be changed globally to pywikibot. Unless noted in this document, other names have not changed; for example, wikipedia.Page can be replaced by pywikibot.Page throughout any -bot. +bot. An effort has been made to design the interface to be as backwards- +compatible as possible, so that in most cases it should be possible to convert +scripts to the new interface simply by changing import statements and doing +global search-and-replace on module names, as discussed in this document.
With pywikipedia scripts were importing "wikipedia" or "pagegenerators" libraries; pywikibot is now written as a standard package, and other modules @@ -17,24 +20,36 @@ most commonly-used names are imported into the pywikibot namespace, so that module names don't need to be used unless specified in the documentation.
-(To use it, just import "pywikibot", assuming that pywikibot/ is in sys.path) +Make sure that the directory that contains the "pywikibot" subdirectory (or +folder) is in sys.path.
+The following changes, at a minimum, need to be made to allow scripts to run: + + change "import wikipedia" to "import pywikibot" + change "import pagegenerators" to "from pywikibot import pagegenerators" + change "import config" to "from pywikibot import config" + change "import catlib" to "from pywikibot import catlib" + change "wikipedia." to "pywikibot." + == Python librairies ==
[Note: the goal will be to package pywikibot with setuptools easy_install, so that these dependencies will be loaded automatically when the package is installed, and users won't need to worry about this...]
-To run pywikibot, you will need the httplib2, simplejson, and setuptools packages-- +To run pywikibot, you will need the httplib2, simplejson, and setuptools +packages-- * httplib2 : http://code.google.com/p/httplib2/ * setuptools : http://pypi.python.org/pypi/setuptools/ * simplejson : http://svn.red-bean.com/bob/simplejson/tags/simplejson-1.7.1/docs/index.html
-or, if you already have setuptools installed, just execute 'easy_install httplib2' -and 'easy_install simplejson' +or, if you already have setuptools installed, just execute +'easy_install httplib2' and 'easy_install simplejson'
-If you run into errors involving httplib2.urlnorm, update httplib2 to -0.4.0 (Ubuntu package python-httlib2 for example, is outdated) +If you run into errors involving httplib2.urlnorm, update httplib2 to 0.4.0 +(Ubuntu package python-httlib2, for example, is outdated). Note that +httplib2 will run under Python 2.6, but will emit DeprecationWarnings (which +are annoying but don't affect the ability to use the package).
== Page objects ==
Modified: branches/rewrite/pywikibot/bot.py =================================================================== --- branches/rewrite/pywikibot/bot.py 2008-12-22 15:42:59 UTC (rev 6184) +++ branches/rewrite/pywikibot/bot.py 2008-12-22 17:04:08 UTC (rev 6185) @@ -176,8 +176,10 @@ # ERROR - user error messages # CRITICAL - fatal error messages # Accordingly, do ''not'' use print statements in bot code; instead, - # send output to the pywikibot.output() function which will route it - # to the logging module. + # send output to logging.log(level, text) or one of its equivalents. + # For backwards-compatibility, pywikibot.output is supported, which + # directs output to logging.info() or other levels as appropriate, but + # its use in new code is deprecated.
logging.addLevelName(VERBOSE, "VERBOSE") # for messages to be displayed on terminal at "verbose" setting @@ -213,7 +215,7 @@ else: file_handler.setLevel(VERBOSE) form = logging.Formatter( - fmt="%(asctime)s %(filename)-18s:%(lineno)-4d " + fmt="%(asctime)s %(filename)18s, %(lineno)d: " "%(levelname)-8s %(message)s", datefmt="%Y-%m-%d %H:%M:%S" )
Modified: branches/rewrite/pywikibot/comms/http.py =================================================================== --- branches/rewrite/pywikibot/comms/http.py 2008-12-22 15:42:59 UTC (rev 6184) +++ branches/rewrite/pywikibot/comms/http.py 2008-12-22 17:04:08 UTC (rev 6185) @@ -31,7 +31,7 @@ import cookielib import threadedhttp
-logger = logging.getLogger("comm") +logger = logging.getLogger("comms.http")
# global variables
Modified: branches/rewrite/pywikibot/comms/threadedhttp.py =================================================================== --- branches/rewrite/pywikibot/comms/threadedhttp.py 2008-12-22 15:42:59 UTC (rev 6184) +++ branches/rewrite/pywikibot/comms/threadedhttp.py 2008-12-22 17:04:08 UTC (rev 6185) @@ -30,7 +30,7 @@ import cookielib import sys
-logger = logging.getLogger("comm") +logger = logging.getLogger("comms.threadedhttp")
# easy_install safeguarded dependencies
Modified: branches/rewrite/pywikibot/data/api.py =================================================================== --- branches/rewrite/pywikibot/data/api.py 2008-12-22 15:42:59 UTC (rev 6184) +++ branches/rewrite/pywikibot/data/api.py 2008-12-22 17:04:08 UTC (rev 6185) @@ -23,7 +23,7 @@ from pywikibot import login from pywikibot.exceptions import *
-logger = logging.getLogger() +logger = logging.getLogger("data.api")
lagpattern = re.compile(r"Waiting for [\d.]+: (?P<lag>\d+) seconds? lagged")
Modified: branches/rewrite/pywikibot/family.py =================================================================== --- branches/rewrite/pywikibot/family.py 2008-12-22 15:42:59 UTC (rev 6184) +++ branches/rewrite/pywikibot/family.py 2008-12-22 17:04:08 UTC (rev 6185) @@ -9,7 +9,7 @@
from datetime import datetime, timedelta
-logger = logging.getLogger("wiki") +logger = logging.getLogger("wiki.family")
# Parent class for all wiki families
Modified: branches/rewrite/pywikibot/login.py =================================================================== --- branches/rewrite/pywikibot/login.py 2008-12-22 15:42:59 UTC (rev 6184) +++ branches/rewrite/pywikibot/login.py 2008-12-22 17:04:08 UTC (rev 6185) @@ -50,7 +50,7 @@ from pywikibot import config from pywikibot.exceptions import *
-logger = logging.getLogger() +logger = logging.getLogger("wiki.login")
# On some wikis you are only allowed to run a bot if there is a link to
Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2008-12-22 15:42:59 UTC (rev 6184) +++ branches/rewrite/pywikibot/page.py 2008-12-22 17:04:08 UTC (rev 6185) @@ -23,7 +23,7 @@ import unicodedata import urllib
-logger = logging.getLogger("wiki") +logger = logging.getLogger("wiki.page")
reNamespace = re.compile("^(.+?) *: *(.*)$")
Modified: branches/rewrite/pywikibot/site.py =================================================================== --- branches/rewrite/pywikibot/site.py 2008-12-22 15:42:59 UTC (rev 6184) +++ branches/rewrite/pywikibot/site.py 2008-12-22 17:04:08 UTC (rev 6185) @@ -28,7 +28,7 @@ import threading import urllib
-logger = logging.getLogger("wiki") +logger = logging.getLogger("wiki.site")
class PageInUse(pywikibot.Error): """Page cannot be reserved for writing due to existing lock."""
pywikipedia-l@lists.wikimedia.org