~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-05-29 15:57:16 UTC
  • mfrom: (3427.5.9 dep_warnings)
  • Revision ID: pqm@pqm.ubuntu.com-20080529155716-0w3kic8lioa63231
(jam) Enable Deprecation Warnings when running -Werror and when
        running selftest

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# (C) 2005 Canonical Development Ltd
2
 
 
 
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""bzr library"""
18
18
 
19
 
 
20
 
# please keep these sorted (in C locale order) to aid merging
21
 
DEFAULT_IGNORE = [
22
 
                  '#*#',
23
 
                  '*$',
24
 
                  '*,v',
25
 
                  '*.BAK',
26
 
                  '*.a',
27
 
                  '*.bak',
28
 
                  '*.elc',
29
 
                  '*.exe',
30
 
                  '*.la',
31
 
                  '*.lo',
32
 
                  '*.o',
33
 
                  '*.o',
34
 
                  '*.obj',
35
 
                  '*.orig',
36
 
                  '*.py[oc]',
37
 
                  '*.so',
38
 
                  '*.tmp',
39
 
                  '.*.tmp',
40
 
                  '*~',
41
 
                  '.#*',
42
 
                  '.*.sw[nop]',
43
 
                  '.sw[nop]',    # vim editing nameless file
44
 
                  '.DS_Store',
45
 
                  '.arch-ids',
46
 
                  '.arch-inventory',
47
 
                  '.bzr.log',
48
 
                  '.del-*',
49
 
                  '.hg',
50
 
                  '.git',
51
 
                  '.jamdeps'
52
 
                  '.libs',
53
 
                  '.make.state',
54
 
                  '.sconsign*',
55
 
                  '.svn',
56
 
                  '.tmp*',
57
 
                  'BitKeeper',
58
 
                  'CVS',
59
 
                  'CVS.adm',
60
 
                  'RCS',
61
 
                  'SCCS',
62
 
                  'TAGS',
63
 
                  '_darcs',
64
 
                  'aclocal.m4',
65
 
                  'autom4te*',
66
 
                  'config.h',
67
 
                  'config.h.in',
68
 
                  'config.log',
69
 
                  'config.status',
70
 
                  'config.sub',
71
 
                  'stamp-h',
72
 
                  'stamp-h.in',
73
 
                  'stamp-h1',
74
 
                  '{arch}',
75
 
                  ]
 
19
import time
 
20
 
 
21
# Keep track of when bzrlib was first imported, so that we can give rough
 
22
# timestamps relative to program start in the log file kept by bzrlib.trace.
 
23
_start_time = time.time()
 
24
 
 
25
from bzrlib.osutils import get_user_encoding
 
26
 
76
27
 
77
28
IGNORE_FILENAME = ".bzrignore"
78
29
 
79
 
import os
80
 
import sys
81
 
if sys.platform == 'darwin':
82
 
    # work around egregious python 2.4 bug
83
 
    sys.platform = 'posix'
84
 
    import locale
85
 
    sys.platform = 'darwin'
86
 
else:
87
 
    import locale
88
 
user_encoding = locale.getpreferredencoding() or 'ascii'
89
 
del locale
90
 
 
91
 
__copyright__ = "Copyright 2005,06 Canonical Development Ltd."
92
 
__version__ = version_string = '0.8rc1'
93
 
# same format as sys.version_info
94
 
version_info = (0, 8, 0, 'rc', 1)
95
 
 
96
 
 
97
 
from bzrlib.symbol_versioning import deprecated_function, zero_seven
98
 
 
99
 
@deprecated_function(zero_seven)
100
 
def get_bzr_revision():
101
 
    """If bzr is run from a branch, return (revno,revid) or None."""
102
 
    import bzrlib.errors
103
 
    from bzrlib.branch import Branch
104
 
    
105
 
    try:
106
 
        branch = Branch.open(os.path.dirname(__path__[0]))
107
 
        rh = branch.revision_history()
108
 
        if rh:
109
 
            return len(rh), rh[-1]
110
 
        else:
111
 
            return None
112
 
    except bzrlib.errors.BzrError:
113
 
        return None
114
 
    
 
30
 
 
31
# XXX: Compatibility. This should probably be deprecated
 
32
user_encoding = get_user_encoding()
 
33
 
 
34
 
 
35
__copyright__ = "Copyright 2005, 2006, 2007, 2008 Canonical Ltd."
 
36
 
 
37
# same format as sys.version_info: "A tuple containing the five components of
 
38
# the version number: major, minor, micro, releaselevel, and serial. All
 
39
# values except releaselevel are integers; the release level is 'alpha',
 
40
# 'beta', 'candidate', or 'final'. The version_info value corresponding to the
 
41
# Python version 2.0 is (2, 0, 0, 'final', 0)."  Additionally we use a
 
42
# releaselevel of 'dev' for unreleased under-development code.
 
43
 
 
44
version_info = (1, 6, 0, 'dev', 0)
 
45
 
 
46
 
 
47
# API compatibility version: bzrlib is currently API compatible with 0.18.
 
48
api_minimum_version = (0, 18, 0)
 
49
 
 
50
def _format_version_tuple(version_info):
 
51
    """Turn a version number 3-tuple or 5-tuple into a short string.
 
52
 
 
53
    This format matches <http://docs.python.org/dist/meta-data.html>
 
54
    and the typical presentation used in Python output.
 
55
 
 
56
    This also checks that the version is reasonable: the sub-release must be
 
57
    zero for final releases, and non-zero for alpha, beta and preview.
 
58
 
 
59
    >>> print _format_version_tuple((1, 0, 0, 'final', 0))
 
60
    1.0
 
61
    >>> print _format_version_tuple((1, 2, 0, 'dev', 0))
 
62
    1.2dev
 
63
    >>> print _format_version_tuple((1, 1, 1, 'candidate', 2))
 
64
    1.1.1rc2
 
65
    >>> print _format_version_tuple((1, 4, 0))
 
66
    1.4
 
67
    """
 
68
    if version_info[2] == 0:
 
69
        main_version = '%d.%d' % version_info[:2]
 
70
    else:
 
71
        main_version = '%d.%d.%d' % version_info[:3]
 
72
    if len(version_info) <= 3:
 
73
        return main_version
 
74
 
 
75
    __release_type = version_info[3]
 
76
    __sub = version_info[4]
 
77
 
 
78
    # check they're consistent
 
79
    if __release_type == 'final' and __sub == 0:
 
80
        __sub_string = ''
 
81
    elif __release_type == 'dev' and __sub == 0:
 
82
        __sub_string = 'dev'
 
83
    elif __release_type in ('alpha', 'beta') and __sub != 0:
 
84
        __sub_string = __release_type[0] + str(__sub)
 
85
    elif __release_type == 'candidate' and __sub != 0:
 
86
        __sub_string = 'rc' + str(__sub)
 
87
    else:
 
88
        raise AssertionError("version_info %r not valid" % version_info)
 
89
 
 
90
    version_string = '%d.%d.%d.%s.%d' % version_info
 
91
    return main_version + __sub_string
 
92
 
 
93
__version__ = _format_version_tuple(version_info)
 
94
version_string = __version__
 
95
 
 
96
 
 
97
# allow bzrlib plugins to be imported.
 
98
import bzrlib.plugin
 
99
bzrlib.plugin.set_plugins_path()
 
100
 
 
101
 
115
102
def test_suite():
116
103
    import tests
117
104
    return tests.test_suite()