Show More
@@ -1,62 +1,65 | |||
|
1 | 1 | # Copyright (C) 2005 by Intevation GmbH |
|
2 | 2 | # Author(s): |
|
3 | 3 | # Thomas Arendsen Hein <thomas@intevation.de> |
|
4 | 4 | # |
|
5 | 5 | # This program is free software under the GNU GPL (>=v2) |
|
6 | 6 | # Read the file COPYING coming with the software for details. |
|
7 | 7 | |
|
8 | 8 | """ |
|
9 | 9 | Mercurial version |
|
10 | 10 | """ |
|
11 | 11 | |
|
12 | 12 | import os |
|
13 | 13 | import os.path |
|
14 | 14 | import re |
|
15 | 15 | import time |
|
16 | 16 | |
|
17 | 17 | unknown_version = 'unknown' |
|
18 | remembered_version = False | |
|
18 | 19 | |
|
19 | 20 | def get_version(): |
|
20 | 21 | """Return version information if available.""" |
|
21 | 22 | try: |
|
22 | 23 | from mercurial.__version__ import version |
|
23 | 24 | except ImportError: |
|
24 | 25 | version = unknown_version |
|
25 | 26 | return version |
|
26 | 27 | |
|
27 | 28 | def write_version(version): |
|
28 | 29 | """Overwrite version file.""" |
|
29 | 30 | filename = os.path.join(os.path.dirname(__file__), '__version__.py') |
|
30 | 31 | f = open(filename, 'w') |
|
31 | 32 | f.write("# This file is auto-generated.\n") |
|
32 | 33 | f.write("version = %r\n" % version) |
|
33 | 34 | f.close() |
|
34 | 35 | |
|
35 | 36 | def remember_version(): |
|
36 | 37 | """Store version information.""" |
|
37 | f = os.popen("hg identify 2>/dev/null") # use real hg installation | |
|
38 | ident = f.read()[:-1] | |
|
39 | if not f.close() and ident: | |
|
40 | ids = ident.split(' ', 1) | |
|
41 | version = ids.pop(0) | |
|
42 | if version[-1] == '+': | |
|
43 |
version = |
|
|
44 | modified = True | |
|
45 | else: | |
|
46 |
modified = |
|
|
47 | if version.isalnum() and ids: | |
|
48 | for tag in ids[0].split('/'): | |
|
49 | # is a tag is suitable as a version number? | |
|
50 | if re.match(r'^(\d+\.)+[\w.-]+$', tag): | |
|
51 | version = tag | |
|
52 | break | |
|
53 | if modified: | |
|
54 | version += time.strftime('+%Y%m%d') | |
|
55 | else: | |
|
56 | version = unknown_version | |
|
57 | write_version(version) | |
|
38 | global remembered_version | |
|
39 | if os.access(".hg", os.F_OK): | |
|
40 | f = os.popen("hg identify 2>/dev/null") # use real hg installation | |
|
41 | ident = f.read()[:-1] | |
|
42 | if not f.close() and ident: | |
|
43 | ids = ident.split(' ', 1) | |
|
44 | version = ids.pop(0) | |
|
45 | if version[-1] == '+': | |
|
46 | version = version[:-1] | |
|
47 | modified = True | |
|
48 | else: | |
|
49 | modified = False | |
|
50 | if version.isalnum() and ids: | |
|
51 | for tag in ids[0].split('/'): | |
|
52 | # is a tag is suitable as a version number? | |
|
53 | if re.match(r'^(\d+\.)+[\w.-]+$', tag): | |
|
54 | version = tag | |
|
55 | break | |
|
56 | if modified: | |
|
57 | version += time.strftime('+%Y%m%d') | |
|
58 | remembered_version = True | |
|
59 | write_version(version) | |
|
58 | 60 | |
|
59 | 61 | def forget_version(): |
|
60 | 62 | """Remove version information.""" |
|
61 | write_version(unknown_version) | |
|
63 | if remembered_version: | |
|
64 | write_version(unknown_version) | |
|
62 | 65 |
General Comments 0
You need to be logged in to leave comments.
Login now