File: version.py

package info (click to toggle)
thuban 1.2.2-14
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 9,176 kB
  • sloc: python: 30,410; ansic: 6,181; xml: 4,234; cpp: 1,595; makefile: 145
file content (213 lines) | stat: -rw-r--r-- 6,579 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# Copyright (C) 2002, 2003, 2004, 2008 by Intevation GmbH
# Authors:
# Thomas Koester <tkoester@intevation.de>
# Frank Koormann <frank.koormann@intevation.de>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with the software for details.

"""
Thuban version information
"""

__version__ = "$Revision: 2885 $"
# $Source$
# $Id: version.py 2885 2009-08-18 13:35:30Z dpinte $


# Note that this file defines the version number of Thuban for the about
# dialog.

# The thuban version string is build from two values, thuban_branch and
# thuban_release.  If release is "cvs" the code is from a non-released
# cvs version and the version string is built from the branch, the
# release and an approximation of the date (e.g. the most recent date of
# the ChangeLog file or the most recent modification time of a source
# file).  Otherwise the string is build from the branch and the release.
# E.g. given
#
#  thuban_branch = "1.1"
#  thuban_release = "svn"
#
# the version string will be "Thuban 1.1 svn-20040224" (obviously the
# actual date might differ :) ). You can add more behind the "svn" to 
# e.g. to indicate a branch and the date will still be added.
# OTOH, given
#
#  thuban_branch = "1.0"
#  thuban_release = "1"
#
# the version string will be "Thuban 1.0.1"
#

thuban_branch = "1.2"
thuban_release = "2"



import sys, os, os.path
import time
from string import split

from Thuban import  _
from Thuban.Lib.version import make_tuple

if __name__ == "__main__":
    import sys
    __file__ = sys.argv[0]

def is_relevant_file(file):
    """check if a file is relevant for determining the current version"""
    extensions = ['.py', '.xpm', '.c', '.h']
    return os.path.isfile(file) and os.path.splitext(file)[1] in extensions

def visit(args, dirname, names):
    """helper for os.path.walk; save mtime of newest file for this directory"""
    files = filter(is_relevant_file,
                   [os.path.join(dirname, file) for file in names])
    args['max'] = max([args['max']] + map(os.path.getmtime, files))

def get_date(format):
    """strftime formatted mtime of the newest relevant file"""
    dir = os.path.dirname(os.path.abspath(__file__))
    args = {'max': 0}
    os.path.walk(dir, visit, args)
    return time.strftime(format, time.localtime(args['max']))

def get_changelog_date():
    changelog = os.path.join(os.path.dirname(__file__), os.pardir, "ChangeLog")
    try:
        file = open(changelog, "r")
        line = file.readline()
        file.close() 
    except:
        return ""
    return 'ChangeLog %s' % line.split(" ")[0]


# 
# Fill in versions with the different versions of the libraries
# that Thuban is using or requires (only if those libraries are
# available.
#

versions = {}

if thuban_release[0:3] == "svn":
    version = '%s %s-%s' % (thuban_branch, thuban_release, get_date('%Y%m%d'))
    longversion = '%s\n%s' % (version, get_changelog_date())
else:
    version = thuban_branch + "." + thuban_release
    longversion = 'Release Version ' + version

versions['thuban'] = version
versions['thuban-long'] = longversion

# wxPython

from wx import __version__ as wxPython_version
versions['wxPython'] = wxPython_version
versions['wxPython-tuple'] = make_tuple(wxPython_version)

# Python
versions['python'] = "%d.%d.%d" % sys.version_info[:3]
versions['python-tuple'] = sys.version_info[:3]

# PySQLite
try:
    import sqlite3 as sqlite
except ImportError:
    try:
        from pysqlite2 import dbapi2 as sqlite
    except ImportError:
        import sqlite
versions['pysqlite'] = sqlite.version
versions['pysqlite-tuple'] = make_tuple(sqlite.version)

# SQLite
try:
    from sqlite3 import sqlite_version
    versions['sqlite'] = sqlite_version
    versions['sqlite-tuple'] = make_tuple(sqlite_version)
except ImportError:
    try:
        from pysqlite2._sqlite import sqlite_version
        versions['sqlite'] = sqlite_version
        versions['sqlite-tuple'] = make_tuple(sqlite_version)
    except ImportError:
        from _sqlite import sqlite_version
        versions['sqlite'] = sqlite_version()
        versions['sqlite-tuple'] = make_tuple(sqlite_version())

# GDAL
from  Thuban.Model.resource import has_gdal_support
if has_gdal_support():
    from gdalwarp import get_gdal_version
    versions['gdal'] = get_gdal_version()
    versions['gdal-tuple'] = make_tuple(get_gdal_version())

from wxproj import get_proj_version, get_gtk_version, get_wx_version

# GTK
gtk_ver = get_gtk_version()
if gtk_ver:
    versions['gtk'] = ".".join(map(str, gtk_ver))
    versions['gtk-tuple'] = gtk_ver

# PROJ
proj_ver = get_proj_version()
if proj_ver:
    versions['proj'] = ".".join(map(str, proj_ver))
    versions['proj-tuple'] = proj_ver

wxproj_wx_version = get_wx_version()
versions['wxproj-wx'] = ".".join(map(str, wxproj_wx_version))
versions['wxproj-wx-tuple'] = wxproj_wx_version


# psycopg/postgis
import Thuban.Model.postgisdb
if Thuban.Model.postgisdb.has_postgis_support():
    v = Thuban.Model.postgisdb.psycopg_version()
    versions['psycopg'] = v
    versions['psycopg-tuple'] = make_tuple(v)

def verify_versions():
    """Verify that Thuban is using the correct versions of libraries.

    Returns a non-empty list of strings indicating which libraries
    are wrong, or the empty list if everthing is ok.
    """

    #
    # The 'name' below must correspong to an mapping in 'versions'.
    # There must also exist a 'name'-tuple mapping.
    #
    #         title           name       version
    list = [["Python",      "python",   (2, 3, 5)],
            ["wxPython",    "wxPython", (2, 6, 0)],
            ["SQLite",      "sqlite",   (2, 8, 3)],
            ["PySQLite",    "pysqlite", (1, 0, 1)],
            ["PROJ",        "proj",     (4, 4, 5)],
            ["GTK",         "gtk",      (1, 2, 3)],
            ["GDAL",        "gdal",     (1, 3, 2)]]

    errors = []
    for title, name, version in list:
        tup = versions.get("%s-tuple" % name, None)
        if tup and tup < version:
            errors.append(_("%s %s < %s") % \
                          (title, versions[name], ".".join(map(str, version))))

    # Check whether the wxWindows version of wxPython and thuban's
    # wxproj module match.  If they don't match, segfaults are likely.
    if versions["wxproj-wx-tuple"][:2] != versions["wxPython-tuple"][:2]:
        errors.append(_("Thuban was compiled with wx %(wxproj-wx)s"
                        " but wxPython is %(wxPython)s")
                      % versions)

    return errors

if __name__ == "__main__":
    print longversion