Debian Codegraph @

lib/getupdates.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # QBrz - Qt frontend to Breezy commands
4 # Copyright (C) 2008 Canonical
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 # This implements the 'qupdate-hybrid' command - a hybrid update command
21 # that examines the tree being updated and displays one of 2 dialogs
22 # depending on if the tree is bound (ie, a checkout) or not.
23
24 from breezy.plugins.qbrz.lib.i18n import gettext
25 from breezy.plugins.qbrz.lib.subprocess import SubProcessDialog
26 from breezy.plugins.qbrz.lib.ui_update_branch import Ui_UpdateBranchForm
27 from breezy.plugins.qbrz.lib.ui_update_checkout import Ui_UpdateCheckoutForm
28 from breezy.plugins.qbrz.lib.util import (
29 iter_saved_pull_locations,
30 save_pull_location,
31 fill_combo_with,
32 fill_pull_combo,
33 hookup_directory_picker,
34 DIRECTORYPICKER_SOURCE,
35 url_for_display,
36 )
37
38
39 class UpdateBranchWindow(SubProcessDialog):
40
41 NAME = "update_branch"
42
43 def __init__(self, branch, ui_mode=True, parent=None):
44 self.branch = branch
45 super(UpdateBranchWindow, self).__init__(
46 name = self.NAME,
47 ui_mode = ui_mode,
48 parent = parent)
49
50 self.ui = Ui_UpdateBranchForm()
51 self.ui.setupUi(self)
52 # and add the subprocess widgets.
53 for w in self.make_default_layout_widgets():
54 self.layout().addWidget(w)
55 # nuke existing items in the combo.
56 while self.ui.location.count():
57 self.ui.location.removeItem(0)
58
59 fill_pull_combo(self.ui.location, self.branch)
60
61 # One directory picker for the pull location.
62 hookup_directory_picker(self,
63 self.ui.location_picker,
64 self.ui.location,
65 DIRECTORYPICKER_SOURCE)
66
67 self.ui.but_pull.setChecked(not not self.branch.get_parent())
68
69 def _is_pull_selected(self):
70 return self.ui.but_pull.isChecked()
71
72 def _get_pull_location(self):
73 return str(self.ui.location.currentText())
74
75 def validate(self):
76 if self._is_pull_selected() and not self._get_pull_location():
77 self.operation_blocked(gettext("You should specify source branch location"))
78 return False
79 return True
80
81 def do_start(self):
82 if self._is_pull_selected():
83 # its a 'pull'
84 args = ['--directory', self.branch.base]
85 if self.ui.but_pull_overwrite.isChecked():
86 args.append('--overwrite')
87 if self.ui.but_pull_remember.isChecked():
88 args.append('--remember')
89 location = self._get_pull_location()
90 self.process_widget.do_start(None, 'pull', location, *args)
91 save_pull_location(self.branch, location)
92 else:
93 # its an 'update'.
94 self.process_widget.do_start(None, 'update', self.branch.base)
95
96
97 class UpdateCheckoutWindow(SubProcessDialog):
98
99 NAME = "update_checkout"
100
101 def __init__(self, branch, ui_mode=True, parent=None):
102 self.branch = branch
103 super(UpdateCheckoutWindow, self).__init__(
104 name = self.NAME,
105 ui_mode = ui_mode,
106 parent = parent)
107
108 self.ui = Ui_UpdateCheckoutForm()
109 self.ui.setupUi(self)
110 # and add the subprocess widgets.
111 for w in self.make_default_layout_widgets():
112 self.layout().addWidget(w)
113 # nuke existing items in the combo.
114 while self.ui.location.count():
115 self.ui.location.removeItem(0)
116 # We don't look at 'related' branches etc when doing a 'pull' from
117 # a checkout - the default is empty, but saved locations are used.
118 fill_combo_with(self.ui.location,
119 '',
120 iter_saved_pull_locations())
121 # and the directory picker for the pull location.
122 hookup_directory_picker(self,
123 self.ui.location_picker,
124 self.ui.location,
125 DIRECTORYPICKER_SOURCE)
126
127 # Our 'label' object is ready to have the bound location specified.
128 loc = url_for_display(self.branch.get_bound_location())
129 self.ui.label.setText(str(self.ui.label.text()) % loc)
130 self.ui.but_pull.setChecked(False)
131
132 def _is_pull_selected(self):
133 return self.ui.but_pull.isChecked()
134
135 def _get_pull_location(self):
136 return str(self.ui.location.currentText())
137
138 def validate(self):
139 if self._is_pull_selected() and not self._get_pull_location():
140 self.operation_blocked(gettext("You should specify source branch location"))
141 return False
142 return True
143
144 def do_start(self):
145 if self._is_pull_selected():
146 args = ['--directory', self.branch.base]
147 if self.ui.but_pull_overwrite.isChecked():
148 args.append('--overwrite')
149 location = self._get_pull_location()
150 self.process_widget.do_start(None, 'pull', location, *args)
151 else:
152 # its an update.
153 self.process_widget.do_start(None, 'update', self.branch.base)