/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to olive/handler.py

  • Committer: Jelmer Vernooij
  • Date: 2006-09-27 17:56:26 UTC
  • mto: (0.12.2 olive)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060927175626-4462e9dc20d422b1
Bunch of random cleanups

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
import os
17
18
import sys
18
19
 
19
20
try:
27
28
except:
28
29
    sys.exit(1)
29
30
 
30
 
from olive.backend.info import is_branch
31
 
import olive.backend.errors as errors
 
31
import bzrlib.errors as errors
 
32
from bzrlib.branch import Branch
 
33
from bzrlib.workingtree import WorkingTree
32
34
 
33
 
from dialog import OliveDialog
 
35
from dialog import about, error_dialog, info_dialog
34
36
from menu import OliveMenu
35
37
from launch import launch
36
38
 
40
42
        self.gladefile = gladefile
41
43
        self.comm = comm
42
44
        
43
 
        self.dialog = OliveDialog(self.gladefile)
44
 
        
45
 
        self.menu = OliveMenu(self.gladefile, self.comm, self.dialog)
 
45
        self.menu = OliveMenu(self.gladefile, self.comm)
46
46
    
47
47
    def on_about_activate(self, widget):
48
 
        self.dialog.about()
 
48
        about()
49
49
        
50
50
    def on_menuitem_add_files_activate(self, widget):
51
51
        """ Add file(s)... menu handler. """
52
52
        from add import OliveAdd
53
 
        add = OliveAdd(self.gladefile, self.comm, self.dialog)
 
53
        add = OliveAdd(self.gladefile, self.comm)
54
54
        add.display()
55
55
    
56
56
    def on_menuitem_branch_get_activate(self, widget):
57
57
        """ Branch/Get... menu handler. """
58
58
        from branch import OliveBranch
59
 
        branch = OliveBranch(self.gladefile, self.comm, self.dialog)
 
59
        branch = OliveBranch(self.gladefile, self.comm)
60
60
        branch.display()
61
61
    
62
62
    def on_menuitem_branch_checkout_activate(self, widget):
63
63
        """ Branch/Checkout... menu handler. """
64
64
        from checkout import OliveCheckout
65
 
        checkout = OliveCheckout(self.gladefile, self.comm, self.dialog)
 
65
        checkout = OliveCheckout(self.gladefile, self.comm)
66
66
        checkout.display()
67
67
    
68
68
    def on_menuitem_branch_commit_activate(self, widget):
69
69
        """ Branch/Commit... menu handler. """
70
70
        from commit import OliveCommit
71
 
        commit = OliveCommit(self.gladefile, self.comm, self.dialog)
 
71
        wt, path = WorkingTree.open_containing(self.comm.get_path())
 
72
        commit = OliveCommit(self.gladefile, wt, path)
72
73
        commit.display()
73
74
    
74
75
    def on_menuitem_branch_missing_revisions_activate(self, widget):
75
76
        """ Branch/Missing revisions menu handler. """
76
 
        import olive.backend.update as update
77
77
        
78
78
        self.comm.set_busy(self.comm.window_main)
79
79
        
80
80
        try:
81
 
            ret = update.missing(self.comm.get_path())
82
 
        except errors.NotBranchError:
83
 
            self.dialog.error_dialog(_('Directory is not a branch'),
84
 
                                     _('You can perform this action only in a branch.'))
85
 
        except errors.ConnectionError:
86
 
            self.dialog.error_dialog(_('Connection error'),
87
 
                                     _('Cannot connect to remote location.\nPlease try again later.'))
88
 
        except errors.NoLocationKnown:
89
 
            self.dialog.error_dialog(_('Parent location is unknown'),
90
 
                                     _('Cannot determine missing revisions if no parent location is known.'))
91
 
        else:
 
81
            import bzrlib
 
82
            
 
83
            try:
 
84
                local_branch = Branch.open_containing(self.comm.get_path())[0]
 
85
            except NotBranchError:
 
86
                error_dialog(_('Directory is not a branch'),
 
87
                                         _('You can perform this action only in a branch.'))
 
88
                return
 
89
            
 
90
            other_branch = local_branch.get_parent()
 
91
            if other_branch is None:
 
92
                error_dialog(_('Parent location is unknown'),
 
93
                                         _('Cannot determine missing revisions if no parent location is known.'))
 
94
                return
 
95
            
 
96
            remote_branch = Branch.open(other_branch)
 
97
            
 
98
            if remote_branch.base == local_branch.base:
 
99
                remote_branch = local_branch
 
100
 
 
101
            ret = len(local_branch.missing_revisions(remote_branch))
 
102
 
92
103
            if ret > 0:
