/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/checkout.py

  • Committer: Jelmer Vernooij
  • Date: 2007-02-01 15:50:40 UTC
  • Revision ID: jelmer@samba.org-20070201155040-3hq4mfbxs99kzazy
add framework for tests.

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 sys
 
17
import os
18
18
 
19
19
try:
20
20
    import pygtk
21
21
    pygtk.require("2.0")
22
22
except:
23
23
    pass
24
 
try:
25
 
    import gtk
26
 
    import gtk.glade
27
 
except:
28
 
    sys.exit(1)
29
 
 
 
24
 
 
25
import gtk
 
26
import gtk.glade
 
27
 
 
28
from bzrlib.branch import Branch
 
29
import bzrlib.bzrdir as bzrdir
30
30
import bzrlib.errors as errors
 
31
import bzrlib.osutils
 
32
 
 
33
from dialog import error_dialog
 
34
from guifiles import GLADEFILENAME
 
35
 
31
36
 
32
37
class OliveCheckout:
33
38
    """ Display checkout dialog and perform the needed operations. """
34
 
    def __init__(self, gladefile, comm, dialog):
 
39
    def __init__(self, path=None):
35
40
        """ Initialize the Checkout dialog. """
36
 
        self.gladefile = gladefile
37
 
        self.glade = gtk.glade.XML(self.gladefile, 'window_checkout', 'olive-gtk')
38
 
        
39
 
        # Communication object
40
 
        self.comm = comm
41
 
        # Dialog object
42
 
        self.dialog = dialog
 
41
        self.glade = gtk.glade.XML(GLADEFILENAME, 'window_checkout', 'olive-gtk')
43
42
        
44
43
        self.window = self.glade.get_widget('window_checkout')
45
44
        
52
51
        
53
52
        # Save FileChooser state
54
53
        self.filechooser = self.glade.get_widget('filechooserbutton_checkout')
55
 
        self.filechooser.set_filename(self.comm.get_path())
 
54
        if path is not None:
 
55
            self.filechooser.set_filename(path)
56
56
 
57
57
    def display(self):
58
58
        """ Display the Checkout dialog. """
62
62
        entry_location = self.glade.get_widget('entry_checkout_location')
63
63
        location = entry_location.get_text()
64
64
        if location is '':
65
 
            self.dialog.error_dialog(_('Missing branch location'),
66
 
                                     _('You must specify a branch location.'))
 
65
            error_dialog(_('Missing branch location'),
 
66
                         _('You must specify a branch location.'))
67
67
            return
68
68
        
69
69
        destination = self.filechooser.get_filename()
70
70
        
71
71
        spinbutton_revno = self.glade.get_widget('spinbutton_checkout_revno')
72
72
        revno = spinbutton_revno.get_value_as_int()
73
 
        rev_id = source.get_rev_id(revno)
74
73
        
75
74
        checkbutton_lightweight = self.glade.get_widget('checkbutton_checkout_lightweight')
76
75
        lightweight = checkbutton_lightweight.get_active()
77
76
        
78
 
        self.comm.set_busy(self.window)
79
77
        try:
80
78
            source = Branch.open(location)
 
79
            rev_id = source.get_rev_id(revno)
81
80
            
82
81
            # if the source and destination are the same, 
83
82
            # and there is no working tree,
86
85
                bzrlib.osutils.abspath(location)):
87
86
                try:
88
87
                    source.bzrdir.open_workingtree()
89
 
                except NoWorkingTree:
 
88
                except errors.NoWorkingTree:
90
89
                    source.bzrdir.create_workingtree()
91
90
                    return
92
91
 
95
94
            os.mkdir(destination)
96
95
 
97
96
            old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
98
 
            bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
97
            bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
99
98
 
100
99
            try:
101
100
                if lightweight:
114
113
            finally:
115
114
                bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
116
115
        except errors.NotBranchError, errmsg:
117
 
            self.dialog.error_dialog(_('Location is not a branch'),
118
 
                                     _('The specified location has to be a branch.'))
119
 
            self.comm.set_busy(self.window, False)
 
116
            error_dialog(_('Location is not a branch'),
 
117
                         _('The specified location has to be a branch.'))
120
118
            return
121
119
        except errors.TargetAlreadyExists, errmsg:
122
 
            self.dialog.error_dialog(_('Target already exists'),
123
 
                                     _('Target directory (%s)\nalready exists. Please select another target.') % errmsg)
124
 
            self.comm.set_busy(self.window, False)
 
120
            error_dialog(_('Target already exists'),
 
121
                         _('Target directory (%s)\nalready exists. Please select another target.') % errmsg)
125
122
            return
126
123
        except errors.NonExistingParent, errmsg:
127
 
            self.dialog.error_dialog(_('Non existing parent directory'),
128
 
                                     _("The parent directory (%s)\ndoesn't exist.") % errmsg)
129
 
            self.comm.set_busy(self.window, False)
 
124
            error_dialog(_('Non existing parent directory'),
 
125
                         _("The parent directory (%s)\ndoesn't exist.") % errmsg)
130
126
            return
131
 
        except:
132
 
            raise
133
127
        
134
128
        self.close()
135
129
        self.comm.refresh_right()