/[gli]/branches/overhaul/src/fe/gtk/NetworkMounts.py
Gentoo

Contents of /branches/overhaul/src/fe/gtk/NetworkMounts.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1623 - (show annotations) (download) (as text)
Fri Jan 19 10:19:38 2007 UTC (7 years, 5 months ago) by agaffney
File MIME type: text/x-python
File size: 13692 byte(s)
remove Help button
rearrange Stage screen
1 # Copyright 1999-2005 Gentoo Foundation
2 # This source code is distributed under the terms of version 2 of the GNU
3 # General Public License as published by the Free Software Foundation, a copy
4 # of which can be found in the main directory of this project.
5
6 import gtk, gobject
7 import GLIScreen
8 import GLIUtility
9 import Widgets
10 import commands, string
11 import copy
12
13 class Panel(GLIScreen.GLIScreen):
14
15 title = "Network Mounts"
16 columns = []
17 netmounts = []
18 active_entry = -1
19 mount_types = ["NFS"]
20 _helptext = """
21 <b><u>Network Mounts</u></b>
22
23 Here, you can specify network shares to mount during (and after) the install.
24 They will be mounted along with the local partitions you specified on the
25 previous screen when the install starts. This is useful for using a NFS mounted
26 /usr/portage.
27
28 To start, click the button labeled 'New'. Then, select a mount type. Currently,
29 the only supported type is NFS. If you get this choice wrong, you shall be
30 shunned. Next, enter a hostname or IP address. Then, you can either enter the
31 name of the share/export or click the button next to the field to have it
32 auto-populated with the available shares on the host you entered in the box
33 above. Enter a local mountpoint and mount options. Click the button labeled
34 'Update' to save the new network mount.
35
36 To edit an existing mount, select it in the list above. Edit any fields below
37 and then click the 'Update' button. You can remove it from the list by clicking
38 the 'Delete' button.
39 """
40
41 def __init__(self, controller):
42 GLIScreen.GLIScreen.__init__(self, controller)
43 vert = gtk.VBox(False, 0)
44 vert.set_border_width(10)
45
46 content_str = """Here, you will be able to define any network mounts that you want to use during
47 and after the installation. For example, you can mount /usr/portage from another box
48 on your network so you don't have to 'emerge sync' and store the tree locally. Currently,
49 only NFS is supported.
50 """
51
52 content_label = gtk.Label(content_str)
53 vert.pack_start(content_label, expand=False, fill=False, padding=0)
54
55 self.treedata = gtk.ListStore(gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
56 for i in range(0, len(self.netmounts)):
57 self.treedata.append([i, self.netmounts[i]['host'], self.netmounts[i]['export'], self.netmounts[i]['type'], self.netmounts[i]['mountpoint'], self.netmounts[i]['mountopts']])
58 self.treedatasort = gtk.TreeModelSort(self.treedata)
59 self.treeview = gtk.TreeView(self.treedatasort)
60 self.treeview.connect("cursor-changed", self.selection_changed)
61 self.columns.append(gtk.TreeViewColumn("Host/IP", gtk.CellRendererText(), text=1))
62 self.columns.append(gtk.TreeViewColumn("Export/Share", gtk.CellRendererText(), text=2))
63 self.columns.append(gtk.TreeViewColumn("Type", gtk.CellRendererText(), text=3))
64 self.columns.append(gtk.TreeViewColumn("Mount Point", gtk.CellRendererText(), text=4))
65 self.columns.append(gtk.TreeViewColumn("Mount Options", gtk.CellRendererText(), text=5))
66 col_num = 0
67 for column in self.columns:
68 column.set_resizable(True)
69 column.set_sort_column_id(col_num)
70 self.treeview.append_column(column)
71 col_num += 1
72 self.treewindow = gtk.ScrolledWindow()
73 self.treewindow.set_size_request(-1, 130)
74 self.treewindow.set_shadow_type(gtk.SHADOW_IN)
75 self.treewindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
76 self.treewindow.add(self.treeview)
77 vert.pack_start(self.treewindow, expand=False, fill=False, padding=0)
78
79 self.mount_info_box = gtk.HBox(False, 0)
80 mount_info_table = gtk.Table(5, 3, False)
81 mount_info_table.set_col_spacings(10)
82 mount_info_table.set_row_spacings(6)
83 mount_info_type_label = gtk.Label("Type:")
84 mount_info_type_label.set_alignment(0.0, 0.5)
85 mount_info_table.attach(mount_info_type_label, 0, 1, 0, 1)
86 self.mount_info_type = gtk.combo_box_new_text()
87 for mount_type in self.mount_types:
88 self.mount_info_type.append_text(mount_type)
89 self.mount_info_type.set_active(0)
90 mount_info_table.attach(self.mount_info_type, 1, 2, 0, 1)
91 mount_info_host_label = gtk.Label("Host/IP:")
92 mount_info_host_label.set_alignment(0.0, 0.5)
93 mount_info_table.attach(mount_info_host_label, 0, 1, 1, 2)
94 self.mount_info_host = gtk.Entry()
95 self.mount_info_host.set_width_chars(25)
96 mount_info_table.attach(self.mount_info_host, 1, 2, 1, 2)
97 mount_info_export_label = gtk.Label("Export/Share:")
98 mount_info_export_label.set_alignment(0.0, 0.5)
99 mount_info_table.attach(mount_info_export_label, 0, 1, 2, 3)
100 self.mount_info_export = gtk.ComboBoxEntry(gtk.ListStore(gobject.TYPE_STRING))
101 if not self.mount_info_export.get_text_column() == 0:
102 self.mount_info_export.set_text_column(0)
103 mount_info_table.attach(self.mount_info_export, 1, 2, 2, 3)
104 self.mount_info_export_refresh = gtk.Button()
105 mount_info_export_refresh_img = gtk.Image()
106 mount_info_export_refresh_img.set_from_file(self.full_path + '/button_images/stock_refresh.png')
107 self.mount_info_export_refresh.add(mount_info_export_refresh_img)
108 self.mount_info_export_refresh.connect("clicked", self.populate_exports)
109 mount_info_table.attach(self.mount_info_export_refresh, 2, 3, 2, 3)
110 mount_info_mountpoint_label = gtk.Label("Mount point:")
111 mount_info_mountpoint_label.set_alignment(0.0, 0.5)
112 mount_info_table.attach(mount_info_mountpoint_label, 0, 1, 3, 4)
113 self.mount_info_mountpoint = gtk.Entry()
114 self.mount_info_mountpoint.set_width_chars(30)
115 mount_info_table.attach(self.mount_info_mountpoint, 1, 2, 3, 4)
116 mount_info_mountopts_label = gtk.Label("Mount options:")
117 mount_info_mountopts_label.set_alignment(0.0, 0.5)
118 mount_info_table.attach(mount_info_mountopts_label, 0, 1, 4, 5)
119 self.mount_info_mountopts = gtk.Entry()
120 self.mount_info_mountopts.set_width_chars(30)
121 mount_info_table.attach(self.mount_info_mountopts, 1, 2, 4, 5)
122 self.mount_info_box.pack_start(mount_info_table, expand=False, fill=False)
123 vert.pack_start(self.mount_info_box, expand=False, fill=False, padding=10)
124
125 mount_button_box = gtk.HBox(False, 0)
126 mount_button_new = gtk.Button(" _New ")
127 mount_button_new.connect("clicked", self.new_mount)
128 mount_button_box.pack_start(mount_button_new, expand=False, fill=False, padding=10)
129 self.mount_button_update = gtk.Button(" _Update ")
130 self.mount_button_update.connect("clicked", self.update_mount)
131 self.mount_button_update.set_sensitive(False)
132 mount_button_box.pack_start(self.mount_button_update, expand=False, fill=False, padding=10)
133 self.mount_button_delete = gtk.Button(" _Delete ")
134 self.mount_button_delete.connect("clicked", self.delete_mount)
135 self.mount_button_delete.set_sensitive(False)
136 mount_button_box.pack_start(self.mount_button_delete, expand=False, fill=False, padding=10)
137 self.mount_button_populate = gtk.Button(" _Populate Exports ")
138 self.mount_button_populate.connect("clicked", self.populate_exports)
139 self.mount_button_populate.set_sensitive(False)
140 mount_button_box.pack_start(self.mount_button_populate, expand=False, fill=False, padding=10)
141 vert.pack_start(mount_button_box, expand=False, fill=False, padding=10)
142
143 self.add_content(vert)
144
145 def disable_all_fields(self):
146 self.mount_info_host.set_text("")
147 self.mount_info_export.get_child().set_text("")
148 self.mount_info_export.set_model(gtk.ListStore(gobject.TYPE_STRING))
149 self.mount_info_mountpoint.set_text("")
150 self.mount_info_mountopts.set_text("")
151 self.mount_info_host.set_sensitive(False)
152 self.mount_info_export.set_sensitive(False)
153 self.mount_info_export_refresh.set_sensitive(False)
154 self.mount_info_type.set_sensitive(False)
155 self.mount_info_mountpoint.set_sensitive(False)
156 self.mount_info_mountopts.set_sensitive(False)
157
158 def enable_all_fields(self):
159 self.mount_info_host.set_text("")
160 self.mount_info_export.get_child().set_text("")
161 self.mount_info_export.set_model(gtk.ListStore(gobject.TYPE_STRING))
162 self.mount_info_mountpoint.set_text("")
163 self.mount_info_mountopts.set_text("")
164 self.mount_info_host.set_sensitive(True)
165 self.mount_info_export.set_sensitive(True)
166 self.mount_info_export_refresh.set_sensitive(True)
167 self.mount_info_type.set_sensitive(True)
168 self.mount_info_mountpoint.set_sensitive(True)
169 self.mount_info_mountopts.set_sensitive(True)
170
171 def refresh_list_at_top(self):
172 self.treedata = gtk.ListStore(gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
173 for i in range(0, len(self.netmounts)):
174 self.treedata.append([i, self.netmounts[i]['host'], self.netmounts[i]['export'], self.netmounts[i]['type'], self.netmounts[i]['mountpoint'], self.netmounts[i]['mountopts']])
175 self.treedatasort = gtk.TreeModelSort(self.treedata)
176 self.treeview.set_model(self.treedatasort)
177 self.treeview.show_all()
178
179 def selection_changed(self, treeview, data=None):
180 treeselection = treeview.get_selection()
181 treemodel, treeiter = treeselection.get_selected()
182 row = treemodel.get(treeiter, 0)
183 self.active_entry = row[0]
184 mount = self.netmounts[self.active_entry]
185 self.enable_all_fields()
186 self.mount_info_host.set_text(mount['host'])
187 self.mount_info_export.set_model(gtk.ListStore(gobject.TYPE_STRING))
188 self.mount_info_export.get_child().set_text(mount['export'])
189 i = 0
190 for mounttype in self.mount_types:
191 if mounttype == mount['type']:
192 self.mount_info_type.set_active(i)
193 else:
194 i = i + 1
195 self.mount_info_mountpoint.set_text(mount['mountpoint'])
196 self.mount_info_mountopts.set_text(mount['mountopts'])
197 self.mount_button_update.set_sensitive(True)
198 self.mount_button_delete.set_sensitive(True)
199 self.mount_button_populate.set_sensitive(True)
200
201 def new_mount(self, button, data=None):
202 self.active_entry = -1
203 self.mount_button_update.set_sensitive(True)
204 self.mount_button_delete.set_sensitive(False)
205 self.mount_button_populate.set_sensitive(True)
206 self.enable_all_fields()
207 self.mount_info_host.grab_focus()
208
209 def update_mount(self, button, data=None):
210 if not GLIUtility.is_ip(self.mount_info_host.get_text()) and not GLIUtility.is_hostname(self.mount_info_host.get_text()):
211 msgdialog = Widgets.Widgets().error_Box("Invalid Host or IP", "You must specify a valid hostname or IP address")
212 result = msgdialog.run()
213 if result == gtk.RESPONSE_ACCEPT:
214 msgdialog.destroy()
215 return
216 if self.mount_info_export.get_child().get_text() == "":
217 msgdialog = Widgets.Widgets().error_Box("Invalid Entry", "You must enter a value for the export field")
218 result = msgdialog.run()
219 if result == gtk.RESPONSE_ACCEPT:
220 msgdialog.destroy()
221 return
222 if self.mount_info_mountpoint.get_text() == "":
223 msgdialog = Widgets.Widgets().error_Box("Invalid Entry", "You must enter a mountpoint")
224 result = msgdialog.run()
225 if result == gtk.RESPONSE_ACCEPT:
226 msgdialog.destroy()
227 return
228 if self.active_entry == -1:
229 self.netmounts.append({ 'host': self.mount_info_host.get_text(), 'export': self.mount_info_export.get_child().get_text(), 'type': self.mount_types[self.mount_info_type.get_active()], 'mountpoint': self.mount_info_mountpoint.get_text(), 'mountopts': self.mount_info_mountopts.get_text() })
230 self.active_entry = -1
231 self.mount_button_update.set_sensitive(False)
232 self.mount_button_delete.set_sensitive(False)
233 self.mount_button_populate.set_sensitive(False)
234 else:
235 self.netmounts[self.active_entry]['host'] = self.mount_info_host.get_text()
236 self.netmounts[self.active_entry]['export'] = self.mount_info_export.get_child().get_text()
237 self.netmounts[self.active_entry]['type'] = self.mount_info_type.get_text()
238 self.netmounts[self.active_entry]['mountpoint'] = self.mount_info_mountpoint.get_text()
239 self.netmounts[self.active_entry]['mountopts'] = self.mount_info_mountopts.get_text()
240 self.refresh_list_at_top()
241 self.disable_all_fields()
242
243 def delete_mount(self, button, data=None):
244 self.netmounts.pop(self.active_entry)
245 self.active_entry = -1
246 self.mount_button_update.set_sensitive(False)
247 self.mount_button_delete.set_sensitive(False)
248 self.mount_button_populate.set_sensitive(False)
249 self.refresh_list_at_top()
250 self.disable_all_fields()
251
252 def populate_exports(self, button, data=None):
253 host = self.mount_info_host.get_text()
254 oldtext = self.mount_info_export.get_child().get_text()
255 if GLIUtility.is_ip(host) or GLIUtility.is_hostname(host):
256 remotemounts = commands.getoutput("/usr/sbin/showmount -e " + host + " 2>&1 | egrep '^/' | cut -d ' ' -f 1 && echo")
257 mountlist = gtk.ListStore(gobject.TYPE_STRING)
258 self.mount_info_export.set_model(mountlist)
259 while remotemounts.find("\n") != -1:
260 index = remotemounts.find("\n") + 1
261 remotemount = remotemounts[:index]
262 remotemounts = remotemounts[index:]
263 remotemount = string.strip(remotemount)
264 mountlist.append([remotemount])
265 self.mount_info_export.get_child().set_text(oldtext)
266 else:
267 msgdialog = Widgets.Widgets().error_Box("Invalid Host or IP", "You must specify a valid hostname or IP address to scan for exports")
268 result = msgdialog.run()
269 if result == gtk.RESPONSE_ACCEPT:
270 msgdialog.destroy()
271
272 def activate(self):
273 self.controller.SHOW_BUTTON_EXIT = True
274 # self.controller.SHOW_BUTTON_HELP = True
275 self.controller.SHOW_BUTTON_BACK = True
276 self.controller.SHOW_BUTTON_FORWARD = True
277 self.controller.SHOW_BUTTON_FINISH = False
278 self.netmounts = copy.deepcopy(self.controller.install_profile.get_network_mounts())
279 self.refresh_list_at_top()
280 self.disable_all_fields()
281 self.mount_button_update.set_sensitive(False)
282 self.mount_button_delete.set_sensitive(False)
283 self.mount_button_populate.set_sensitive(False)
284
285 def deactivate(self):
286 self.controller.install_profile.set_network_mounts(self.netmounts)
287 return True

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20