source: main/trunk/openPLM/__init__.py @ 2566

Revision 2566, 1.8 KB checked in by pcosquer, 6 years ago (diff)

s/dev/final/ ?

Line 
1import os.path
2import re
3
4VERSION = (2, 0, 0, 'final', 0)
5
6def get_svn_revision(path):
7    """
8    Returns the SVN revision in the form SVN-XXXX,
9    where XXXX is the revision number.
10
11    Returns SVN-unknown if anything goes wrong, such as an unexpected
12    format of internal SVN files.
13
14    *path* must be a directory whose SVN info you want to
15    inspect. If it's not provided, this will use the root django/ package
16    directory.
17    """
18    # from old djnago.utils.version package (< 1.5)
19    rev = None
20    entries_path = '%s/.svn/entries' % path
21
22    try:
23        entries = open(entries_path, 'r').read()
24    except IOError:
25        pass
26    else:
27        # Versions >= 7 of the entries file are flat text.  The first line is
28        # the version number. The next set of digits after 'dir' is the revision.
29        if re.match('(\d+)', entries):
30            rev_match = re.search('\d+\s+dir\s+(\d+)', entries)
31            if rev_match:
32                rev = rev_match.groups()[0]
33        # Older XML versions of the file specify revision as an attribute of
34        # the first entries node.
35        else:
36            from xml.dom import minidom
37            dom = minidom.parse(entries_path)
38            rev = dom.getElementsByTagName('entry')[0].getAttribute('revision')
39
40    if rev:
41        return u'SVN-%s' % rev
42    return u'SVN-unknown'
43
44def get_version():
45    version = '%s.%s' % (VERSION[0], VERSION[1])
46    if VERSION[2]:
47        version = '%s.%s' % (version, VERSION[2])
48    if VERSION[3:] == ('alpha', 0):
49        version = '%s pre-alpha' % version
50    else:
51        if VERSION[3] != 'final':
52            version = '%s %s %s' % (version, VERSION[3], VERSION[4])
53    svn_rev = get_svn_revision(os.path.dirname(__file__))
54    if svn_rev != u'SVN-unknown':
55        version = "%s %s" % (version, svn_rev)
56    return version
Note: See TracBrowser for help on using the repository browser.