Added libbe.version, wrapping the auto-generated libbe._version.
[be.git] / libbe / version.py
1 #!/usr/bin/env python
2 # Copyright (C) 2009 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 libbe._version as _version
27
28 # Manually set a version string (optional, defaults to bzr revision id)
29 #_VERSION = "1.2.3"
30
31 def version(verbose=False):
32     """
33     Returns the version string for this BE installation.  If
34     verbose==True, the string will include extra lines with more
35     detail (e.g. bzr branch nickname, etc.).
36     """
37     if "_VERSION" in globals():
38         string = _VERSION
39     else:
40         string = _version.version_info["revision_id"]
41     if verbose == True:
42         string += ("\n"
43                    "revision: %(revno)d\n"
44                    "nick: %(branch_nick)s\n"
45                    "revision id: %(revision_id)s"
46                    % _version.version_info)
47     return string
48
49 if __name__ == "__main__":
50     print version(verbose=True)