Mercurial > hg
comparison mercurial/version.py @ 423:25afb21d97ba
Support for 'hg --version'. setup.py stores version from hg repository.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Support for 'hg --version'. setup.py stores version from hg repository.
manifest hash: c69058298ea12035f2cf356f987ba2fb5ff4bbae
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFCtD6ZW7P1GVgWeRoRAnGHAKCLscthht2UlBEMDmxL9cku4PlcswCffOVo
wTOhYkW4Ie5+8bdmL8EqsvY=
=uGpn
-----END PGP SIGNATURE-----
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Sat, 18 Jun 2005 16:32:41 +0100 |
parents | |
children | 719663b7f235 |
comparison
equal
deleted
inserted
replaced
396:8f8bb77d560e | 423:25afb21d97ba |
---|---|
1 # Copyright (C) 2005 by Intevation GmbH | |
2 # Author(s): | |
3 # Thomas Arendsen Hein <thomas@intevation.de> | |
4 # | |
5 # This program is free software under the GNU GPL (>=v2) | |
6 # Read the file COPYING coming with the software for details. | |
7 | |
8 """ | |
9 Mercurial version | |
10 """ | |
11 | |
12 import os | |
13 import os.path | |
14 import re | |
15 import time | |
16 | |
17 unknown_version = 'unknown' | |
18 | |
19 def get_version(): | |
20 """Return version information if available.""" | |
21 try: | |
22 from mercurial.__version__ import version | |
23 except ImportError: | |
24 version = unknown_version | |
25 return version | |
26 | |
27 def write_version(version): | |
28 """Overwrite version file.""" | |
29 filename = os.path.join(os.path.dirname(__file__), '__version__.py') | |
30 f = open(filename, 'w') | |
31 f.write("# This file is auto-generated.\n") | |
32 f.write("version = %r\n" % version) | |
33 f.close() | |
34 | |
35 def remember_version(): | |
36 """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 = version[:-1] | |
44 modified = True | |
45 else: | |
46 modified = False | |
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) | |
58 | |
59 def forget_version(): | |
60 """Remove version information.""" | |
61 write_version(unknown_version) | |
62 |