http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10961
Revision: 10961 Author: drtrigon Date: 2013-01-20 16:08:06 +0000 (Sun, 20 Jan 2013) Log Message: ----------- follow-up; to r10960 merged with trunk (the are now exactly the same)
Modified Paths: -------------- branches/rewrite/pywikibot/version.py branches/rewrite/scripts/version.py
Modified: branches/rewrite/pywikibot/version.py =================================================================== --- branches/rewrite/pywikibot/version.py 2013-01-20 16:03:08 UTC (rev 10960) +++ branches/rewrite/pywikibot/version.py 2013-01-20 16:08:06 UTC (rev 10961) @@ -11,7 +11,6 @@
import os import time -import sys import urllib
cache = None @@ -19,13 +18,20 @@ class ParseError(Exception): """ Parsing went wrong """
+def _get_program_dir(): + _program_dir = os.path.normpath(os.path.split(os.path.dirname(__file__))[0]) +# _program_dir = _program_dir.rstrip(os.path.basename(_program_dir)) +## if not os.path.isabs(_program_dir): +## _program_dir = os.path.normpath(os.path.join(os.getcwd(), _program_dir)) + return _program_dir + def getversion(): data = getversiondict() try: rev2 = int(getversion_onlinerepo()) rev1 = int(str(data['rev']).split()[0]) data['cmp_ver'] = 'OUTDATED' if rev1 < rev2 else 'ok' - except ParseError: + except Exception: data['cmp_ver'] = 'n/a' return '%(tag)s (r%(rev)s, %(date)s, %(cmp_ver)s)' % data
@@ -35,39 +41,38 @@ return cache try: (tag, rev, date) = getversion_svn() - except Exception, e: + except Exception: try: (tag, rev, date) = getversion_nightly() - except Exception, e: - #version = getfileversion('pywikibot/__init__.py') - import pywikibot - version = pywikibot.__version__ - if len(version) == 4: + except Exception: + try: + version = getfileversion('pywikibot/__init__.py') + if not version: + # fall-back in case everything breaks (should not be used) + import pywikibot + version = pywikibot.__version__ + + id, file, rev, date, ts, author, dollar = version.split(' ') + tag = '' + date = time.strptime('%sT%s' % (date, ts), '%Y-%m-%dT%H:%M:%SZ') + rev += ' (pywikibot/__init__.py)' + except: # nothing worked; version unknown (but suppress exceptions) # the value is most likely '$Id' + '$', it means that # wikipedia.py got imported without using svn at all - cache = dict(tag='', rev='-1 (unknown)', date='0 (unknown)') - return cache + return dict(tag='', rev='-1 (unknown)', date='0 (unknown)')
- id, file, rev, date, ts, author, dollar = version.split(' ') - tag = '' - date = time.strptime('%sT%s' % (date, ts), '%Y-%m-%dT%H:%M:%SZ') - rev += ' (pywikibot/__init__.py)' datestring = time.strftime('%Y/%m/%d, %H:%M:%S', date) cache = dict(tag=tag, rev=rev, date=datestring) return cache
def getversion_svn(path=None): - _program_dir = path or os.path.normpath(os.path.dirname(sys.argv[0])) - _program_dir = _program_dir.rstrip(os.path.basename(_program_dir)) -# if not os.path.isabs(_program_dir): -# _program_dir = os.path.normpath(os.path.join(os.getcwd(), _program_dir)) + _program_dir = path or _get_program_dir() entries = open(os.path.join(_program_dir, '.svn/entries')) version = entries.readline().strip() #use sqlite table for new entries format if version == "12": entries.close() from sqlite3 import dbapi2 as sqlite - from datetime import datetime con = sqlite.connect(os.path.join(_program_dir, ".svn/wc.db")) cur = con.cursor() cur.execute( '''select local_relpath, repos_path, revision, changed_date from nodes order by revision desc, changed_date desc''') @@ -120,8 +125,7 @@ # without importing it (thus can be done for any file) # def getfileversion(filename): - _program_dir = os.path.normpath(os.path.dirname(sys.argv[0])) - _program_dir = _program_dir.rstrip(os.path.basename(_program_dir)) + _program_dir = _get_program_dir() __version__ = None fn = os.path.join(_program_dir, filename) if os.path.exists(fn):
Modified: branches/rewrite/scripts/version.py =================================================================== --- branches/rewrite/scripts/version.py 2013-01-20 16:03:08 UTC (rev 10960) +++ branches/rewrite/scripts/version.py 2013-01-20 16:08:06 UTC (rev 10961) @@ -11,12 +11,15 @@
from pywikibot.version import * from pywikibot import config2 as config +import sys
if __name__ == '__main__': print 'Pywikibot %s' % getversion() print 'Python %s' % sys.version + #print 'config-settings:' + #print 'site_interface =', config.site_interface + #print 'API_config_expiry =', config.API_config_expiry if not __import__('unicodedata').normalize('NFC', u'\u092e\u093e\u0930\u094d\u0915 \u091c\u093c\u0941\u0915\u0947\u0930\u092c\u0930\u094d\u0917') == u'\u092e\u093e\u0930\u094d\u0915 \u091c\u093c\u0941\u0915\u0947\u0930\u092c\u0930\u094d\u0917': print u'unicode test: triggers problem #3081100' else: print u'unicode test: ok' -
pywikipedia-svn@lists.wikimedia.org