21
21
pygtk.require("2.0")
28
import bzrlib.errors as errors
29
from __init__ import gladefile
30
import olive.backend.init as init
31
import olive.backend.errors as errors
32
34
""" Display branch dialog and perform the needed operations. """
33
def __init__(self, path=None):
35
def __init__(self, gladefile, comm, dialog):
34
36
""" Initialize the Branch dialog. """
35
self.glade = gtk.glade.XML(gladefile, 'window_branch', 'olive-gtk')
37
self.gladefile = gladefile
38
self.glade = gtk.glade.XML(self.gladefile, 'window_branch')
40
# Communication object
37
45
self.window = self.glade.get_widget('window_branch')
39
47
# Dictionary for signal_autoconnect
56
63
entry_location = self.glade.get_widget('entry_branch_location')
57
64
location = entry_location.get_text()
59
error_dialog(_('Missing branch location'),
60
_('You must specify a branch location.'))
66
self.dialog.error_dialog('Missing branch location',
67
'You must specify a branch location.')
63
70
destination = self.filechooser.get_filename()
65
72
spinbutton_revno = self.glade.get_widget('spinbutton_branch_revno')
66
73
revno = spinbutton_revno.get_value_as_int()
67
revision_id = br_from.get_rev_id(revno)
77
self.comm.set_busy(self.window)
70
from bzrlib.transport import get_transport
72
br_from = Branch.open(location)
76
destination = destination + '/' + os.path.basename(location.rstrip("/\\"))
77
to_transport = get_transport(destination)
78
to_transport.mkdir('.')
81
dir = br_from.bzrdir.sprout(to_transport.base, revision_id)
82
branch = dir.open_branch()
83
except NoSuchRevision:
84
to_transport.delete_tree('.')
91
info_dialog(_('Branching successful'),
92
_('%d revision(s) branched.') % revs)
79
revs = init.branch(location, destination, revno)
93
80
except errors.NonExistingSource, errmsg:
94
error_dialog(_('Non existing source'),
95
_("The location (%s)\ndoesn't exist.") % errmsg)
81
self.dialog.error_dialog('Non existing source',
82
"The location (%s)\ndoesn't exist." % errmsg)
83
self.comm.set_busy(self.window, False)
97
85
except errors.TargetAlreadyExists, errmsg:
98
error_dialog(_('Target already exists'),
99
_('Target directory (%s)\nalready exists. Please select another target.') % errmsg)
86
self.dialog.error_dialog('Target already exists',
87
'Target directory (%s)\nalready exists. Please select another target.' % errmsg)
88
self.comm.set_busy(self.window, False)
101
90
except errors.NonExistingParent, errmsg:
102
error_dialog(_('Non existing parent directory'),
103
_("The parent directory (%s)\ndoesn't exist.") % errmsg)
91
self.dialog.error_dialog("Non existing parent directory",
92
"The parent directory (%s)\ndoesn't exist." % errmsg)
93
self.comm.set_busy(self.window, False)
105
95
except errors.NonExistingRevision:
106
error_dialog(_('Non existing revision'),
107
_("The revision you specified doesn't exist."))
96
self.dialog.error_dialog('Non existing revision',
97
"The revision you specified doesn't exist.")
98
self.comm.set_busy(self.window, False)
109
100
except errors.NotBranchError, errmsg:
110
error_dialog(_('Location is not a branch'),
111
_('The specified location has to be a branch.'))
101
self.dialog.error_dialog('Location is not a branch'
102
'The specified location has to be a branch')
103
self.comm.set_busy(self.window, False)
109
self.dialog.info_dialog('Branching successful',
110
'%d revision(s) branched.' % revs)
111
self.comm.refresh_right()
115
113
def close(self, widget=None):
116
114
self.window.destroy()