http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11028
Revision: 11028 Author: yurik Date: 2013-02-05 06:20:56 +0000 (Tue, 05 Feb 2013) Log Message: ----------- UserAgent to match the main branch - "script/ver pywikipediabot/2.0"
Modified Paths: -------------- branches/rewrite/pywikibot/comms/http.py branches/rewrite/pywikibot/version.py
Modified: branches/rewrite/pywikibot/comms/http.py =================================================================== --- branches/rewrite/pywikibot/comms/http.py 2013-02-04 07:36:21 UTC (rev 11027) +++ branches/rewrite/pywikibot/comms/http.py 2013-02-05 06:20:56 UTC (rev 11028) @@ -32,13 +32,22 @@ import pywikibot import cookielib import threadedhttp +import pywikibot.version
_logger = "comm.http"
# global variables
-useragent = 'Pywikipediabot/2.0' # This should include some global version string +# the User-agent: header. The default is +# '<script>/<revision> Pywikipediabot/2.0', where '<script>' is the tail +# path component and file name of the currently executing script and +# revision is the SVN revision of Pywikipediabot. +USER_AGENT_FORMAT = '{script}/r{version[rev]} Pywikipediabot/2.0' +useragent = (USER_AGENT_FORMAT.format( + script=('-'.join(pywikibot.version.get_executing_script())), + version=pywikibot.version.getversiondict() +)) numthreads = 1 threads = []
Modified: branches/rewrite/pywikibot/version.py =================================================================== --- branches/rewrite/pywikibot/version.py 2013-02-04 07:36:21 UTC (rev 11027) +++ branches/rewrite/pywikibot/version.py 2013-02-05 06:20:56 UTC (rev 11028) @@ -12,6 +12,7 @@ import os import time import urllib +import sys
cache = None
@@ -134,3 +135,16 @@ exec(line) break return __version__ + +## Get the tail path component and file name of the currently executing +# script. Returns a tuple. +# +def get_executing_script(): + """Get the last path component and filename of the currently + executing script.""" + try: + script = os.path.abspath(sys.modules['__main__'].__file__) + except (KeyError, AttributeError): + script = sys.executable + path, file = os.path.split(script) + return (os.path.basename(path), file)