Merged Eric Kow's HTML escaping patch
[be.git] / libbe / version.py
1 #!/usr/bin/env python
2 # Copyright (C) 2009-2010 W. Trevor King <wking@drexel.edu>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 """
19 Store version info for this BE installation.  By default, use the
20 bzr-generated information in _version.py, but allow manual overriding
21 by setting _VERSION.  This allows support of both the "I don't want to
22 be bothered setting version strings" and the "I want complete control
23 over the version strings" workflows.
24 """
25
26 import copy
27
28 import libbe._version as _version
29 import libbe.storage
30
31 # Manually set a version string (optional, defaults to bzr revision id)
32 #_VERSION = "1.2.3"
33
34 def version(verbose=False):
35     """
36     Returns the version string for this BE installation.  If
37     verbose==True, the string will include extra lines with more
38     detail (e.g. bzr branch nickname, etc.).
39     """
40     if "_VERSION" in globals():
41         string = _VERSION
42     else:
43         string = _version.version_info["revision_id"]
44     if verbose == True:
45         info = copy.copy(_version.version_info)
46         info['storage'] = libbe.storage.STORAGE_VERSION
47         string += ("\n"
48                    "revision: %(revno)d\n"
49                    "nick: %(branch_nick)s\n"
50                    "revision id: %(revision_id)s\n"
51                    "storage version: %(storage)s"
52                    % info)
53     return string
54
55 if __name__ == "__main__":
56     print version(verbose=True)