/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1185.1.29 by Robert Collins
merge merge tweaks from aaron, which includes latest .dev
1
# Copyright (C) 2005 Canonical Ltd
2
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
18
19
"""UI abstraction.
20
21
This tells the library how to display things to the user.  Through this
22
layer different applications can choose the style of UI.
23
24
At the moment this layer is almost trivial: the application can just
25
choose the style of progress bar.
26
27
Set the ui_factory member to define the behaviour.  The default
28
displays no output.
29
"""
30
1594.1.1 by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar.
31
1185.1.29 by Robert Collins
merge merge tweaks from aaron, which includes latest .dev
32
import bzrlib.progress
1594.1.1 by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar.
33
from bzrlib.symbol_versioning import *
1185.1.29 by Robert Collins
merge merge tweaks from aaron, which includes latest .dev
34
35
1185.49.21 by John Arbash Meinel
Refactored bzrlib/ui.py into a module with the possibility for multiple ui forms.
36
class UIFactory(object):
37
    """UI abstraction.
38
39
    This tells the library how to display things to the user.  Through this
40
    layer different applications can choose the style of UI.
41
    """
1594.1.1 by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar.
42
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
43
    def __init__(self):
44
        super(UIFactory, self).__init__()
45
        self._progress_bar_stack = None
46
1594.1.2 by Robert Collins
Update news and deprecated the old progress bar api.
47
    @deprecated_method(zero_eight)
1185.1.29 by Robert Collins
merge merge tweaks from aaron, which includes latest .dev
48
    def progress_bar(self):
1594.1.1 by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar.
49
        """See UIFactory.nested_progress_bar()."""
50
        raise NotImplementedError(self.progress_bar)
1185.49.22 by John Arbash Meinel
Added get_password to the UIFactory, using it inside of sftp.py
51
52
    def get_password(self, prompt='', **kwargs):
53
        """Prompt the user for a password.
54
55
        :param prompt: The prompt to present the user
56
        :param kwargs: Arguments which will be expanded into the prompt.
57
                       This lets front ends display different things if
58
                       they so choose.
59
        :return: The password string, return None if the user 
60
                 canceled the request.
61
        """
1594.1.1 by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar.
62
        raise NotImplementedError(self.get_password)
1185.49.22 by John Arbash Meinel
Added get_password to the UIFactory, using it inside of sftp.py
63
        
1594.1.1 by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar.
64
    def nested_progress_bar(self):
65
        """Return a nested progress bar.
66
67
        When the bar has been finished with, it should be released bu calling
68
        bar.finished().
69
        """
70
        raise NotImplementedError(self.nested_progress_bar)
71
1558.8.1 by Aaron Bentley
Fix overall progress bar's interaction with 'note' and 'warning'
72
    def clear_term(self):
73
        """Prepare the terminal for output.
74
75
        This will, for example, clear text progress bars, and leave the
76
        cursor at the leftmost position."""
77
        raise NotImplementedError(self.clear_term)
78
1185.49.21 by John Arbash Meinel
Refactored bzrlib/ui.py into a module with the possibility for multiple ui forms.
79
80
class SilentUIFactory(UIFactory):
81
    """A UI Factory which never prints anything.
82
83
    This is the default UI, if another one is never registered.
84
    """
1594.1.1 by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar.
85
1594.1.2 by Robert Collins
Update news and deprecated the old progress bar api.
86
    @deprecated_method(zero_eight)
1185.1.29 by Robert Collins
merge merge tweaks from aaron, which includes latest .dev
87
    def progress_bar(self):
1594.1.1 by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar.
88
        """See UIFactory.nested_progress_bar()."""
1185.1.29 by Robert Collins
merge merge tweaks from aaron, which includes latest .dev
89
        return bzrlib.progress.DummyProgress()
90
1185.49.22 by John Arbash Meinel
Added get_password to the UIFactory, using it inside of sftp.py
91
    def get_password(self, prompt='', **kwargs):
92
        return None
93
1594.1.1 by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar.
94
    def nested_progress_bar(self):
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
95
        if self._progress_bar_stack is None:
96
            self._progress_bar_stack = bzrlib.progress.ProgressBarStack(
97
                klass=bzrlib.progress.DummyProgress)
98
        return self._progress_bar_stack.get_nested()
1594.1.1 by Robert Collins
Introduce new bzr progress bar api. ui_factory.nested_progress_bar.
99
1558.8.1 by Aaron Bentley
Fix overall progress bar's interaction with 'note' and 'warning'
100
    def clear_term(self):
101
        pass
102
103
104
def clear_decorator(func, *args, **kwargs):
105
    """Decorator that clears the term"""
106
    ui_factory.clear_term()
107
    func(*args, **kwargs)
108
1185.49.22 by John Arbash Meinel
Added get_password to the UIFactory, using it inside of sftp.py
109
1185.1.29 by Robert Collins
merge merge tweaks from aaron, which includes latest .dev
110
ui_factory = SilentUIFactory()
1534.5.9 by Robert Collins
Advise users running upgrade on a checkout to also run it on the branch.
111
"""IMPORTANT: never import this symbol directly. ONLY ever access it as 
112
ui.ui_factory."""