Revision: 3935 Author: valhallasw Date: 2007-08-01 21:19:26 +0000 (Wed, 01 Aug 2007)
Log Message: ----------- New: version.py. returns pywikipedia version based on (in order) .svn/entries, version (file for use in nightlies) and wikipedia.__version__.
Added Paths: ----------- trunk/pywikipedia/version.py
Added: trunk/pywikipedia/version.py =================================================================== --- trunk/pywikipedia/version.py (rev 0) +++ trunk/pywikipedia/version.py 2007-08-01 21:19:26 UTC (rev 3935) @@ -0,0 +1,56 @@ +""" Module to determine the pywikipedia version (tag, revision and date) """ +# +# (C) Merlijn 'valhallasw' van Deen +# +# Distributed under the terms of the MIT license. +# +__version__ = '$Id$' + +import wikipediatools +import time +import sys + +class ParseError(Exception): + """ Parsing went wrong """ + +def getversion(): + try: + (tag, rev, date) = getversion_svn() + except Exception, e: + try: + (tag, rev, date) = getversion_nightly() + except IOError, e: + import wikipedia + d = wikipedia.__version__.split(' ') + tag = '' + date = time.strptime('T'.join(d[3:5]), '%Y-%m-%dT%H:%M:%SZ') + rev = d[2] + ' (wikipedia.py)' + + datestring = time.strftime('%b %d %Y, %H:%M:%S', date) + return '%s (r%s, %s)' % (tag, rev, datestring) + +def getversion_svn(): + entries = open(wikipediatools.absoluteFilename('.svn/entries')) + for i in range(4): + entries.readline() + tag = entries.readline().replace('svn+ssh://svn.wikimedia.org/svnroot/pywikipedia/', '').strip() + for i in range(4): + entries.readline() + date = time.strptime(entries.readline()[:19],'%Y-%m-%dT%H:%M:%S') + rev = entries.readline()[:-1] + if not date or not tag or not rev: + raise ParseError + return (tag, rev, date) + +def getversion_nightly(): + data = open(wikipediatools.absoluteFilename('version')) + tag = data.readline().strip() + date = time.strptime(data.readline()[:19],'%Y-%m-%dT%H:%M:%S') + rev = data.readline().strip() + if not date or not tag or not rev: + raise ParseError + return (tag, rev, date) + +if __name__ == '__main__': + print 'Pywikipedia %s' % getversion() + print 'Python %s' % sys.version \ No newline at end of file
Property changes on: trunk/pywikipedia/version.py ___________________________________________________________________ Name: svn:keywords + Id *.c = svn:eol-style=native *.cpp = svn:eol-style=native *.h = svn:eol-style=native *.dsp = svn:eol-style=CRLF *.dsw = svn:eol-style=CRLF *.sh = svn:eol-style=native Name: svn:executable *.txt + svn:eol-style=native *.png = svn:mime-type=image/png *.jpg = svn:mime-type=image/jpeg Makefile = svn:eol-style=native Name: svn:eol-style + native
pywikipedia-l@lists.wikimedia.org