Index: trunk/pywikipedia/version.py |
— | — | @@ -2,6 +2,7 @@ |
3 | 3 | """ Module to determine the pywikipedia version (tag, revision and date) """ |
4 | 4 | # |
5 | 5 | # (C) Merlijn 'valhallasw' van Deen, 2007-2008 |
| 6 | +# (C) xqt, 2010-2011 |
6 | 7 | # (C) Pywikipedia bot team, 2007-2011 |
7 | 8 | # |
8 | 9 | # Distributed under the terms of the MIT license. |
— | — | @@ -28,6 +29,7 @@ |
29 | 30 | try: |
30 | 31 | (tag, rev, date) = getversion_svn() |
31 | 32 | except Exception, e: |
| 33 | + print e |
32 | 34 | try: |
33 | 35 | (tag, rev, date) = getversion_nightly() |
34 | 36 | except Exception, e: |
— | — | @@ -52,16 +54,31 @@ |
53 | 55 | # if not os.path.isabs(_program_dir): |
54 | 56 | # _program_dir = os.path.normpath(os.path.join(os.getcwd(), _program_dir)) |
55 | 57 | entries = open(os.path.join(_program_dir, '.svn/entries')) |
56 | | - for i in range(4): |
57 | | - entries.readline() |
58 | | - tag = entries.readline().strip() |
59 | | - t = tag.split('://') |
60 | | - t[1] = t[1].replace('svn.wikimedia.org/svnroot/pywikipedia/', '') |
61 | | - tag = '[%s] %s' % (t[0], t[1]) |
62 | | - for i in range(4): |
63 | | - entries.readline() |
64 | | - date = time.strptime(entries.readline()[:19],'%Y-%m-%dT%H:%M:%S') |
65 | | - rev = entries.readline()[:-1] |
| 58 | + version = entries.readline().strip() |
| 59 | + #use sqlite table for new entries format |
| 60 | + if version == "12": |
| 61 | + entries.close() |
| 62 | + from sqlite3 import dbapi2 as sqlite |
| 63 | + from datetime import datetime |
| 64 | + con = sqlite.connect(os.path.join(_program_dir, ".svn/wc.db")) |
| 65 | + cur = con.cursor() |
| 66 | + cur.execute( '''select local_relpath, repos_path, revision, changed_date from nodes order by revision desc''') |
| 67 | + name, tag, rev, date = cur.fetchone() |
| 68 | + con.close() |
| 69 | + tag = tag.rstrip(name) |
| 70 | + date = time.gmtime(date/1000000) |
| 71 | + else: |
| 72 | + for i in range(3): |
| 73 | + entries.readline() |
| 74 | + tag = entries.readline().strip() |
| 75 | + t = tag.split('://') |
| 76 | + t[1] = t[1].replace('svn.wikimedia.org/svnroot/pywikipedia/', '') |
| 77 | + tag = '[%s] %s' % (t[0], t[1]) |
| 78 | + for i in range(4): |
| 79 | + entries.readline() |
| 80 | + date = time.strptime(entries.readline()[:19],'%Y-%m-%dT%H:%M:%S') |
| 81 | + rev = entries.readline()[:-1] |
| 82 | + entries.close() |
66 | 83 | if not date or not tag or not rev: |
67 | 84 | raise ParseError |
68 | 85 | return (tag, rev, date) |