Ran update-copyright.py.
[be.git] / libbe / version.py
1 #!/usr/bin/env python
2 # Copyright (C) 2009-2012 Chris Ball <cjb@laptop.org>
3 #                         Gianluca Montecchi <gian@grys.it>
4 #                         W. Trevor King <wking@tremily.us>
5 #
6 # This file is part of Bugs Everywhere.
7 #
8 # Bugs Everywhere is free software: you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by the Free
10 # Software Foundation, either version 2 of the License, or (at your option) any
11 # later version.
12 #
13 # Bugs Everywhere is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
16 # more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Bugs Everywhere.  If not, see <http://www.gnu.org/licenses/>.
20
21 """
22 Store version info for this BE installation.  By default, use the
23 bzr-generated information in _version.py, but allow manual overriding
24 by setting _VERSION.  This allows support of both the "I don't want to
25 be bothered setting version strings" and the "I want complete control
26 over the version strings" workflows.
27 """
28
29 import copy
30
31 import libbe.storage
32 try:
33     from ._version import version_info    
34 except ImportError, e:
35     import logging
36     logging.warn('unable to import libbe._version: %s' % e)
37     version_info = {
38         'revision': 'unknown',
39         'date': 'unknown',
40         'committer': 'unknown',
41         }
42
43 # Manually set a version string (optional, defaults to bzr revision id)
44 _VERSION = '1.0.0'
45
46 def version(verbose=False):
47     """
48     Returns the version string for this BE installation.  If
49     verbose==True, the string will include extra lines with more
50     detail (e.g. last committer's name, etc.).
51     """
52     if "_VERSION" in globals():
53         string = _VERSION
54     else:
55         string = version_info['revision']
56     if verbose == True:
57         info = copy.copy(version_info)
58         info['storage'] = libbe.storage.STORAGE_VERSION
59         string += ("\n"
60                    "revision: %(revision)s\n"
61                    "date: %(date)s\n"
62                    "committer: %(committer)s\n"
63                    "storage version: %(storage)s"
64                    % info)
65     return string
66
67 if __name__ == "__main__":
68     print version(verbose=True)