93
 
                self.dialog.info_dialog(_('There are missing revisions'),
 
104
                info_dialog(_('There are missing revisions'),
94
105
                                        _('%d revision(s) missing.') % ret)
95
106
            else:
96
 
                self.dialog.info_dialog(_('Local branch up to date'),
 
107
                info_dialog(_('Local branch up to date'),
97
108
                                        _('There are no missing revisions.'))
98
 
        
99
 
        self.comm.set_busy(self.comm.window_main, False)
 
109
        finally:
 
110
            self.comm.set_busy(self.comm.window_main, False)
100
111
    
101
112
    def on_menuitem_branch_pull_activate(self, widget):
102
113
        """ Branch/Pull menu handler. """
103
 
        import olive.backend.update as update
104
114
        
105
115
        self.comm.set_busy(self.comm.window_main)
106
 
        
 
116
 
107
117
        try:
108
 
            ret = update.pull(self.comm.get_path())
109
 
        except errors.NotBranchError:
110
 
            self.dialog.error_dialog(_('Directory is not a branch'),
111
 
                                     _('You can perform this action only in a branch.'))
112
 
        except errors.NoLocationKnown:
113
 
            self.dialog.error_dialog(_('Parent location is unknown'),
114
 
                                     _('Pulling is not possible until there is no parent location.'))
115
 
        else:
116
 
            self.dialog.info_dialog(_('Pull successful'),
 
118
            try:
 
119
                from bzrlib.workingtree import WorkingTree
 
120
                tree_to = WorkingTree.open_containing(self.comm.get_path())[0]
 
121
                branch_to = tree_to.branch
 
122
            except errors.NoWorkingTree:
 
123
                tree_to = None
 
124
                branch_to = Branch.open_containing(self.comm.get_path())[0]
 
125
            except errors.NotBranchError:
 
126
                 error_dialog(_('Directory is not a branch'),
 
127
                                         _('You can perform this action only in a branch.'))
 
128
 
 
129
            location = branch_to.get_parent()
 
130
            if location is None:
 
131
                error_dialog(_('Parent location is unknown'),
 
132
                                         _('Pulling is not possible until there is a parent location.'))
 
133
                return
 
134
 
 
135
            try:
 
136
                branch_from = Branch.open(location)
 
137
            except errors.NotBranchError:
 
138
                error_dialog(_('Directory is not a branch'),
 
139
                                         _('You can perform this action only in a branch.'))
 
140
 
 
141
            if branch_to.get_parent() is None:
 
142
                branch_to.set_parent(branch_from.base)
 
143
 
 
144
            old_rh = branch_to.revision_history()
 
145
            if tree_to is not None:
 
146
                tree_to.pull(branch_from)
 
147
            else:
 
148
                branch_to.pull(branch_from)
 
149
            
 
150
            info_dialog(_('Pull successful'),
117
151
                                    _('%d revision(s) pulled.') % ret)
118
 
        
119
 
        self.comm.set_busy(self.comm.window_main, False)
 
152
            
 
153
        finally:
 
154
            self.comm.set_busy(self.comm.window_main, False)
120
155
    
121
156
    def on_menuitem_branch_push_activate(self, widget):
122
157
        """ Branch/Push... menu handler. """
123
158
        from push import OlivePush
124
 
        push = OlivePush(self.gladefile, self.comm, self.dialog)
 
159
        push = OlivePush(self.gladefile, self.comm)
125
160
        push.display()
126
161
    
127
162
    def on_menuitem_branch_status_activate(self, widget):
128
163
        """ Branch/Status... menu handler. """
129
164
        from status import OliveStatus
130
 
        status = OliveStatus(self.gladefile, self.comm, self.dialog)
 
165
        wt, wtpath = WorkingTree.open_containing(self.comm.get_path())
 
166
        status = OliveStatus(self.gladefile, wt, wtpath)
131
167
        status.display()
132
168
    
133
169
    def on_menuitem_branch_initialize_activate(self, widget):
134
170
        """ Initialize current directory. """
135
 
        import olive.backend.init as init
136
 
        
137
171
        try:
138
 
            init.init(self.comm.get_path())
 
172
            location = self.comm.get_path()
 
173
            from bzrlib.builtins import get_format_type
 
174
 
 
175
            format = get_format_type('default')
 
176
 
 
177
            if not os.path.exists(location):
 
178
                os.mkdir(location)
 
179
     
 
180
            try:
 
181
                existing_bzrdir = bzrdir.BzrDir.open(location)
 
182
            except NotBranchError:
 
183
                bzrdir.BzrDir.create_branch_convenience(location, format=format)
 
184
            else:
 
185
                if existing_bzrdir.has_branch():
 
186
                    if existing_bzrdir.has_workingtree():
 
187
                        raise AlreadyBranchError(location)
 
188
                    else:
 
189
                        raise BranchExistsWithoutWorkingTree(location)
 
190
                else:
 
191
                    existing_bzrdir.create_branch()
 
192
                    existing_bzrdir.create_workingtree()
139
193
        except errors.AlreadyBranchError, errmsg:
140
 
            self.dialog.error_dialog(_('Directory is already a branch'),
 
194
            error_dialog(_('Directory is already a branch'),
141
195
                                     _('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
142
196
        except errors.BranchExistsWithoutWorkingTree, errmsg:
143
 
            self.dialog.error_dialog(_('Branch without a working tree'),
 
197
            error_dialog(_('Branch without a working tree'),
144
198
                                     _('The current directory (%s)\nis a branch without a working tree.') % errmsg)
145
 
        except:
146
 
            raise
147
199
        else:
148
 
            self.dialog.info_dialog(_('Ininialize successful'),
 
200
            info_dialog(_('Initialize successful'),
149
201
                                    _('Directory successfully initialized.'))
150
202
            self.comm.refresh_right()
151
203
        
152
204
    def on_menuitem_file_make_directory_activate(self, widget):
153
205
        """ File/Make directory... menu handler. """
154
206
        from mkdir import OliveMkdir
155
 
        mkdir = OliveMkdir(self.gladefile, self.comm, self.dialog)
 
207
        mkdir = OliveMkdir(self.gladefile, self.comm)
156
208
        mkdir.display()
157
209
    
158
210
    def on_menuitem_file_move_activate(self, widget):
159
211
        """ File/Move... menu handler. """
160
212
        from move import OliveMove
161
 
        move = OliveMove(self.gladefile, self.comm, self.dialog)
 
213
        move = OliveMove(self.gladefile, self.comm)
162
214
        move.display()
163
215
    
164
216
    def on_menuitem_file_rename_activate(self, widget):
165
217
        """ File/Rename... menu handler. """
166
218
        from rename import OliveRename
167
 
        rename = OliveRename(self.gladefile, self.comm, self.dialog)
 
219
        rename = OliveRename(self.gladefile, self.comm)
168
220
        rename.display()
169
221
 
170
222
    def on_menuitem_remove_file_activate(self, widget):
171
223
        """ Remove (unversion) selected file. """
172
224
        from remove import OliveRemove
173
 
        remove = OliveRemove(self.gladefile, self.comm, self.dialog)
 
225
        remove = OliveRemove(self.gladefile, self.comm)
174
226
        remove.display()
175
227
    
176
228
    def on_menuitem_stats_diff_activate(self, widget):
177
229
        """ Statistics/Differences... menu handler. """
178
230
        from diff import OliveDiff
179
 
        diff = OliveDiff(self.gladefile, self.comm, self.dialog)
 
231
        diff = OliveDiff(self.gladefile, self.comm)
180
232
        diff.display()
181
233
    
182
234
    def on_menuitem_stats_infos_activate(self, widget):
183
235
        """ Statistics/Informations... menu handler. """
184
236
        from info import OliveInfo
185
 
        info = OliveInfo(self.gladefile, self.comm, self.dialog)
 
237
        info = OliveInfo(self.gladefile, self.comm)
186
238
        info.display()
187
239
    
188
240
    def on_menuitem_stats_log_activate(self, widget):
189
241
        """ Statistics/Log... menu handler. """
190
242
        from log import OliveLog
191
 
        log = OliveLog(self.gladefile, self.comm, self.dialog)
 
243
        log = OliveLog(self.gladefile, self.comm)
192
244
        log.display()
193
245
    
194
246
    def on_menuitem_view_refresh_activate(self, widget):
243
295
            m_commit = self.menu.ui.get_widget('/context_right/commit')
244
296
            m_diff = self.menu.ui.get_widget('/context_right/diff')
245
297
            # check if we're in a branch
246
 
            if not is_branch(self.comm.get_path()):
 
298
            try:
 
299
                from bzrlib.branch import Branch
 
300
                Branch.open_containing(self.comm.get_path())
247
301
                m_add.set_sensitive(False)
248
302
                m_remove.set_sensitive(False)
249
303
                m_commit.set_sensitive(False)
250
304
                m_diff.set_sensitive(False)
251
 
            else:
 
305
            except errors.NotBranchError:
252
306
                m_add.set_sensitive(True)
253
307
                m_remove.set_sensitive(True)
254
308
                m_commit.set_sensitive(True)
289
343
        self.comm.pref.write()
290
344
        self.comm.window_main.destroy()
291
345
 
292
 
    def not_implemented(self, widget):
293
 
        """ Display a Not implemented error message. """
294
 
        self.dialog.error_dialog(_('We feel sorry'),
295
 
                                 _('This feature is not yet implemented.'))
296
346