~doxxx/qbzr/qconflicts-cmdline-splitting

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# -*- coding: utf-8 -*-
#
# QBzr - Qt frontend to Bazaar commands
# Copyright (C) 2008 Canonical
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# This implements the 'qupdate-hybrid' command - a hybrid update command
# that examines the tree being updated and displays one of 2 dialogs
# depending on if the tree is bound (ie, a checkout) or not.

from bzrlib.plugins.qbzr.lib.subprocess import SubProcessDialog
from bzrlib.plugins.qbzr.lib.ui_update_branch import Ui_UpdateBranchForm
from bzrlib.plugins.qbzr.lib.ui_update_checkout import Ui_UpdateCheckoutForm
from bzrlib.plugins.qbzr.lib.util import (
    iter_saved_pull_locations,
    save_pull_location,
    fill_combo_with,
    fill_pull_combo,
    hookup_directory_picker,
    DIRECTORYPICKER_SOURCE,
    url_for_display,
    )


class UpdateBranchWindow(SubProcessDialog):

    NAME = "update_branch"

    def __init__(self, branch, ui_mode=True, parent=None):
        self.branch = branch
        super(UpdateBranchWindow, self).__init__(
                                  name = self.NAME,
                                  ui_mode = ui_mode,
                                  parent = parent)

        self.ui = Ui_UpdateBranchForm()
        self.ui.setupUi(self)
        # and add the subprocess widgets.
        for w in self.make_default_layout_widgets():
            self.layout().addWidget(w)
        # nuke existing items in the combo.
        while self.ui.location.count():
            self.ui.location.removeItem(0)

        fill_pull_combo(self.ui.location, self.branch)

        # One directory picker for the pull location.
        hookup_directory_picker(self,
                                self.ui.location_picker,
                                self.ui.location,
                                DIRECTORYPICKER_SOURCE)

        self.ui.but_pull.setChecked(not not self.branch.get_parent())

    def do_start(self):
        if self.ui.but_pull.isChecked():
            # its a 'pull'
            args = ['--directory', self.branch.base]
            if self.ui.but_pull_overwrite.isChecked():
                args.append('--overwrite')
            if self.ui.but_pull_remember.isChecked():
                args.append('--remember')
            location = unicode(self.ui.location.currentText())
            if not location:
                return

            self.process_widget.do_start(None, 'pull', location, *args)
            save_pull_location(self.branch, location)
        else:
            # its an 'update'.
            self.process_widget.do_start(None, 'update', self.branch.base)


class UpdateCheckoutWindow(SubProcessDialog):

    NAME = "update_checkout"

    def __init__(self, branch, ui_mode=True, parent=None):
        self.branch = branch
        super(UpdateCheckoutWindow, self).__init__(
                                  name = self.NAME,
                                  ui_mode = ui_mode,
                                  parent = parent)

        self.ui = Ui_UpdateCheckoutForm()
        self.ui.setupUi(self)
        # and add the subprocess widgets.
        for w in self.make_default_layout_widgets():
            self.layout().addWidget(w)
        # nuke existing items in the combo.
        while self.ui.location.count():
            self.ui.location.removeItem(0)
        # We don't look at 'related' branches etc when doing a 'pull' from
        # a checkout - the default is empty, but saved locations are used.
        fill_combo_with(self.ui.location,
                        u'',
                        iter_saved_pull_locations())
        # and the directory picker for the pull location.
        hookup_directory_picker(self,
                                self.ui.location_picker,
                                self.ui.location,
                                DIRECTORYPICKER_SOURCE)

        # Our 'label' object is ready to have the bound location specified.
        loc = url_for_display(self.branch.get_bound_location())
        self.ui.label.setText(unicode(self.ui.label.text()) % loc)
        self.ui.but_pull.setChecked(False)

    def do_start(self):
        if self.ui.but_pull.isChecked():
            args = ['--directory', self.branch.base]
            if self.ui.but_pull_overwrite.isChecked():
                args.append('--overwrite')
            #if self.ui.but_pull_remember.isChecked():
            #    args.append('--remember')
            location = unicode(self.ui.location.currentText())
            if not location:
                return
            self.process_widget.do_start(None, 'pull', location, *args)
        else:
            # its an update.
            self.process_widget.do_start(None, 'update', self.branch.base)