1 |
frank |
922 |
#!/usr/bin/env python |
2 |
|
|
# |
3 |
|
|
# Copyright (C) 2002, 2003 by Intevation GmbH |
4 |
|
|
# Authors: |
5 |
|
|
# Thomas Koester <[email protected]> |
6 |
|
|
# Frank Koormann <[email protected]> |
7 |
|
|
# |
8 |
|
|
# This program is free software under the GPL (>=v2) |
9 |
|
|
# Read the file COPYING coming with the software for details. |
10 |
|
|
|
11 |
|
|
""" |
12 |
|
|
Thuban version information |
13 |
|
|
""" |
14 |
|
|
|
15 |
|
|
__version__ = "$Revision$" |
16 |
|
|
# $Source$ |
17 |
|
|
# $Id$ |
18 |
|
|
|
19 |
|
|
|
20 |
|
|
version = 'cvs' |
21 |
|
|
append_date = 1 |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
import os, os.path |
25 |
|
|
import time |
26 |
|
|
|
27 |
|
|
if __name__ == "__main__": |
28 |
|
|
import sys |
29 |
|
|
__file__ = sys.argv[0] |
30 |
|
|
|
31 |
|
|
def is_relevant_file(file): |
32 |
|
|
"""check if a file is relevant for determining the current version""" |
33 |
|
|
extensions = ['.py', '.xpm', '.c', '.h'] |
34 |
|
|
return os.path.isfile(file) and os.path.splitext(file)[1] in extensions |
35 |
|
|
|
36 |
|
|
def visit(args, dirname, names): |
37 |
|
|
"""helper for os.path.walk; save mtime of newest file for this directory""" |
38 |
|
|
files = filter(is_relevant_file, |
39 |
|
|
[os.path.join(dirname, file) for file in names]) |
40 |
|
|
args['max'] = max([args['max']] + map(os.path.getmtime, files)) |
41 |
|
|
|
42 |
|
|
def get_date(format): |
43 |
|
|
"""strftime formatted mtime of the newest relevant file""" |
44 |
|
|
dir = os.path.dirname(os.path.abspath(__file__)) |
45 |
|
|
args = {'max': 0} |
46 |
|
|
os.path.walk(dir, visit, args) |
47 |
|
|
return time.strftime(format, time.localtime(args['max'])) |
48 |
|
|
|
49 |
|
|
def get_changelog_date(): |
50 |
|
|
changelog = os.path.join(os.path.dirname(__file__), os.pardir, "ChangeLog") |
51 |
|
|
file = open(changelog, "r") |
52 |
|
|
line = file.readline() |
53 |
|
|
file.close() |
54 |
|
|
return line.split(" ")[0] |
55 |
|
|
|
56 |
|
|
if append_date: |
57 |
|
|
version = '%s-%s' % (version, get_date('%Y%m%d')) |
58 |
|
|
longversion = '%s\n ChangeLog %s' % (version, get_changelog_date()) |
59 |
|
|
#longversion = 'Thuban Release Version 0.2' |
60 |
|
|
|
61 |
|
|
if __name__ == "__main__": |
62 |
|
|
print longversion |