/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:
 
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
 
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
import os
 
18
 
 
19
try:
 
20
    import pygtk
 
21
    pygtk.require("2.0")
 
22
except:
 
23
    pass
 
24
 
 
25
import gtk
 
26
import gtk.glade
 
27
 
 
28
from bzrlib.branch import Branch
 
29
import bzrlib.bzrdir as bzrdir
 
30
import bzrlib.errors as errors
 
31
import bzrlib.osutils
 
32
 
 
33
from dialog import error_dialog
 
34
from guifiles import GLADEFILENAME
 
35
 
 
36
 
 
37
class OliveCheckout:
 
38
    """ Display checkout dialog and perform the needed operations. """
 
39
    def __init__(self, path=None):
 
40
        """ Initialize the Checkout dialog. """
 
41
        self.glade = gtk.glade.XML(GLADEFILENAME, 'window_checkout', 'olive-gtk')
 
42
        
 
43
        self.window = self.glade.get_widget('window_checkout')
 
44
        
 
45
        # Dictionary for signal_autoconnect
 
46
        dic = { "on_button_checkout_checkout_clicked": self.checkout,
 
47
                "on_button_checkout_cancel_clicked": self.close }
 
48
        
 
49
        # Connect the signals to the handlers
 
50
        self.glade.signal_autoconnect(dic)
 
51
        
 
52
        # Save FileChooser state
 
53
        self.filechooser = self.glade.get_widget('filechooserbutton_checkout')
 
54
        if path is not None:
 
55
            self.filechooser.set_filename(path)
 
56
 
 
57
    def display(self):
 
58
        """ Display the Checkout dialog. """
 
59
        self.window.show_all()
 
60
    
 
61
    def checkout(self, widget):
 
62
        entry_location = self.glade.get_widget('entry_checkout_location')
 
63
        location = entry_location.get_text()
 
64
        if location is '':
 
65
            error_dialog(_('Missing branch location'),
 
66
                         _('You must specify a branch location.'))
 
67
            return
 
68
        
 
69
        destination = self.filechooser.get_filename()
 
70
        
 
71
        spinbutton_revno = self.glade.get_widget('spinbutton_checkout_revno')
 
72
        revno = spinbutton_revno.get_value_as_int()
 
73
        
 
74
        checkbutton_lightweight = self.glade.get_widget('checkbutton_checkout_lightweight')
 
75
        lightweight = checkbutton_lightweight.get_active()
 
76
        
 
77
        try:
 
78
            source = Branch.open(location)
 
79
            rev_id = source.get_rev_id(revno)
 
80
            
 
81
            # if the source and destination are the same, 
 
82
            # and there is no working tree,
 
83
            # then reconstitute a branch
 
84
            if (bzrlib.osutils.abspath(destination) ==
 
85
                bzrlib.osutils.abspath(location)):
 
86
                try:
 
87
                    source.bzrdir.open_workingtree()
 
88
                except errors.NoWorkingTree:
 
89
                    source.bzrdir.create_workingtree()
 
90
                    return
 
91
 
 
92
            destination = destination + '/' + os.path.basename(location.rstrip("/\\"))
 
93
            
 
94
            os.mkdir(destination)
 
95
 
 
96
            old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
 
97
            bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
98
 
 
99
            try:
 
100
                if lightweight:
 
101
                    checkout = bzrdir.BzrDirMetaFormat1().initialize(destination)
 
102
                    bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
 
103
                else:
 
104
                    checkout_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
 
105
                        destination, force_new_tree=False)
 
106
                    checkout = checkout_branch.bzrdir
 
107
                    checkout_branch.bind(source)
 
108
                    if rev_id is not None:
 
109
                        rh = checkout_branch.revno_history()
 
110
                        checkout_branch.set_revno_history(rh[:rh.index(rev_id) + 1])
 
111
 
 
112
                checkout.create_workingtree(rev_id)
 
113
            finally:
 
114
                bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
 
115
        except errors.NotBranchError, errmsg:
 
116
            error_dialog(_('Location is not a branch'),
 
117
                         _('The specified location has to be a branch.'))
 
118
            return
 
119
        except errors.TargetAlreadyExists, errmsg:
 
120
            error_dialog(_('Target already exists'),
 
121
                         _('Target directory (%s)\nalready exists. Please select another target.') % errmsg)
 
122
            return
 
123
        except errors.NonExistingParent, errmsg:
 
124
            error_dialog(_('Non existing parent directory'),
 
125
                         _("The parent directory (%s)\ndoesn't exist.") % errmsg)
 
126
            return
 
127
        
 
128
        self.close()
 
129
        self.comm.refresh_right()
 
130
 
 
131
    def close(self, widget=None):
 
132
        self.window.destroy()