Debian Codegraph @

lib/init.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # QBrz - Qt frontend to Breezy commands
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 from PyQt5 import QtCore
19 import os
20
21 from breezy.commands import get_cmd_object
22
23 from breezy.plugins.qbrz.lib.i18n import gettext
24 from breezy.plugins.qbrz.lib.subprocess import SubProcessDialog
25 from breezy.plugins.qbrz.lib.ui_init import Ui_InitForm
26
27 from breezy.plugins.qbrz.lib.util import (
28 hookup_directory_picker,
29 DIRECTORYPICKER_TARGET,
30 )
31
32
33 class QBzrInitWindow(SubProcessDialog):
34
35 def __init__(self, localdir=".", parent=None, ui_mode=False):
36 super(QBzrInitWindow, self).__init__(
37 gettext("Initialize"),
38 name = "init",
39 ui_mode = ui_mode,
40 dialog = True,
41 parent = parent,
42 hide_progress=True)
43
44 self.ui = Ui_InitForm()
45 self.ui.setupUi(self)
46 # and add the subprocess widgets.
47 for w in self.make_default_layout_widgets():
48 self.layout().addWidget(w)
49
50 # One directory picker
51 self.ui.location.setText(os.path.abspath(localdir))
52 hookup_directory_picker(self,
53 self.ui.location_picker,
54 self.ui.location,
55 DIRECTORYPICKER_TARGET)
56
57 # Combo box for repo format.
58 cmd = get_cmd_object('init')
59 opt = cmd.options()['format']
60 fill_option_combo(self.ui.combo_format, opt, 'default',
61 self.ui.format_desc)
62
63 self.ui.but_append_only.setToolTip(cmd.options()['append-revisions-only'].help)
64
65 cmd = get_cmd_object('init-repo')
66 opt = cmd.options()['no-trees']
67 self.ui.but_no_trees.setToolTip(opt.help)
68
69 def _get_location(self):
70 return str(self.ui.location.text())
71
72 def validate(self):
73 if not self._get_location():
74 self.operation_blocked(gettext("You should specify a location"))
75 return False
76 return True
77
78 def do_start(self):
79 if self.ui.but_init.isChecked():
80 args = ['init']
81 if self.ui.but_append_only.isChecked():
82 args.append('--append-revisions-only')
83 else:
84 args = ['init-repo']
85 if self.ui.but_no_trees.isChecked():
86 args.append('--no-trees')
87 args.append('--format=' + self.ui.combo_format.currentText())
88
89 args.append(self._get_location())
90
91 self.process_widget.do_start(None, *args)
92
93
94 # TODO: Move this to the 'utils' module - but let's wait until we have another
95 # user for this function, and we can see if it makes more sense to just
96 # pass the command and option names rather than the option object itself?
97 def fill_option_combo(combo, option, default, desc_widget=None):
98 """Fill a widget with the values specified in a bzr.options.Option object.
99
100 If default is specified, a string match is made. Otherwise, the first
101 option is the default.
102
103 If desc_widget is specified, it is a widget which will be updated with
104 the help text for the option as each option is selected.
105 """
106
107 def index_changed(index, combo=combo, desc_widget=desc_widget):
108 help = combo.itemData(index)
109 desc_widget.setText(help)
110
111 default_index = 0
112 for i, info in enumerate(option.iter_switches()):
113 if i==0:
114 # this is the option itself
115 continue
116 name, short_name, argname, help = info
117 if option.is_hidden(name):
118 continue
119 user_data = help or ''
120 combo.addItem(name, user_data)
121 if name == default:
122 default_index = combo.count() - 1
123 if desc_widget is not None:
124 combo.currentIndexChanged[int].connect(index_changed)
125
126 combo.setCurrentIndex(default_index)