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