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