Incorrect accquiring bugdir command line argument
[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 """Store version info for this BE installation.
22
23 By default, use the Git-generated information in
24 :py:mod:`~libbe._version`, but allow manual overriding by setting
25 :py:data:`libbe.version._VERSION`.  This allows support of both the "I
26 don't want to be bothered setting version strings" and the "I want
27 complete control over the version strings" workflows.
28 """
29
30 import copy
31
32 import libbe.storage
33 try:
34     from ._version import version_info    
35 except ImportError as e:
36     import logging
37     logging.warn('unable to import libbe._version: {0}'.format(e))
38     version_info = {
39         'revision': 'unknown',
40         'date': 'unknown',
41         'committer': 'unknown',
42         }
43
44 # Manually set a version string (optional, defaults to bzr revision id)
45 #_VERSION = '1.2.3'
46
47 def version(verbose=False):
48     """
49     Returns the version string for this BE installation.  If
50     verbose==True, the string will include extra lines with more
51     detail (e.g. last committer's name, etc.).
52     """
53     if "_VERSION" in globals():
54         string = _VERSION
55     else:
56         string = version_info['revision'][:8]
57     if verbose == True:
58         info = copy.copy(version_info)
59         info['storage'] = libbe.storage.STORAGE_VERSION
60         string += (
61             '\n'
62             'revision: {revision}\n'
63             'date: {date}\n'
64             'committer: {committer}\n'
65             'storage version: {storage}'
66             ).format(**info)
67     return string
68
69
70 if __name__ == '__main__':
71     print(version(verbose=True))