Print this page
*** NO COMMENTS ***
| Split |
Close |
| Expand all |
| Collapse all |
--- old/src/packagemanager.py
+++ new/src/packagemanager.py
1 1 #!/usr/bin/python2.4
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License (the "License").
7 7 # You may not use this file except in compliance with the License.
8 8 #
9 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 # or http://www.opensolaris.org/os/licensing.
11 11 # See the License for the specific language governing permissions
12 12 # and limitations under the License.
13 13 #
14 14 # When distributing Covered Code, include this CDDL HEADER in each
15 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 # If applicable, add the following below this CDDL HEADER, with the
17 17 # fields enclosed by brackets "[]" replaced with your own identifying
18 18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 19 #
20 20 # CDDL HEADER END
21 21 #
22 22 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 # Use is subject to license terms.
24 24 #
25 25
26 26 # Progress:
27 27 # Startup Progress has two phases:
28 28 # - Start phase:
29 29 # The start phase should be fairly constant at around a few seconds and so is given 5%
30 30 # of the total progress bar.
31 31 # - Package entry loading phase:
32 32 # The package entry loading phase is given the remaining 95% of the bar for progress.
33 33
34 34 INITIAL_PROGRESS_TIME_INTERVAL = 0.5 # Time to update progress during start phase
35 35 INITIAL_PROGRESS_TIME_PERCENTAGE = 0.005 # Amount to update progress during start phase
36 36 INITIAL_PROGRESS_TOTAL_PERCENTAGE = 0.05 # Total progress for start phase
37 37 PACKAGE_PROGRESS_TOTAL_INCREMENTS = 95.0 # Total increments for loading phase
38 38 PACKAGE_PROGRESS_PERCENT_INCREMENT = 0.01 # Amount to update progress during loading phase
39 39 PACKAGE_PROGRESS_PERCENT_TOTAL = 1.0 # Total progress for loading phase
40 40
41 41 import getopt
42 42 import os
43 43 import sys
44 44 import time
45 45 import locale
46 46 import socket
47 47 import gettext
48 48 from threading import Thread
49 49 try:
50 50 import gobject
51 51 gobject.threads_init()
|
↓ open down ↓ |
51 lines elided |
↑ open up ↑ |
52 52 import gtk
53 53 import gtk.glade
54 54 import pygtk
55 55 pygtk.require("2.0")
56 56 except ImportError:
57 57 sys.exit(1)
58 58 import pkg.client.image as image
59 59 import pkg.client.progress as progress
60 60 import pkg.misc as misc
61 61 import pkg.portable as portable
62 +import pkg.gui.beadmin as beadm
62 63 import pkg.gui.imageinfo as imageinfo
63 64 import pkg.gui.installupdate as installupdate
64 65 import pkg.gui.remove as remove
65 66 import pkg.gui.enumerations as enumerations
66 67
67 68
68 69 class PackageManager:
69 70 def __init__(self):
70 71 self.image_o = None
71 72 socket.setdefaulttimeout(
72 73 int(os.environ.get("PKG_CLIENT_TIMEOUT", "30"))) # in seconds
73 74
74 75 # Override default MAX_TIMEOUT_COUNT if a value has been specified
75 76 # in the environment.
76 77 timeout_max = misc.MAX_TIMEOUT_COUNT
77 78 misc.MAX_TIMEOUT_COUNT = int(os.environ.get("PKG_TIMEOUT_MAX",
78 79 timeout_max))
79 80
80 81 try:
81 82 self.application_dir = os.environ["PACKAGE_MANAGER_ROOT"]
82 83 except KeyError:
83 84 self.application_dir = "/"
84 85 locale.setlocale(locale.LC_ALL, '')
85 86 for module in (gettext, gtk.glade):
86 87 module.bindtextdomain("packagemanager", self.application_dir + \
87 88 "/usr/share/locale")
88 89 module.textdomain("packagemanager")
89 90 self._ = gettext.gettext
90 91 main_window_title = self._('Package Manager - revision 0.1')
91 92 self.user_rights = portable.is_admin()
92 93 self.cancelled = False # For background processes
93 94 self.image_directory = None
94 95 self.description_thread_running = False # For background processes
95 96 self.pkginfo_thread = None # For background processes
96 97 gtk.rc_parse('~/.gtkrc-1.2-gnome2') # Load gtk theme
97 98 self.main_clipboard_text = None
98 99 self.ipkg_fmri = "SUNWipkg"
99 100 self.ipkggui_fmri = "SUNWipkg-gui"
100 101 self.progress_stop_timer_thread = False
101 102 self.progress_fraction_time_count = 0
102 103 self.progress_canceled = False
103 104 self.ips_uptodate = False
104 105 self.image_dir_arg = None
105 106 self.application_path = None
106 107
107 108 self.application_list = \
108 109 gtk.ListStore(
109 110 gobject.TYPE_BOOLEAN, # enumerations.MARK_COLUMN
110 111 gtk.gdk.Pixbuf, # enumerations.STATUS_ICON_COLUMN
111 112 gtk.gdk.Pixbuf, # enumerations.ICON_COLUMN
112 113 gobject.TYPE_STRING, # enumerations.NAME_COLUMN
113 114 gobject.TYPE_STRING, # enumerations.INSTALLED_VERSION_COLUMN
114 115 gobject.TYPE_PYOBJECT, # enumerations.INSTALLED_OBJECT_COLUMN
115 116 gobject.TYPE_STRING, # enumerations.LATEST_AVAILABLE_COLUMN
116 117 gobject.TYPE_INT, # enumerations.RATING_COLUMN
117 118 gobject.TYPE_STRING, # enumerations.DESCRIPTION_COLUMN
118 119 gobject.TYPE_PYOBJECT, # enumerations.PACKAGE_OBJECT_COLUMN
119 120 gobject.TYPE_PYOBJECT, # enumerations.IMAGE_OBJECT_COLUMN
120 121 gobject.TYPE_BOOLEAN, # enumerations.IS_VISIBLE_COLUMN
121 122 gobject.TYPE_PYOBJECT # enumerations.CATEGORY_LIST_OBJECT
122 123 )
123 124 self.category_list = \
124 125 gtk.ListStore(
125 126 gobject.TYPE_INT, # enumerations.CATEGORY_ID
126 127 gobject.TYPE_STRING, # enumerations.CATEGORY_NAME
127 128 gobject.TYPE_STRING, # enumerations.CATEGORY_DESCRIPTION
128 129 gtk.gdk.Pixbuf, # enumerations.CATEGORY_ICON
129 130 gobject.TYPE_BOOLEAN, # enumerations.CATEGORY_VISIBLE
130 131 gobject.TYPE_PYOBJECT, # enumerations.SECTION_LIST_OBJECT
131 132 )
132 133 self.section_list = \
133 134 gtk.ListStore(
134 135 gobject.TYPE_INT, # enumerations.SECTION_ID
135 136 gobject.TYPE_STRING, # enumerations.SECTION_NAME
136 137 )
137 138 self.filter_list = \
138 139 gtk.ListStore(
139 140 gobject.TYPE_INT, # enumerations.FILTER_ID
140 141 gobject.TYPE_STRING, # enumerations.FILTER_NAME
141 142 )
142 143 self.repositories_list = \
143 144 gtk.ListStore(
144 145 gobject.TYPE_INT, # enumerations.REPOSITORY_ID
145 146 gobject.TYPE_STRING, # enumerations.REPOSITORY_NAME
146 147 )
147 148
148 149 self.application_list_filter = self.application_list.filter_new()
149 150 self.pr = progress.NullProgressTracker()
150 151
151 152 # Create Widgets and show gui
152 153
153 154 self.gladefile = self.application_dir + \
154 155 "/usr/share/package-manager/packagemanager.glade"
155 156 w_tree_main = gtk.glade.XML(self.gladefile, "mainwindow")
156 157 w_tree_progress = gtk.glade.XML(self.gladefile, "progressdialog")
157 158
158 159 self.w_main_window = w_tree_main.get_widget("mainwindow")
159 160 self.w_application_treeview = \
160 161 w_tree_main.get_widget("applicationtreeview")
161 162 self.w_categories_treeview = w_tree_main.get_widget("categoriestreeview")
162 163 self.w_generalinfo_textview = \
163 164 w_tree_main.get_widget("generalinfotextview")
164 165 self.w_installedfiles_textview = \
165 166 w_tree_main.get_widget("installedfilestextview")
166 167 self.w_dependencies_textview = \
167 168 w_tree_main.get_widget("dependenciestextview")
168 169 self.w_packagename_label = w_tree_main.get_widget("packagenamelabel")
169 170 self.w_shortdescription_label = \
170 171 w_tree_main.get_widget("shortdescriptionlabel")
171 172 self.w_searchentry_dialog = w_tree_main.get_widget("searchentry")
172 173 self.w_installupdate_button = \
173 174 w_tree_main.get_widget("install_update_button")
174 175 self.w_remove_button = w_tree_main.get_widget("remove_button")
175 176 self.w_updateall_button = w_tree_main.get_widget("update_all_button")
176 177 self.w_reload_button = w_tree_main.get_widget("reloadbutton")
177 178 self.w_repository_combobox = w_tree_main.get_widget("repositorycombobox")
178 179 self.w_sections_combobox = w_tree_main.get_widget("sectionscombobox")
179 180 self.w_filter_combobox = w_tree_main.get_widget("filtercombobox")
180 181 self.w_packageicon_image = w_tree_main.get_widget("packageimage")
181 182 self.w_main_statusbar = w_tree_main.get_widget("statusbar")
182 183 self.w_installupdate_menuitem = \
183 184 w_tree_main.get_widget("package_install_update")
184 185 self.w_remove_menuitem = w_tree_main.get_widget("package_remove")
185 186 self.w_updateall_menuitem = w_tree_main.get_widget("package_update_all")
186 187 self.w_cut_menuitem = w_tree_main.get_widget("edit_cut")
187 188 self.w_copy_menuitem = w_tree_main.get_widget("edit_copy")
188 189 self.w_paste_menuitem = w_tree_main.get_widget("edit_paste")
189 190 self.w_clear_menuitem = w_tree_main.get_widget("edit_clear")
190 191 self.w_selectall_menuitem = w_tree_main.get_widget("edit_select_all")
191 192 self.w_selectupdates_menuitem = \
192 193 w_tree_main.get_widget("edit_select_updates")
193 194 self.w_deselect_menuitem = w_tree_main.get_widget("edit_deselect")
194 195 self.w_main_clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
195 196
196 197 self.w_progress_dialog = w_tree_progress.get_widget("progressdialog")
197 198 self.w_progress_dialog.set_title(self._("Update All"))
198 199 self.w_progressinfo_label = w_tree_progress.get_widget("progressinfo")
199 200 self.w_progressinfo_label.set_text(self._( \
200 201 "Checking SUNWipkg and SUNWipkg-gui versions\n\nPlease wait ..."))
201 202 self.w_progressbar = w_tree_progress.get_widget("progressbar")
202 203 self.w_progressbar.set_pulse_step(0.1)
203 204 self.w_progress_cancel = w_tree_progress.get_widget("progresscancel")
204 205 self.progress_canceled = False
205 206
206 207 self.__update_reload_button()
207 208 self.w_main_clipboard.request_text(self.__clipboard_text_received)
208 209 self.w_main_window.set_title(main_window_title)
209 210
210 211 try:
211 212 dic_mainwindow = \
212 213 {
213 214 "on_mainwindow_delete_event": \
214 215 self.__on_mainwindow_delete_event,
215 216 "on_searchentry_changed":self.__on_searchentry_changed,
216 217 "on_searchentry_focus_in_event": \
217 218 self.__on_searchentry_focus_in,
218 219 "on_searchentry_focus_out_event": \
|
↓ open down ↓ |
147 lines elided |
↑ open up ↑ |
219 220 self.__on_searchentry_focus_out,
220 221 "on_searchentry_event":self.__on_searchentry_event,
221 222 "on_sectionscombobox_changed": \
222 223 self.__on_sectionscombobox_changed,
223 224 "on_filtercombobox_changed": \
224 225 self.__on_filtercombobox_changed,
225 226 "on_repositorycombobox_changed": \
226 227 self.__on_repositorycombobox_changed,
227 228 #menu signals
228 229 "on_file_quit_activate":self.__on_file_quit_activate,
230 + "on_file_be_activate":self.__on_file_be_activate,
229 231 "on_package_install_update_activate": \
230 232 self.__on_install_update,
231 233 "on_package_remove_activate":self.__on_remove,
232 234 "on_help_about_activate":self.__on_help_about,
233 235 "on_edit_paste_activate":self.__on_edit_paste,
234 236 "on_edit_clear_activate":self.__on_clear_paste,
235 237 "on_edit_copy_activate":self.__on_copy,
236 238 "on_edit_cut_activate":self.__on_cut,
237 239 "on_edit_select_all_activate":self.__on_select_all,
238 240 "on_edit_select_updates_activate": \
239 241 self.__on_select_updates,
240 242 "on_edit_deselect_activate":self.__on_deselect,
241 243 # XXX disabled until new API
242 244 "on_package_update_all_activate":self.__on_update_all,
243 245 #toolbar signals
244 246 # XXX disabled until new API
245 247 "on_update_all_button_clicked":self.__on_update_all,
246 248 "on_reload_button_clicked":self.__on_reload,
247 249 "on_install_update_button_clicked": \
248 250 self.__on_install_update,
249 251 "on_remove_button_clicked":self.__on_remove
250 252 }
251 253 dic_progress = \
252 254 {
253 255 "on_cancel_progressdialog_clicked": \
254 256 self.__on_cancel_progressdialog_clicked,
255 257 }
256 258 w_tree_main.signal_autoconnect(dic_mainwindow)
257 259 w_tree_progress.signal_autoconnect(dic_progress)
258 260 except AttributeError, error:
259 261 print self._( \
260 262 'GUI will not respond to any event! %s.' + \
261 263 'Check declare_signals()') \
262 264 % error
263 265
264 266 self.package_selection = None
265 267 self.category_list_filter = None
266 268 self.in_setup = True
267 269 self.w_main_window.show_all()
268 270
269 271 def __init_tree_views(self):
270 272 '''This function connects treeviews with their models and also applies
271 273 filters'''
272 274 ##APPLICATION MAIN TREEVIEW
273 275 application_list_sort = \
274 276 gtk.TreeModelSort(self.application_list_filter)
275 277 self.w_application_treeview.set_model(application_list_sort)
276 278 model = self.w_application_treeview.get_model()
277 279 toggle_renderer = gtk.CellRendererToggle()
278 280 toggle_renderer.connect('toggled', self.__active_pane_toggle, model)
279 281 column = gtk.TreeViewColumn("", toggle_renderer, \
280 282 active = enumerations.MARK_COLUMN)
281 283 column.set_sort_column_id(enumerations.MARK_COLUMN)
282 284 column.set_sort_indicator(True)
283 285 column.set_cell_data_func(toggle_renderer, self.cell_data_function, None)
284 286 self.w_application_treeview.append_column(column)
285 287 column = gtk.TreeViewColumn()
286 288 column.set_title("")
287 289 #Commented, since there was funny jumping of the icons
288 290 #column.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
289 291 render_pixbuf = gtk.CellRendererPixbuf()
290 292 column.pack_start(render_pixbuf, expand = False)
291 293 column.add_attribute(render_pixbuf, "pixbuf", \
292 294 enumerations.STATUS_ICON_COLUMN)
293 295 column.set_fixed_width(32)
294 296 column.set_cell_data_func(render_pixbuf, self.cell_data_function, None)
295 297 self.w_application_treeview.append_column(column)
296 298 column = gtk.TreeViewColumn()
297 299 column.set_title("")
298 300 #Commented, since there was funny jumping of the icons
299 301 #column.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
300 302 render_pixbuf = gtk.CellRendererPixbuf()
301 303 column.pack_start(render_pixbuf, expand = False)
302 304 column.add_attribute(render_pixbuf, "pixbuf", enumerations.ICON_COLUMN)
303 305 column.set_fixed_width(32)
304 306 column.set_cell_data_func(render_pixbuf, self.cell_data_function, None)
305 307 self.w_application_treeview.append_column(column)
306 308 name_renderer = gtk.CellRendererText()
307 309 column = gtk.TreeViewColumn(self._("Name"), name_renderer, \
308 310 text = enumerations.NAME_COLUMN)
309 311 column.set_sort_column_id(enumerations.NAME_COLUMN)
310 312 column.set_sort_indicator(True)
311 313 column.set_cell_data_func(name_renderer, self.cell_data_function, None)
312 314 self.w_application_treeview.append_column(column)
313 315 installed_version_renderer = gtk.CellRendererText()
314 316 column = gtk.TreeViewColumn(self._('Installed Version'), \
315 317 installed_version_renderer, \
316 318 text = enumerations.INSTALLED_VERSION_COLUMN)
317 319 column.set_sort_column_id(enumerations.INSTALLED_VERSION_COLUMN)
318 320 column.set_sort_indicator(True)
319 321 column.set_cell_data_func(installed_version_renderer, \
320 322 self.cell_data_function, None)
321 323 self.w_application_treeview.append_column(column)
322 324 latest_available_renderer = gtk.CellRendererText()
323 325 column = gtk.TreeViewColumn(self._('Latest Version'), \
324 326 latest_available_renderer, \
325 327 text = enumerations.LATEST_AVAILABLE_COLUMN)
326 328 column.set_sort_column_id(enumerations.LATEST_AVAILABLE_COLUMN)
327 329 column.set_sort_indicator(True)
328 330 column.set_cell_data_func(latest_available_renderer, \
329 331 self.cell_data_function, None)
330 332 self.w_application_treeview.append_column(column)
331 333 rating_renderer = gtk.CellRendererText()
332 334 column = gtk.TreeViewColumn(self._('Rating'), rating_renderer, \
333 335 text = enumerations.RATING_COLUMN)
334 336 column.set_cell_data_func(rating_renderer, self.cell_data_function, None)
335 337 description_renderer = gtk.CellRendererText()
336 338 column = gtk.TreeViewColumn(self._('Description'), \
337 339 description_renderer, text = enumerations.DESCRIPTION_COLUMN)
338 340 column.set_sort_column_id(enumerations.DESCRIPTION_COLUMN)
339 341 column.set_sort_indicator(True)
340 342 column.set_cell_data_func(description_renderer, \
341 343 self.cell_data_function, None)
342 344 self.w_application_treeview.append_column(column)
343 345 #Added selection listener
344 346 self.package_selection = self.w_application_treeview.get_selection()
345 347 self.package_selection.set_mode(gtk.SELECTION_SINGLE)
346 348 self.package_selection.connect("changed", \
347 349 self.__on_package_selection_changed, None)
348 350 ##CATEGORIES TREEVIEW
349 351 #enumerations.CATEGORY_NAME
350 352 self.category_list_filter = self.category_list.filter_new()
351 353 self.category_list_filter.set_visible_func(self.category_filter)
352 354 self.w_categories_treeview.set_model(self.category_list_filter)
353 355 enumerations.CATEGORY_NAME_renderer = gtk.CellRendererText()
354 356 column = gtk.TreeViewColumn(self._('Name'), \
355 357 enumerations.CATEGORY_NAME_renderer, \
356 358 text = enumerations.CATEGORY_NAME)
357 359 self.w_categories_treeview.append_column(column)
358 360 #Added selection listener
359 361 category_selection = self.w_categories_treeview.get_selection()
360 362 category_selection.set_mode(gtk.SELECTION_SINGLE)
361 363 category_selection.connect("changed", \
362 364 self.__on_category_selection_changed, None)
363 365 ##SECTION COMBOBOX
364 366 #enumerations.SECTION_NAME
365 367 self.w_sections_combobox.set_model(self.section_list)
366 368 cell = gtk.CellRendererText()
367 369 self.w_sections_combobox.pack_start(cell, True)
368 370 self.w_sections_combobox.add_attribute(cell, 'text', \
369 371 enumerations.SECTION_NAME)
370 372 self.w_sections_combobox.set_row_separator_func( \
371 373 self.combobox_id_separator)
372 374 ##FILTER COMBOBOX
373 375 #enumerations.FILTER_NAME
374 376 self.w_filter_combobox.set_model(self.filter_list)
375 377 cell = gtk.CellRendererText()
376 378 self.w_filter_combobox.pack_start(cell, True)
377 379 self.w_filter_combobox.add_attribute(cell, 'text', \
378 380 enumerations.FILTER_NAME)
379 381 self.w_filter_combobox.set_row_separator_func(self.combobox_id_separator)
380 382 ##FILTER COMBOBOX
381 383 #enumerations.FILTER_NAME
382 384 self.w_repository_combobox.set_model(self.repositories_list)
383 385 cell = gtk.CellRendererText()
384 386 self.w_repository_combobox.pack_start(cell, True)
385 387 self.w_repository_combobox.add_attribute(cell, 'text', \
386 388 enumerations.REPOSITORY_NAME)
387 389 self.w_repository_combobox.set_row_separator_func( \
388 390 self.combobox_id_separator)
389 391 self.w_filter_combobox.set_active(0)
390 392
391 393 def __init_sections(self):
392 394 '''This function is for initializing sections combo box, also adds "All"
393 395 Category. It sets active section combobox entry "All"'''
394 396 self.section_list.append([0, self._('All'), ])
395 397 self.section_list.append([-1, "", ])
396 398 self.section_list.append([2, self._('Meta Packages'), ])
397 399 self.section_list.append([3, self._('Applications Desktop'), ])
398 400 self.section_list.append([4, self._('Applications Web-Based'), ])
399 401 self.section_list.append([5, self._('Operating System'), ])
400 402 self.section_list.append([6, self._('User Environment'), ])
401 403 self.section_list.append([7, self._('Web Infrastructure'), ])
402 404
403 405 def __init_show_filter(self):
404 406 self.filter_list.append([0, self._('All Packages'), ])
405 407 self.filter_list.append([-1, "", ])
406 408 self.filter_list.append([2, self._('Installed Packages'), ])
407 409 self.filter_list.append([3, self._('Updates'), ])
408 410 self.filter_list.append([4, self._('Non-installed Packages'), ])
409 411 self.filter_list.append([-1, "", ])
410 412 # self.filter_list.append([self._('Locked Packages'), ])
411 413 # self.filter_list.append(["", ])
412 414 self.filter_list.append([6, self._('Selected Packages'), ])
413 415
414 416 def __on_cancel_progressdialog_clicked(self, widget):
415 417 self.progress_canceled = True
416 418 self.progress_stop_timer_thread = True
417 419
418 420 def __on_mainwindow_delete_event(self, widget, event):
419 421 ''' handler for delete event of the main window '''
420 422 if self.__check_if_something_was_changed() == True:
421 423 # XXX Change this to not quit and show dialog
|
↓ open down ↓ |
183 lines elided |
↑ open up ↑ |
422 424 # XXX if some changes were applied:
423 425 self.__main_application_quit()
424 426 return True
425 427 else:
426 428 self.__main_application_quit()
427 429
428 430 def __on_file_quit_activate(self, widget):
429 431 ''' handler for quit menu event '''
430 432 self.__on_mainwindow_delete_event(None, None)
431 433
434 + def __on_file_be_activate(self, widget):
435 + ''' handler for be menu event '''
436 + beadm.Beadmin(self)
437 +
432 438 def __on_searchentry_changed(self, widget):
433 439 '''On text search field changed we should refilter the main view'''
434 440 Thread(target = self.__on_searchentry_threaded, args = ()).start()
435 441
436 442 def __on_searchentry_threaded(self):
437 443 gobject.idle_add(self.application_list_filter.refilter)
438 444 gobject.idle_add(self.__enable_disable_selection_menus)
439 445
440 446 def __on_edit_paste(self, widget):
441 447 self.w_searchentry_dialog.insert_text(self.main_clipboard_text, \
442 448 self.w_searchentry_dialog.get_position())
443 449
444 450 def __on_clear_paste(self, widget):
445 451 bounds = self.w_searchentry_dialog.get_selection_bounds()
446 452 self.w_searchentry_dialog.delete_text(bounds[0], bounds[1])
447 453 return
448 454
449 455 def __on_copy(self, widget):
450 456 bounds = self.w_searchentry_dialog.get_selection_bounds()
451 457 text = self.w_searchentry_dialog.get_chars(bounds[0], bounds[1])
452 458 self.w_main_clipboard.set_text(text)
453 459 return
454 460
455 461 def __on_cut(self, widget):
456 462 bounds = self.w_searchentry_dialog.get_selection_bounds()
457 463 text = self.w_searchentry_dialog.get_chars(bounds[0], bounds[1])
458 464 self.w_searchentry_dialog.delete_text(bounds[0], bounds[1])
459 465 self.w_main_clipboard.set_text(text)
460 466 return
461 467
462 468 def __on_select_all(self, widget):
463 469 sort_filt_model = \
464 470 self.w_application_treeview.get_model() #gtk.TreeModelSort
465 471 filt_model = sort_filt_model.get_model() #gtk.TreeModelFilter
466 472 model = filt_model.get_model() #gtk.ListStore
467 473 iter_next = sort_filt_model.get_iter_first()
468 474 list_of_paths = []
469 475 while iter_next != None:
470 476 sorted_path = sort_filt_model.get_path(iter_next)
471 477 filtered_path = \
472 478 sort_filt_model.convert_path_to_child_path(sorted_path)
473 479 path = filt_model.convert_path_to_child_path(filtered_path)
474 480 list_of_paths.append(path)
475 481 iter_next = sort_filt_model.iter_next(iter_next)
476 482 for path in list_of_paths:
477 483 itr = model.get_iter(path)
478 484 model.set_value(itr, enumerations.MARK_COLUMN, True)
479 485 self.__enable_disable_selection_menus()
480 486 self.update_statusbar()
481 487 self.__enable_disable_install_update()
482 488 self.__enable_disable_remove()
483 489
484 490 def __on_select_updates(self, widget):
485 491 sort_filt_model = \
486 492 self.w_application_treeview.get_model() #gtk.TreeModelSort
487 493 filt_model = sort_filt_model.get_model() #gtk.TreeModelFilter
488 494 model = filt_model.get_model() #gtk.ListStore
489 495 iter_next = sort_filt_model.get_iter_first()
490 496 list_of_paths = []
491 497 while iter_next != None:
492 498 sorted_path = sort_filt_model.get_path(iter_next)
493 499 filtered_iter = sort_filt_model.convert_iter_to_child_iter(None, \
494 500 iter_next)
495 501 app_iter = filt_model.convert_iter_to_child_iter(filtered_iter)
496 502
497 503 filtered_path = \
498 504 sort_filt_model.convert_path_to_child_path(sorted_path)
499 505 path = filt_model.convert_path_to_child_path(filtered_path)
500 506 if model.get_value(app_iter, \
501 507 enumerations.INSTALLED_VERSION_COLUMN):
502 508 if model.get_value(app_iter, \
503 509 enumerations.LATEST_AVAILABLE_COLUMN):
504 510 list_of_paths.append(path)
505 511 iter_next = sort_filt_model.iter_next(iter_next)
506 512 for path in list_of_paths:
507 513 itr = model.get_iter(path)
508 514 model.set_value(itr, enumerations.MARK_COLUMN, True)
509 515 self.__enable_disable_selection_menus()
510 516 self.update_statusbar()
511 517 self.__enable_disable_install_update()
512 518 self.__enable_disable_remove()
513 519
514 520 def __on_deselect(self, widget):
515 521 sort_filt_model = \
516 522 self.w_application_treeview.get_model() #gtk.TreeModelSort
517 523 filt_model = sort_filt_model.get_model() #gtk.TreeModelFilter
518 524 model = filt_model.get_model() #gtk.ListStore
519 525 iter_next = sort_filt_model.get_iter_first()
520 526 list_of_paths = []
521 527 while iter_next != None:
522 528 sorted_path = sort_filt_model.get_path(iter_next)
523 529 filtered_iter = sort_filt_model.convert_iter_to_child_iter(None, \
524 530 iter_next)
525 531 app_iter = filt_model.convert_iter_to_child_iter(filtered_iter)
526 532 filtered_path = \
527 533 sort_filt_model.convert_path_to_child_path(sorted_path)
528 534 path = filt_model.convert_path_to_child_path(filtered_path)
529 535 if model.get_value(app_iter, enumerations.MARK_COLUMN):
530 536 list_of_paths.append(path)
531 537 iter_next = sort_filt_model.iter_next(iter_next)
532 538 for path in list_of_paths:
533 539 itr = model.get_iter(path)
534 540 model.set_value(itr, enumerations.MARK_COLUMN, False)
535 541 self.__enable_disable_selection_menus()
536 542 self.update_statusbar()
537 543 self.__enable_disable_install_update()
538 544 self.__enable_disable_remove()
539 545
540 546 def __on_searchentry_focus_in(self, widget, event):
541 547 self.w_paste_menuitem.set_sensitive(True)
542 548
543 549 def __on_searchentry_focus_out(self, widget, event):
544 550 self.w_paste_menuitem.set_sensitive(False)
545 551
546 552 def __on_searchentry_event(self, widget, event):
547 553 self.w_main_clipboard.request_text(self.__clipboard_text_received)
548 554 if widget.get_selection_bounds():
549 555 #enable selection functions
550 556 self.w_cut_menuitem.set_sensitive(True)
551 557 self.w_copy_menuitem.set_sensitive(True)
552 558 self.w_clear_menuitem.set_sensitive(True)
553 559 else:
554 560 self.w_cut_menuitem.set_sensitive(False)
555 561 self.w_copy_menuitem.set_sensitive(False)
556 562 self.w_clear_menuitem.set_sensitive(False)
557 563
558 564 def __on_category_selection_changed(self, selection, widget):
559 565 '''This function is for handling category selection changes'''
560 566 self.application_list_filter.refilter()
561 567 self.__enable_disable_selection_menus()
562 568
563 569 def __on_package_selection_changed(self, selection, widget):
564 570 '''This function is for handling package selection changes'''
565 571 model, itr = selection.get_selected()
566 572 if itr:
567 573 pkg = model.get_value(itr, enumerations.INSTALLED_OBJECT_COLUMN)
568 574 if not pkg:
569 575 packages = model.get_value(itr, \
570 576 enumerations.PACKAGE_OBJECT_COLUMN)
571 577 pkg = max(packages)
572 578 self.pkginfo_thread = pkg
573 579 Thread(target = self.__show_package_info, \
574 580 args = (model, itr)).start()
575 581
576 582 def __on_filtercombobox_changed(self, widget):
577 583 '''On filter combobox changed'''
578 584 self.application_list_filter.refilter()
579 585 self.__enable_disable_selection_menus()
580 586
581 587 def __on_sectionscombobox_changed(self, widget):
582 588 '''On section combobox changed'''
583 589 selected_section = widget.get_active()
584 590 if selected_section == 0:
585 591 for category in self.category_list:
586 592 category[enumerations.CATEGORY_VISIBLE] = True
587 593 else:
588 594 for category in self.category_list:
589 595 if category[enumerations.CATEGORY_ID] == 0:
590 596 category[enumerations.CATEGORY_VISIBLE] = True
591 597 else:
592 598 category_list = \
593 599 category[enumerations.SECTION_LIST_OBJECT]
594 600 if not category_list:
595 601 category[enumerations.CATEGORY_VISIBLE] \
596 602 = False
597 603 else:
598 604 for section in category_list:
599 605 if section == selected_section:
600 606 category[enumerations. \
601 607 CATEGORY_VISIBLE] = \
602 608 True
603 609 else:
604 610 category[enumerations. \
605 611 CATEGORY_VISIBLE] = \
606 612 False
607 613 self.category_list_filter.refilter()
608 614 self.application_list_filter.refilter()
609 615 self.__enable_disable_selection_menus()
610 616
611 617 def __on_repositorycombobox_changed(self, widget):
612 618 '''On repository combobox changed'''
613 619 if self.in_setup:
614 620 return
615 621 self.application_list_filter.refilter()
616 622 self.__enable_disable_selection_menus()
617 623
618 624 def __on_install_update(self, widget):
619 625 installupdate.InstallUpdate(self.application_list, self, False)
620 626
621 627 def __on_update_all(self, widget):
622 628 opensolaris_image = True
623 629 fmris, notfound = self.__installed_fmris_from_args(self.image_o, \
624 630 ["SUNWipkg", "SUNWcs"])
625 631
626 632 if notfound:
627 633 opensolaris_image = False
628 634
629 635 if opensolaris_image:
630 636 # Load the catalogs from the repository, its a long
631 637 # running tasks so need a progress dialog
632 638 self.w_progress_dialog.set_title(self._("Update All"))
633 639 self.w_progressinfo_label.set_text(self._( \
634 640 "Checking SUNWipkg and SUNWipkg-gui versions\n" + \
635 641 "\nPlease wait ..."))
636 642
637 643 self.w_progress_dialog.show()
638 644 Thread(target = self.__progressdialog_progress_pulse).start()
639 645 Thread(target = self.__do_ips_uptodate_check).start()
640 646 self.w_progress_dialog.run()
641 647
642 648 if self.progress_canceled:
643 649 return
644 650 else:
645 651 self.ips_uptodate = True
646 652
647 653 #2790: Make sure ipkg and ipkg-gui are up to date, if not update them and
648 654 # prompt user to restart
649 655 if not self.ips_uptodate:
650 656 # Prompt user
651 657 msgbox = gtk.MessageDialog(parent = self.w_main_window, \
652 658 buttons = gtk.BUTTONS_YES_NO, \
653 659 flags = gtk.DIALOG_MODAL, type = gtk.MESSAGE_QUESTION, \
654 660 message_format = self._("Newer versions of SUNWipkg and" + \
655 661 "SUNWipkg-gui are available " + "and\nmust be updated" + \
656 662 "before running Update All.\n\n Do you want to update" + \
657 663 "them now?"))
658 664 msgbox.set_title(self._("Update All"))
659 665 result = msgbox.run()
660 666 msgbox.destroy()
661 667 if result == gtk.RESPONSE_YES:
662 668 pkg_list = [self.ipkg_fmri, self.ipkggui_fmri]
663 669 installupdate.InstallUpdate({self.image_o:pkg_list}, \
664 670 self, False, True)
665 671 else:
666 672 msgbox = gtk.MessageDialog(parent = self.w_main_window, \
667 673 buttons = gtk.BUTTONS_OK, \
668 674 flags = gtk.DIALOG_MODAL, type = gtk.MESSAGE_INFO, \
669 675 message_format = self._("Update All was not " + \
670 676 "run.\n\n It can not be run until SUNWipkg and " + \
671 677 "SUNWipkg-gui have been updated."))
672 678 msgbox.set_title(self._("Update All"))
673 679 result = msgbox.run()
674 680 msgbox.destroy()
675 681 else:
676 682 pkg_list = [ ipkg.get_pkg_stem() for ipkg in \
677 683 self.image_o.gen_installed_pkgs() ]
678 684 installupdate.InstallUpdate({self.image_o:pkg_list}, self, \
679 685 True, False)
680 686
681 687 def __on_help_about(self, widget):
682 688 wTreePlan = gtk.glade.XML(self.gladefile, "aboutdialog")
683 689 aboutdialog = wTreePlan.get_widget("aboutdialog")
684 690 aboutdialog.connect("response", lambda x = None, \
685 691 y = None: aboutdialog.destroy())
686 692 aboutdialog.run()
687 693
688 694 def __on_remove(self, widget):
689 695 remove.Remove(self.application_list, self)
690 696
691 697 def __on_reload(self, widget):
692 698 if self.description_thread_running:
693 699 self.cancelled = True
694 700 self.__catalog_refresh()
695 701 self.process_package_list_start(self.image_directory)
696 702 self.category_list_filter.refilter()
697 703 self.application_list_filter.refilter()
698 704 self.__enable_disable_selection_menus()
699 705 self.update_statusbar()
700 706 self.__update_install_update_button(None, True)
701 707 self.__update_remove_button(None, True)
702 708
703 709 def __clipboard_text_received(self, clipboard, text, data):
704 710 self.main_clipboard_text = text
705 711 return
706 712
707 713 def __main_application_quit(self, restart_app = False):
708 714 '''quits the main gtk loop'''
709 715 self.cancelled = True
710 716 if self.in_setup:
711 717 return
712 718
713 719 if restart_app:
714 720 if "image_dir_arg" in self.__dict__:
715 721 gobject.spawn_async([self.application_path, "-R", \
716 722 self.image_dir_arg])
717 723 else:
718 724 gobject.spawn_async([self.application_path])
719 725 gtk.main_quit()
720 726 sys.exit(0)
721 727 return True
722 728
723 729 def __check_if_something_was_changed(self):
724 730 ''' Returns True if any of the check boxes for package was changed, false
725 731 if not'''
726 732 for pkg in self.application_list:
727 733 if pkg[enumerations.MARK_COLUMN] == True:
728 734 return True
729 735 return False
730 736
731 737 def __setup_repositories_combobox(self, img):
732 738 if self.in_setup or img == None:
733 739 return
734 740
735 741 repositories = img.catalogs
736 742 default_authority = img.get_default_authority()
737 743 self.repositories_list.clear()
738 744 i = 0
739 745 active = 0
740 746 for repo in repositories:
741 747 if cmp(repo, default_authority) == 0:
742 748 active = i
743 749
744 750 self.repositories_list.append([i, repo, ])
745 751 i = i + 1
746 752 if default_authority:
747 753 self.w_repository_combobox.set_active(active)
748 754 else:
749 755 self.w_repository_combobox.set_active(0)
750 756
751 757 def __active_pane_toggle(self, cell, path, model_sort):
752 758 '''Toggle function for column enumerations.MARK_COLUMN'''
753 759 applicationModel = model_sort.get_model()
754 760 applicationPath = model_sort.convert_path_to_child_path(path)
755 761 filterModel = applicationModel.get_model()
756 762 child_path = applicationModel.convert_path_to_child_path(applicationPath)
757 763 itr = filterModel.get_iter(child_path)
758 764 if itr:
759 765 modified = filterModel.get_value(itr, enumerations.MARK_COLUMN)
760 766 filterModel.set_value(itr, enumerations.MARK_COLUMN, \
761 767 not modified)
762 768 latest_available = filterModel.get_value(itr, \
763 769 enumerations.LATEST_AVAILABLE_COLUMN)
764 770 installed_available = filterModel.get_value(itr, \
765 771 enumerations.INSTALLED_VERSION_COLUMN)
766 772 self.update_statusbar()
767 773 self.__update_install_update_button(latest_available, modified)
768 774 self.__update_remove_button(installed_available, modified)
769 775 self.__enable_disable_selection_menus()
770 776
771 777
772 778 def __update_install_update_button(self, latest_available, toggle_true):
773 779 if not toggle_true and self.user_rights:
774 780 if latest_available:
775 781 self.w_installupdate_button.set_sensitive(True)
776 782 self.w_installupdate_menuitem.set_sensitive(True)
777 783 else:
778 784 available = None
779 785 for row in self.application_list:
780 786 if row[enumerations.MARK_COLUMN]:
781 787 available = \
782 788 row[enumerations.LATEST_AVAILABLE_COLUMN]
783 789 if available:
784 790 return
785 791 if not available:
786 792 self.w_installupdate_button.set_sensitive(False)
787 793 self.w_installupdate_menuitem.set_sensitive(False)
788 794
789 795 def __update_reload_button(self):
790 796 if self.user_rights:
791 797 self.w_reload_button.set_sensitive(True)
792 798 else:
793 799 self.w_reload_button.set_sensitive(False)
794 800
795 801 def __update_remove_button(self, installed_available, toggle_true):
796 802 if not toggle_true and self.user_rights:
797 803 if installed_available:
798 804 self.w_remove_button.set_sensitive(True)
799 805 self.w_remove_menuitem.set_sensitive(True)
800 806 else:
801 807 available = None
802 808 for row in self.application_list:
803 809 if row[enumerations.MARK_COLUMN]:
804 810 installed = \
805 811 row[enumerations.INSTALLED_VERSION_COLUMN]
806 812 if installed:
807 813 return
808 814 if not available:
809 815 self.w_remove_button.set_sensitive(False)
810 816 self.w_remove_menuitem.set_sensitive(False)
811 817
812 818 def __update_package_info(self, pkg, icon, installed, manifest):
813 819 if icon and icon != pkg:
814 820 self.w_packageicon_image.set_from_pixbuf(icon)
815 821 else:
816 822 self.w_packageicon_image.set_from_pixbuf( \
817 823 self.__get_pixbuf_from_path("/usr/share/package-manager/", \
818 824 "PM_package_36x"))
819 825 self.w_packagename_label.set_markup("<b>" + pkg.get_name() + "</b>")
820 826 instbuffer = self.w_installedfiles_textview.get_buffer()
821 827 depbuffer = self.w_dependencies_textview.get_buffer()
822 828 infobuffer = self.w_generalinfo_textview.get_buffer()
823 829 if not manifest:
824 830 self.w_shortdescription_label.set_text( \
825 831 self._("Fetching description..."))
826 832 instbuffer.set_text(self._("Fetching information..."))
827 833 depbuffer.set_text(self._("Fetching information..."))
828 834 infobuffer.set_text(self._("Fetching information..."))
829 835 return
830 836 if manifest == "NotAvailable":
831 837 self.w_shortdescription_label.set_text( \
832 838 self._("Description not available for this package..."))
833 839 instbuffer.set_text( \
834 840 self._("Files Details not available for this package..."))
835 841 depbuffer.set_text(self._( \
836 842 "Dependencies info not available for this package..."))
837 843 infobuffer.set_text( \
838 844 self._("Information not available for this package..."))
839 845 return
840 846 self.w_shortdescription_label.set_text(manifest.get("description", ""))
841 847 instbuffer.set_text(self._("Root: %s\n") % manifest.img.get_root())
842 848 depbuffer.set_text(self._("Dependencies:\n"))
843 849 if installed:
844 850 infobuffer.set_text( \
845 851 self._("Information for installed package:\n\n"))
846 852 else:
847 853 infobuffer.set_text( \
848 854 self._("Information for latest available package:\n\n"))
849 855 depiter = depbuffer.get_end_iter()
850 856 institer = instbuffer.get_end_iter()
851 857 infoiter = infobuffer.get_end_iter()
852 858 #Name: SUNWckr
853 859 #FMRI: pkg://opensolaris.org/SUNWckr@0.5.11,5.11-0.75:20071114T203148Z
854 860 #Version: 0.5.11
855 861 #Branch: 0.75
856 862 #Packaging Date: 2007-11-14 20:31:48
857 863 #Size: 29369698
858 864 #Summary: Core Solaris Kernel (Root)
859 865 for a in manifest.actions:
860 866 if cmp(a.name, self.n_("depend")) == 0:
861 867 #Remove "depend: " -> [8:]
862 868 depbuffer.insert(depiter, "\t" + \
863 869 self.__locale_distinguished_name(a)[8:]+"\n")
864 870 elif cmp(a.name,self.n_("dir")) == 0:
865 871 instbuffer.insert(institer, "\t" + \
866 872 self.__locale_distinguished_name(a)+"\n")
867 873 elif cmp(a.name,self.n_("file")) == 0:
868 874 instbuffer.insert(institer, "\t" + \
869 875 self.__locale_distinguished_name(a)+"\n")
870 876 elif cmp(a.name,self.n_("hardlink")) == 0:
871 877 instbuffer.insert(institer, "\t" + \
872 878 self.__locale_distinguished_name(a)+"\n")
873 879 elif cmp(a.name,self.n_("link")) == 0:
874 880 instbuffer.insert(institer, "\t" + \
875 881 self.__locale_distinguished_name(a)+"\n")
876 882 elif cmp(a.name,self.n_("legacy")) == 0:
877 883 if cmp(a.attrlist(self.n_("pkg"))[0], \
878 884 pkg.get_name()) == 0:
879 885 desc = a.attrlist(self.n_("desc"))
880 886 infobuffer.insert(infoiter, \
881 887 self._(" Description:\t%s\n") % desc[0])
882 888 else:
883 889 pass
884 890 infobuffer.insert(infoiter, self._(" Name:\t\t%s\n") % pkg.get_name())
885 891 infobuffer.insert(infoiter, self._(" FMRI:\t\t%s\n") % pkg.get_fmri())
886 892 infobuffer.insert(infoiter, self._(" Version:\t\t%s\n") % \
887 893 pkg.version.get_short_version())
888 894 infobuffer.insert(infoiter, self._(" Packaged:\t%s\n") % \
889 895 self.get_datetime(pkg.version))
890 896
891 897 def __update_description(self, description, package):
892 898 '''workaround function'''
893 899 for pkg in self.application_list:
894 900 p = pkg[enumerations.PACKAGE_OBJECT_COLUMN][0]
895 901 if p == package:
896 902 pkg[enumerations.DESCRIPTION_COLUMN] = description
897 903 return
898 904
899 905 def __show_package_info(self, model, itr):
900 906 img = model.get_value(itr, enumerations.IMAGE_OBJECT_COLUMN)
901 907 pkg = model.get_value(itr, enumerations.INSTALLED_OBJECT_COLUMN)
902 908 icon = model.get_value(itr, enumerations.INSTALLED_OBJECT_COLUMN)
903 909 if not pkg:
904 910 packages = model.get_value(itr, \
905 911 enumerations.PACKAGE_OBJECT_COLUMN)
906 912 pkg = max(packages)
907 913 gobject.idle_add(self.__update_package_info, pkg, icon, False, \
908 914 None)
909 915 else:
910 916 gobject.idle_add(self.__update_package_info, pkg, icon,
911 917 True, None)
912 918 man = None
913 919 try:
914 920 man = img.get_manifest(pkg, filtered = True)
915 921 except IOError:
916 922 man = "NotAvailable"
917 923 if cmp(self.pkginfo_thread, pkg) == 0:
918 924 if not pkg:
919 925 gobject.idle_add(self.__update_package_info, pkg, icon, \
920 926 False, man)
921 927 else:
922 928 gobject.idle_add(self.__update_package_info, pkg, icon, \
923 929 True, man)
924 930 else:
925 931 return
926 932
927 933 # This function is ported from pkg.actions.generic.distinguished_name()
928 934 def __locale_distinguished_name(self, action):
929 935 if action.key_attr == None:
930 936 return str(action)
931 937 return "%s: %s" % \
932 938 (self._(action.name), action.attrs.get(action.key_attr, "???"))
933 939
934 940 def __application_filter(self, model, itr):
935 941 '''This function is used to filter content in the main
936 942 application view'''
937 943 if self.in_setup or self.cancelled:
938 944 return False
939 945 # XXX Show filter, chenge text to integers
940 946 selected_category = 0
941 947 selection = self.w_categories_treeview.get_selection()
942 948 category_model, category_iter = selection.get_selected()
943 949 if not category_iter: #no category was selected, so select "All"
944 950 selection.select_path(0)
945 951 category_model, category_iter = selection.get_selected()
946 952 if category_iter:
947 953 selected_category = category_model.get_value(category_iter, \
948 954 enumerations.CATEGORY_ID)
949 955 category_list_iter = model.get_value(itr, \
950 956 enumerations.CATEGORY_LIST_OBJECT)
951 957 category = False
952 958 repository = self.__is_pkg_repository_visible(model, itr)
953 959 if category_list_iter:
954 960 sel = False
955 961 for category_iter in category_list_iter:
956 962 if category != True:
957 963 category = \
958 964 self.category_filter(self.category_list, \
959 965 category_iter)
960 966 if selected_category != 0:
961 967 if selected_category == \
962 968 self.category_list.get_value(category_iter, \
963 969 enumerations.CATEGORY_ID):
964 970 sel = True
965 971 category = sel
966 972 else:
967 973 if selected_category == 0:
968 974 selected_section = self.w_sections_combobox.get_active()
969 975 if selected_section == 0:
970 976 category = True
971 977 if (model.get_value(itr, enumerations.IS_VISIBLE_COLUMN) == False):
972 978 return False
973 979 if self.w_searchentry_dialog.get_text() == "":
974 980 return (repository & category & \
975 981 self.__is_package_filtered(model, itr))
976 982 if not model.get_value(itr, enumerations.NAME_COLUMN) == None:
977 983 if self.w_searchentry_dialog.get_text().lower() in \
978 984 model.get_value \
979 985 (itr, enumerations.NAME_COLUMN).lower():
980 986 return (repository & category & \
981 987 self.__is_package_filtered(model, itr))
982 988 if not model.get_value(itr, enumerations.DESCRIPTION_COLUMN) == None:
983 989 if self.w_searchentry_dialog.get_text().lower() in \
984 990 model.get_value \
985 991 (itr, enumerations.DESCRIPTION_COLUMN).lower():
986 992 return (repository & category & \
987 993 self.__is_package_filtered(model, itr))
988 994 else:
989 995 return False
990 996
991 997 def __is_package_filtered(self, model, itr):
992 998 '''Function for filtercombobox'''
993 999 # XXX Instead of string comparison, we should do it through integers.
994 1000 # XXX It should be faster and better for localisations.
995 1001 filter_text = self.w_filter_combobox.get_active()
996 1002 if filter_text == 0:
997 1003 return True
998 1004 elif filter_text == 2:
999 1005 return model.get_value(itr, \
1000 1006 enumerations.INSTALLED_VERSION_COLUMN) != None
1001 1007 elif filter_text == 3:
1002 1008 return (model.get_value(itr, \
1003 1009 enumerations.INSTALLED_VERSION_COLUMN) != None) & \
1004 1010 (model.get_value(itr, \
1005 1011 enumerations.LATEST_AVAILABLE_COLUMN) != None)
1006 1012 elif filter_text == 4:
1007 1013 return not model.get_value(itr, \
1008 1014 enumerations.INSTALLED_VERSION_COLUMN) != None
1009 1015 elif filter_text == 6:
1010 1016 return model.get_value(itr, enumerations.MARK_COLUMN)
1011 1017 elif filter_text == 8:
1012 1018 # XXX Locked support
1013 1019 return False
1014 1020
1015 1021
1016 1022 def __is_pkg_repository_visible(self, model, itr):
1017 1023 if len(self.repositories_list) <= 1:
1018 1024 return True
1019 1025 else:
1020 1026 auth_iter = self.w_repository_combobox.get_active_iter()
1021 1027 authority = self.repositories_list.get_value(auth_iter, \
1022 1028 enumerations.REPOSITORY_NAME)
1023 1029 packages = model.get_value(itr, \
1024 1030 enumerations.PACKAGE_OBJECT_COLUMN)
1025 1031 if not packages:
1026 1032 return False
1027 1033 pkg = max(packages)
1028 1034 if cmp(pkg.get_authority(), authority) == 0:
1029 1035 return True
1030 1036 else:
1031 1037 return False
1032 1038
1033 1039 def __do_ips_uptodate_check(self):
1034 1040 self.ips_uptodate = self.__ipkg_ipkgui_uptodate(self.image_o)
1035 1041 self.progress_stop_timer_thread = True
1036 1042
1037 1043 def __ipkg_ipkgui_uptodate(self, img):
1038 1044 if not img.is_liveroot():
1039 1045 newimg = image.Image()
1040 1046 cmdpath = os.path.join(os.getcwd(), sys.argv[0])
1041 1047 cmdpath = os.path.realpath(cmdpath)
1042 1048 cmddir = os.path.dirname(os.path.realpath(cmdpath))
1043 1049 try:
1044 1050 #
1045 1051 # Find the path to ourselves, and use that
1046 1052 # as a way to locate the image we're in. It's
1047 1053 # not perfect-- we could be in a developer's
1048 1054 # workspace, for example.
1049 1055 #
1050 1056 newimg.find_root(cmddir)
1051 1057 except ValueError:
1052 1058 # We can't answer in this case, so we return True to
1053 1059 # let installation proceed.
1054 1060 # TODO: log - msg(_("No image corresponding to '%s' was
1055 1061 # located. " \ "Proceeding.") % cmdpath)
1056 1062 return True
1057 1063 newimg.load_config()
1058 1064 img = newimg
1059 1065
1060 1066 try:
1061 1067 img.retrieve_catalogs()
1062 1068 except RuntimeError:
1063 1069 raise
1064 1070 # Reload catalog. This picks up the update from retrieve_catalogs.
1065 1071 img.load_catalogs(self.pr)
1066 1072
1067 1073 try:
1068 1074 # We will use whatever the incorporation provides as the latest
1069 1075 # version of ipkg and ipkg-gui
1070 1076
1071 1077 img.make_install_plan([self.ipkg_fmri, self.ipkggui_fmri], \
1072 1078 self.pr, filters = [], noexecute = True)
1073 1079 except RuntimeError:
1074 1080 return True
1075 1081
1076 1082 if img.imageplan.nothingtodo():
1077 1083 return True
1078 1084
1079 1085 return False
1080 1086
1081 1087
1082 1088 def __enable_disable_selection_menus(self):
1083 1089
1084 1090 if self.in_setup:
1085 1091 return
1086 1092 self.__enable_disable_select_all()
1087 1093 self.__enable_disable_select_updates()
1088 1094 self.__enable_disable_deselect()
1089 1095 # XXX disabled until new API
1090 1096 self.__enable_disable_update_all()
1091 1097
1092 1098 def __enable_disable_select_all(self):
1093 1099
1094 1100 if self.in_setup:
1095 1101 return
1096 1102 if len(self.w_application_treeview.get_model()) > 0:
1097 1103 for row in self.w_application_treeview.get_model():
1098 1104 if not row[enumerations.MARK_COLUMN]:
1099 1105 self.w_selectall_menuitem.set_sensitive(True)
1100 1106 return
1101 1107 self.w_selectall_menuitem.set_sensitive(False)
1102 1108 else:
1103 1109 self.w_selectall_menuitem.set_sensitive(False)
1104 1110
1105 1111 def __enable_disable_install_update(self):
1106 1112 for row in self.application_list:
1107 1113 if row[enumerations.MARK_COLUMN]:
1108 1114 if row[enumerations.LATEST_AVAILABLE_COLUMN] and \
1109 1115 self.user_rights:
1110 1116 self.w_installupdate_button.set_sensitive(True)
1111 1117 self.w_installupdate_menuitem.set_sensitive(True)
1112 1118 return
1113 1119 self.w_installupdate_button.set_sensitive(False)
1114 1120 self.w_installupdate_menuitem.set_sensitive(False)
1115 1121
1116 1122 def __enable_disable_remove(self):
1117 1123 for row in self.application_list:
1118 1124 if row[enumerations.MARK_COLUMN]:
1119 1125 if row[enumerations.INSTALLED_VERSION_COLUMN] and \
1120 1126 self.user_rights:
1121 1127 self.w_remove_button.set_sensitive(True)
1122 1128 self.w_remove_menuitem.set_sensitive(True)
1123 1129 return
1124 1130 self.w_remove_button.set_sensitive(False)
1125 1131 self.w_remove_menuitem.set_sensitive(False)
1126 1132
1127 1133 def __enable_disable_select_updates(self):
1128 1134 for row in self.w_application_treeview.get_model():
1129 1135 if row[enumerations.INSTALLED_VERSION_COLUMN]:
1130 1136 if row[enumerations.LATEST_AVAILABLE_COLUMN]:
1131 1137 if not row[enumerations.MARK_COLUMN]:
1132 1138 self.w_selectupdates_menuitem. \
1133 1139 set_sensitive(True)
1134 1140 return
1135 1141 self.w_selectupdates_menuitem.set_sensitive(False)
1136 1142 return
1137 1143
1138 1144 def __enable_disable_update_all(self):
1139 1145 for row in self.application_list:
1140 1146 if self.__is_pkg_repository_visible(self.application_list, \
1141 1147 row.iter):
1142 1148 if self.application_list.get_value(row.iter, \
1143 1149 enumerations.INSTALLED_VERSION_COLUMN):
1144 1150 if self.application_list.get_value(row.iter, \
1145 1151 enumerations.LATEST_AVAILABLE_COLUMN) and \
1146 1152 self.user_rights:
1147 1153 self.w_updateall_menuitem. \
1148 1154 set_sensitive(True)
1149 1155 self.w_updateall_button. \
1150 1156 set_sensitive(True)
1151 1157 return
1152 1158 self.w_updateall_button.set_sensitive(False)
1153 1159 self.w_updateall_menuitem.set_sensitive(False)
1154 1160
1155 1161 def __enable_disable_deselect(self):
1156 1162 for row in self.w_application_treeview.get_model():
1157 1163 if row[enumerations.MARK_COLUMN]:
1158 1164 self.w_deselect_menuitem.set_sensitive(True)
1159 1165 return
1160 1166 self.w_deselect_menuitem.set_sensitive(False)
1161 1167 return
1162 1168
1163 1169
1164 1170 def __catalog_refresh(self):
1165 1171 """Update image's catalogs."""
1166 1172 images = self.__get_images_from_model()
1167 1173 full_refresh = False
1168 1174 for img in images:
1169 1175 # Ensure Image directory structure is valid.
1170 1176 if not os.path.isdir("%s/catalog" % img.imgdir):
1171 1177 img.mkdirs()
1172 1178 # Loading catalogs allows us to perform incremental update
1173 1179 img.retrieve_catalogs(full_refresh)
1174 1180
1175 1181 def __get_images_from_model(self):
1176 1182 images = []
1177 1183 for row in self.application_list:
1178 1184 img = row[enumerations.IMAGE_OBJECT_COLUMN]
1179 1185 if img:
1180 1186 if not img in images:
1181 1187 images.append(img)
1182 1188 return images
1183 1189
1184 1190 def __get_image_obj_from_directory(self, image_directory):
1185 1191 image_obj = image.Image()
1186 1192 dr = "/"
1187 1193 try:
1188 1194 image_obj.find_root(image_directory)
1189 1195 image_obj.load_config()
1190 1196 image_obj.load_catalogs(self.pr)
1191 1197 except ValueError:
1192 1198 print self._('%s is not valid image, trying root image') \
1193 1199 % image_directory
1194 1200 try:
1195 1201 dr = os.environ["PKG_IMAGE"]
1196 1202 except KeyError:
1197 1203 print
1198 1204 try:
1199 1205 image_obj.find_root(dr)
1200 1206 image_obj.load_config()
1201 1207 image_obj.load_catalogs(self.pr)
1202 1208 except ValueError:
1203 1209 print self._('%s is not valid root image, return None') \
1204 1210 % dr
1205 1211 image_obj = None
1206 1212 return image_obj
1207 1213
1208 1214
1209 1215
|
↓ open down ↓ |
768 lines elided |
↑ open up ↑ |
1210 1216 def __get_image_from_directory(self, image_obj, progressdialog_progress):
1211 1217 """ This method set up image from the given directory and
1212 1218 returns the image object or None"""
1213 1219 # XXX Convert timestamp to some nice date :)
1214 1220 self.application_list.clear()
1215 1221 self.category_list.clear()
1216 1222 self.application_list_filter.refilter()
1217 1223 pkgs_known = [ pf[0] for pf in
1218 1224 sorted(image_obj.inventory(all_known = True)) ]
1219 1225 #Only one instance of those icons should be in memory
1220 - update_available_icon = self.__get_icon_pixbuf("new_update")
1226 + update_available_icon = self.get_icon_pixbuf("new_update")
1221 1227 #Imageinfo for categories
1222 1228 imginfo = imageinfo.ImageInfo()
1223 1229 sectioninfo = imageinfo.ImageInfo()
1224 1230 catalogs = image_obj.catalogs
1225 1231 categories = {}
1226 1232 sections = {}
1227 1233 self.__setup_repositories_combobox(image_obj)
1228 1234 for cat in catalogs:
1229 1235 category = imginfo.read(self.application_dir + \
1230 1236 "/usr/share/package-manager/data/" + cat)
1231 1237 categories[cat] = category
1232 1238 section = sectioninfo.read(self.application_dir + \
1233 1239 "/usr/share/package-manager/data/" + cat + ".sections")
1234 1240 sections[cat] = section
1235 1241 # Speedup, instead of checking if the pkg is already in the list,
1236 1242 # iterating through all elements, we will only compare to the previous
1237 1243 # package and if the package is the same (version difference) then we
1238 1244 # are adding to the first iterator for the set of those packages.
1239 1245 # We can do that, since the list pkgs_known is sorted
1240 1246 # This will give a sppedup from 18sec to ~3!!!
1241 1247 p_pkg_iter = None
1242 1248 p_pkg = None
1243 1249 insert_count = 0
1244 1250 icon_path = self.application_dir + \
1245 1251 "/usr/share/package-manager/data/pixmaps/"
1246 1252
1247 1253 pkg_count = 0
1248 1254 progress_percent = INITIAL_PROGRESS_TOTAL_PERCENTAGE
1249 1255 total_pkg_count = len(pkgs_known)
1250 1256 progress_increment = \
1251 1257 total_pkg_count / PACKAGE_PROGRESS_TOTAL_INCREMENTS
1252 1258
1253 1259 self.progress_stop_timer_thread = True
1254 1260 while gtk.events_pending():
1255 1261 gtk.main_iteration(False)
1256 1262 for pkg in pkgs_known:
1257 1263 if pkg_count % progress_increment == 0:
1258 1264 progress_percent += PACKAGE_PROGRESS_PERCENT_INCREMENT
1259 1265 if progress_percent <= PACKAGE_PROGRESS_PERCENT_TOTAL:
1260 1266 gobject.idle_add(progressdialog_progress,
1261 1267 progress_percent, pkg_count, total_pkg_count)
1262 1268 while gtk.events_pending():
1263 1269 gtk.main_iteration(False)
1264 1270 pkg_count += 1
1265 1271
1266 1272 #speedup hack, check only last package
1267 1273 already_in_model = \
1268 1274 self.check_if_pkg_have_row_in_model(pkg, p_pkg)
1269 1275 if not already_in_model: #Create new row
1270 1276 available_version = None
1271 1277 version_installed = None
1272 1278 status_icon = None
1273 1279 fmris = [pkg, ]
1274 1280 package_installed = \
1275 1281 self.get_installed_version(image_obj, pkg)
1276 1282 if package_installed:
1277 1283 version_installed = \
1278 1284 package_installed.version.get_short_version()
1279 1285 #HACK, sometimes the package is installed but
1280 1286 #it's not in the pkgs_known
1281 1287 if package_installed != pkg:
1282 1288 fmris.append(package_installed)
1283 1289 else:
1284 1290 dt = self.get_datetime(pkg.version)
1285 1291 dt_str = (":%02d%02d") % (dt.month, dt.day)
1286 1292 available_version = \
1287 1293 pkg.version.get_short_version() + dt_str
1288 1294 package_icon = self.__get_pixbuf_from_path(icon_path, \
1289 1295 pkg.get_name())
1290 1296 app = \
1291 1297 [
1292 1298 False, status_icon, package_icon, pkg.get_name(),
1293 1299 version_installed, package_installed,
1294 1300 available_version, -1, '...', fmris,
1295 1301 image_obj, True, None
1296 1302 ]
1297 1303 # XXX Small hack, if this is not applied, first package
1298 1304 # is listed twice. Insert is ~0.5 sec faster than append
1299 1305 if insert_count == 0:
1300 1306 row_iter = self.application_list.append(app)
1301 1307 else:
1302 1308 row_iter = \
1303 1309 self.application_list.insert(insert_count, \
1304 1310 app)
1305 1311 # XXX Do not iterate through all the catalogs. Package
1306 1312 # should know what is package fmri prefix?
1307 1313 apc = self.__add_package_to_category
1308 1314 for cat in categories:
1309 1315 if cat in categories:
1310 1316 name = pkg.get_name()
1311 1317 if name in categories[cat]:
1312 1318 pkg_categories = \
1313 1319 categories[cat][ \
1314 1320 name]
1315 1321 for pcat in \
1316 1322 pkg_categories.split(","):
1317 1323 if pcat:
1318 1324 apc(self._( \
1319 1325 pcat), None \
1320 1326 , None, \
1321 1327 row_iter)
1322 1328 insert_count = insert_count + 1
1323 1329 p_pkg_iter = row_iter
1324 1330 p_pkg = pkg #The current become previous
1325 1331 else:
1326 1332 # XXX check versions in here. For all installed/not
1327 1333 # installed:
1328 1334 # if there is newer version, put it in the available
1329 1335 # field.
1330 1336 #
1331 1337 # XXXhack, since image_get_version_installed(pkg) is not
1332 1338 # working,as it should. For example package:
1333 1339 # SUNWarc@0.5.11,5.11-0.79:20080205T152309Z
1334 1340 # is not installed and it's newer version of installed
1335 1341 # package:
1336 1342 # SUNWarc@0.5.11,5.11-0.75:20071114T201151Z
1337 1343 # the function returns only proper installed version for
1338 1344 # the older package and None for the newer.
1339 1345 # The hack is a little bit slow since we are iterating
1340 1346 # for all known packages
1341 1347 list_of_pkgs = \
1342 1348 self.application_list.get_value(p_pkg_iter, \
1343 1349 enumerations.PACKAGE_OBJECT_COLUMN)
1344 1350 if pkg not in list_of_pkgs:
1345 1351 list_of_pkgs.append(pkg)
1346 1352 installed = self.application_list.get_value(p_pkg_iter, \
1347 1353 enumerations.INSTALLED_OBJECT_COLUMN)
1348 1354 latest = max(list_of_pkgs)
1349 1355 dt = self.get_datetime(latest.version)
1350 1356 dt_str = (":%02d%02d") % (dt.month, dt.day)
1351 1357 if not installed:
1352 1358 self.application_list.set_value(p_pkg_iter, \
1353 1359 enumerations.LATEST_AVAILABLE_COLUMN, \
1354 1360 latest.version.get_short_version() + \
1355 1361 dt_str)
1356 1362 else:
1357 1363 if installed < latest:
1358 1364 self.application_list.set_value( \
1359 1365 p_pkg_iter, \
1360 1366 enumerations. \
1361 1367 LATEST_AVAILABLE_COLUMN, \
1362 1368 latest.version.get_short_version() + \
1363 1369 dt_str)
1364 1370 self.application_list.set_value(\
1365 1371 p_pkg_iter, \
1366 1372 enumerations.STATUS_ICON_COLUMN, \
1367 1373 update_available_icon)
1368 1374 # XXX How to get descriptions without manifest?
1369 1375 # XXX Downloading manifest is slow and can not work without
1370 1376 # XXX Network connection
1371 1377 #if not image_obj.has_manifest(pkg):
1372 1378 # image_obj.get_manifest(pkg)#verify(pkg, pr)
1373 1379 #installed_version = None
1374 1380 #package_iter = None #the iterator which points for other package
1375 1381 for authority in sections:
1376 1382 for section in sections[authority]:
1377 1383 for category in sections[authority][section].split(","):
1378 1384 self.__add_category_to_section(self._(category), \
1379 1385 self._(section))
1380 1386
1381 1387 #1915 Sort the Categories into alphabetical order and prepend All Category
1382 1388 if len(self.category_list) > 0:
1383 1389 rows = [tuple(r) + (i,) for i, r in enumerate(self.category_list)]
1384 1390 rows.sort(self.__sort)
1385 1391 self.category_list.reorder([r[-1] for r in rows])
1386 1392 self.category_list.prepend([0, self._('All'), None, None, True, None])
1387 1393
1388 1394 gobject.idle_add(progressdialog_progress, PACKAGE_PROGRESS_PERCENT_TOTAL,
1389 1395 pkg_count, total_pkg_count)
1390 1396
1391 1397 def __add_package_to_category(self, category_name, category_description, \
1392 1398 category_icon, package):
1393 1399 if not package or category_name == self._('All'):
1394 1400 return
1395 1401 if not category_name:
1396 1402 return
1397 1403 # XXX check if needed
1398 1404 # category_name = self._('All')
1399 1405 # category_description = self._('All packages')
1400 1406 # category_icon = None
1401 1407 category_ref = None
1402 1408 for category in self.category_list:
1403 1409 if category[enumerations.CATEGORY_NAME] == category_name:
1404 1410 category_ref = category.iter
1405 1411 if not category_ref: # Category not exists
1406 1412 category_ref = self.category_list.append([len( \
1407 1413 self.category_list), category_name, category_description, \
1408 1414 category_icon, True, None])
1409 1415 if category_ref:
1410 1416 if self.application_list.get_value(package, \
1411 1417 enumerations.CATEGORY_LIST_OBJECT):
1412 1418 a = self.application_list.get_value(package, \
1413 1419 enumerations.CATEGORY_LIST_OBJECT)
1414 1420 a.append(category_ref)
1415 1421 else:
1416 1422 category_list = []
1417 1423 category_list.append(category_ref)
1418 1424 self.application_list.set(package, \
1419 1425 enumerations.CATEGORY_LIST_OBJECT, category_list)
1420 1426
1421 1427 def __add_category_to_section(self, category_name, section_name):
1422 1428 '''Adds the section to section list in category. If there is no such
1423 1429 section, than it is not added. If there was already section than it
1424 1430 is skipped. Sections must be case sensitive'''
1425 1431 if not category_name:
1426 1432 return
1427 1433 for section in self.section_list:
1428 1434 if section[enumerations.SECTION_NAME] == section_name:
1429 1435 for category in self.category_list:
1430 1436 if category[enumerations.CATEGORY_NAME] == \
1431 1437 category_name:
1432 1438 if not category[ \
1433 1439 enumerations.SECTION_LIST_OBJECT]:
1434 1440 category[ \
1435 1441 enumerations. \
1436 1442 SECTION_LIST_OBJECT] = \
1437 1443 [section[ \
1438 1444 enumerations.SECTION_ID], ]
1439 1445 else:
|
↓ open down ↓ |
209 lines elided |
↑ open up ↑ |
1440 1446 if not section_name in \
1441 1447 category[ \
1442 1448 enumerations. \
1443 1449 SECTION_LIST_OBJECT]:
1444 1450 category[enumerations. \
1445 1451 SECTION_LIST_OBJECT \
1446 1452 ].append(section[ \
1447 1453 enumerations. \
1448 1454 SECTION_ID])
1449 1455
1450 - def __get_icon_pixbuf(self, icon_name):
1451 - #2821: The __get_icon_pixbuf should use PACKAGE_MANAGER_ROOT
1452 - return self.__get_pixbuf_from_path(self.application_dir + \
1453 - "/usr/share/icons/package-manager/", icon_name)
1454 -
1455 1456 def __get_pixbuf_from_path(self, path, icon_name):
1456 1457 icon = icon_name.replace(' ', '_')
1457 1458
1458 1459 # Performance: Faster to check if files exist rather than catching
1459 1460 # exceptions when they do not. Picked up open failures using dtrace
1460 1461 png_exists = os.path.exists(self.application_dir + path + icon + ".png")
1461 1462 svg_exists = os.path.exists(self.application_dir + path + icon + ".svg")
1462 1463
1463 1464 if not png_exists and not svg_exists:
1464 1465 return None
1465 1466 try:
1466 1467 return gtk.gdk.pixbuf_new_from_file( \
1467 1468 self.application_dir + path + icon + ".png")
1468 1469 except gobject.GError:
1469 1470 try:
1470 1471 return gtk.gdk.pixbuf_new_from_file( \
1471 1472 self.application_dir + path + icon + ".svg")
1472 1473 except gobject.GError:
1473 1474 iconview = gtk.IconView()
1474 1475 icon = iconview.render_icon(getattr(gtk, \
1475 1476 "STOCK_MISSING_IMAGE"), \
1476 1477 size = gtk.ICON_SIZE_MENU,
1477 1478 detail = None)
1478 1479 # XXX Could return image-we don't want to show ugly icon.
1479 1480 return None
1480 1481
1481 1482 def __installed_fmris_from_args(self, img, args):
1482 1483 found = []
1483 1484 notfound = []
1484 1485 try:
1485 1486 for m in img.inventory(args):
1486 1487 found.append(m[0])
1487 1488 except RuntimeError, e:
1488 1489 notfound = e[0]
1489 1490
1490 1491 return found, notfound
1491 1492
1492 1493 def __progressdialog_progress_pulse(self):
1493 1494 while not self.progress_stop_timer_thread:
1494 1495 gobject.idle_add(self.w_progressbar.pulse)
1495 1496 time.sleep(0.1)
1496 1497 gobject.idle_add(self.w_progress_dialog.hide)
1497 1498 self.progress_stop_timer_thread = False
1498 1499
1499 1500 # For initial setup before loading package entries allow 5% of progress bar
1500 1501 # update it on a time base as we have no other way to judge progress at this point
1501 1502 def __progressdialog_progress_time(self):
1502 1503 while not self.progress_stop_timer_thread and \
1503 1504 self.progress_fraction_time_count <= \
1504 1505 INITIAL_PROGRESS_TOTAL_PERCENTAGE:
1505 1506
1506 1507 gobject.idle_add(self.w_progressbar.set_fraction, \
1507 1508 self.progress_fraction_time_count)
1508 1509 self.progress_fraction_time_count += \
1509 1510 INITIAL_PROGRESS_TIME_PERCENTAGE
1510 1511 time.sleep(INITIAL_PROGRESS_TIME_INTERVAL)
1511 1512 self.progress_stop_timer_thread = False
1512 1513 self.progress_fraction_time_count = 0
1513 1514
1514 1515 def __progressdialog_progress_percent(self, fraction, count, total):
1515 1516 gobject.idle_add(self.w_progressinfo_label.set_text, self._( \
1516 1517 "Processing package entries: %d of %d" % (count, total) ))
1517 1518 gobject.idle_add(self.w_progressbar.set_fraction, fraction)
1518 1519
1519 1520 def __setup_data_finished(self):
1520 1521 gobject.idle_add(self.w_progress_dialog.hide)
1521 1522 self.in_setup = False
1522 1523
1523 1524 #-----------------------------------------------------------------------------#
1524 1525 # Static Methods
1525 1526 #-----------------------------------------------------------------------------#
1526 1527
1527 1528 @staticmethod
1528 1529 def n_(message):
1529 1530 return message
1530 1531
1531 1532 @staticmethod
1532 1533 def __sort(a, b):
1533 1534 return cmp(a[1], b[1])
1534 1535
1535 1536 @staticmethod
1536 1537 def cell_data_function(column, renderer, model, itr, data):
1537 1538 '''Function which sets the background colour to black if package is
1538 1539 selected'''
1539 1540 if itr:
1540 1541 if model.get_value(itr, enumerations.MARK_COLUMN):
1541 1542 renderer.set_property("cell-background", "#ffe5cc")
1542 1543 renderer.set_property("cell-background-set", True)
1543 1544 else:
1544 1545 renderer.set_property("cell-background-set", False)
1545 1546
1546 1547 @staticmethod
1547 1548 def combobox_separator(model, itr):
1548 1549 return model.get_value(itr, enumerations.FILTER_NAME) == ""
1549 1550
1550 1551 @staticmethod
1551 1552 def combobox_id_separator(model, itr):
1552 1553 return model.get_value(itr, 0) == -1
1553 1554
1554 1555 @staticmethod
1555 1556 def check_if_pkg_have_row_in_model(pkg, p_pkg):
1556 1557 """Returns True if package is already in model or False if not"""
1557 1558 if p_pkg:
1558 1559 if pkg.is_same_pkg(p_pkg):
1559 1560 return True
1560 1561 else:
1561 1562 return False
1562 1563 return False
1563 1564
1564 1565 @staticmethod
1565 1566 def category_filter(model, itr):
1566 1567 '''This function filters category in the main application view'''
1567 1568 return model.get_value(itr, enumerations.CATEGORY_VISIBLE)
1568 1569
1569 1570 @staticmethod
1570 1571 def get_datetime(version):
1571 1572 dt = None
1572 1573 try:
1573 1574 dt = version.get_datetime()
1574 1575 except AttributeError:
1575 1576 dt = version.get_timestamp()
1576 1577 return dt
1577 1578
1578 1579 @staticmethod
1579 1580 def get_installed_version(img, pkg):
1580 1581 if not img.has_version_installed(pkg):
1581 1582 return None
1582 1583 else:
1583 1584 img_ret = None
1584 1585 try:
1585 1586 img_ret = img.get_version_installed(pkg)
1586 1587 except AttributeError:
1587 1588 img_ret = img._get_version_installed(pkg)
1588 1589 return img_ret
1589 1590
1590 1591 @staticmethod
1591 1592 def get_manifest(img, package, filtered = True):
1592 1593 '''helper function'''
1593 1594 # XXX Should go to the -> imageinfo.py
1594 1595 manifest = None
1595 1596
1596 1597 # 3087 shutdown time is too long when closing down soon after startup
1597 1598 if packagemanager.cancelled:
1598 1599 return manifest
1599 1600 try:
1600 1601 manifest = img.get_manifest(package, filtered)
1601 1602 except OSError:
1602 1603 # XXX It is possible here that the user doesn't have network con,
1603 1604 # XXX proper permissions to save manifest, should we do something
1604 1605 # XXX and popup information dialog?
1605 1606 pass
1606 1607 except NameError:
1607 1608 pass
1608 1609 return manifest
1609 1610
1610 1611 @staticmethod
1611 1612 def update_desc(description, pkg, package):
1612 1613 p = pkg[enumerations.PACKAGE_OBJECT_COLUMN][0]
1613 1614 if p == package:
1614 1615 pkg[enumerations.DESCRIPTION_COLUMN] = description
1615 1616 return
1616 1617
1617 1618 #-----------------------------------------------------------------------------#
1618 1619 # Public Methods
1619 1620 #-----------------------------------------------------------------------------#
1620 1621 def setup_progressdialog_show(self):
1621 1622 self.w_progress_dialog.set_title(self._("Loading Repository Information"))
1622 1623 self.w_progressinfo_label.set_text(
1623 1624 self._( "Fetching package entries ..."))
1624 1625 self.w_progress_cancel.hide()
1625 1626
1626 1627 Thread(target = self.w_progress_dialog.run).start()
1627 1628 Thread(target = self.__progressdialog_progress_time).start()
1628 1629
1629 1630 def init_sections(self):
1630 1631 self.__init_sections() #Initiates sections
1631 1632
1632 1633 def process_package_list_start(self, image_directory):
1633 1634 self.image_directory = image_directory
1634 1635 # Create our image object based on image directory.
1635 1636 image_obj = self.__get_image_obj_from_directory(image_directory)
1636 1637 self.image_o = image_obj
1637 1638
1638 1639 # Acquire image contents and update progress bar as you do so.
1639 1640 self.__get_image_from_directory(image_obj,
1640 1641 self.__progressdialog_progress_percent)
1641 1642 while gtk.events_pending():
1642 1643 gtk.main_iteration(False)
|
↓ open down ↓ |
178 lines elided |
↑ open up ↑ |
1643 1644
1644 1645 def init_package_view(self):
1645 1646 self.__init_show_filter()
1646 1647 self.__setup_data_finished()
1647 1648 self.__init_tree_views()
1648 1649
1649 1650 self.w_filter_combobox.set_active(0)
1650 1651 self.w_sections_combobox.set_active(0)
1651 1652 self.application_list_filter.set_visible_func(self.__application_filter)
1652 1653 self.__setup_repositories_combobox(self.image_o)
1654 +
1655 + def get_icon_pixbuf(self, icon_name):
1656 + #2821: The get_icon_pixbuf should use PACKAGE_MANAGER_ROOT
1657 + return self.__get_pixbuf_from_path(self.application_dir + \
1658 + "/usr/share/icons/package-manager/", icon_name)
1653 1659
1654 1660 def get_manifests_for_packages(self):
1655 1661 ''' Function, which get's manifest for packages. If the manifest is not
1656 1662 locally tries to retrieve it. For installed packages gets manifest
1657 1663 for the particular version (local operation only), if the package is
1658 1664 not installed than the newest one'''
1659 1665 self.description_thread_running = True
1660 1666 for pkg in self.application_list:
1661 1667 if self.cancelled:
1662 1668 self.description_thread_running = False
1663 1669 return
1664 1670 info = None
1665 1671 img = pkg[enumerations.IMAGE_OBJECT_COLUMN]
1666 1672 package = pkg[enumerations.PACKAGE_OBJECT_COLUMN][0]
1667 1673 if (img and package):
1668 1674 version = img.has_version_installed(package)
1669 1675 if version:
1670 1676 version = self.get_installed_version(img, \
1671 1677 package)
1672 1678 man = self.get_manifest(img, version, \
1673 1679 filtered = True)
1674 1680 if man:
1675 1681 info = man.get("description", "")
1676 1682 else:
1677 1683 newest = max( \
1678 1684 pkg[enumerations.PACKAGE_OBJECT_COLUMN])
1679 1685 man = self.get_manifest(img, newest, \
1680 1686 filtered = True)
1681 1687 if man:
1682 1688 info = man.get("description", "")
1683 1689 # XXX workaround, this should be done nicer
1684 1690 gobject.idle_add(self.update_desc, info, pkg, package)
1685 1691 time.sleep(0.01)
1686 1692 self.description_thread_running = False
1687 1693
1688 1694 def update_statusbar(self):
1689 1695 '''Function which updates statusbar'''
1690 1696 installed = 0
1691 1697 selected = 0
1692 1698 broken = 0
1693 1699 for pkg in self.application_list:
1694 1700 if pkg[enumerations.INSTALLED_VERSION_COLUMN]:
1695 1701 installed = installed + 1
1696 1702 if pkg[enumerations.MARK_COLUMN]:
1697 1703 selected = selected + 1
1698 1704 listed_str = self._('%d packages listed') % len(self.application_list)
1699 1705 inst_str = self._('%d installed') % installed
1700 1706 sel_str = self._('%d selected') % selected
1701 1707 broken_str = self._('%d broken') % broken
1702 1708 self.w_main_statusbar.push(0, listed_str + ', ' + inst_str + ', ' + \
1703 1709 sel_str + ', ' + broken_str + '.')
1704 1710
1705 1711
1706 1712 def update_package_list(self):
1707 1713 for row in self.application_list:
1708 1714 if row[enumerations.MARK_COLUMN]:
1709 1715 img = row[enumerations.IMAGE_OBJECT_COLUMN]
1710 1716 pkg = row[enumerations.PACKAGE_OBJECT_COLUMN][0]
1711 1717 package_installed = self.get_installed_version(img, pkg)
1712 1718 version_installed = None
1713 1719 if package_installed:
1714 1720 version_installed = \
1715 1721 package_installed.version.get_short_version()
1716 1722 row[enumerations.MARK_COLUMN] = False
1717 1723 row[enumerations.STATUS_ICON_COLUMN] = None
1718 1724 row[enumerations.INSTALLED_VERSION_COLUMN] = \
1719 1725 version_installed
1720 1726 row[enumerations.INSTALLED_OBJECT_COLUMN] = \
1721 1727 package_installed
1722 1728 if not package_installed:
1723 1729 pkg = max(row[enumerations.PACKAGE_OBJECT_COLUMN])
1724 1730 dt = self.get_datetime(pkg.version)
1725 1731 dt_str = (":%02d%02d") % (dt.month, dt.day)
1726 1732 available_version = \
1727 1733 pkg.version.get_short_version() + dt_str
1728 1734 row[enumerations.LATEST_AVAILABLE_COLUMN] = \
1729 1735 available_version
1730 1736 else:
1731 1737 row[enumerations.LATEST_AVAILABLE_COLUMN] = None
1732 1738 self.w_installupdate_button.set_sensitive(False)
1733 1739 self.w_installupdate_menuitem.set_sensitive(False)
1734 1740 self.w_remove_button.set_sensitive(False)
1735 1741 self.w_remove_menuitem.set_sensitive(False)
1736 1742 self.__enable_disable_selection_menus()
1737 1743 self.update_statusbar()
1738 1744
1739 1745 def shutdown_after_ips_update(self):
1740 1746
1741 1747 # 2790: As IPS and IPS-GUI have been updated the IPS GUI must be shutdown
1742 1748 # and restarted
1743 1749 msgbox = gtk.MessageDialog(parent = self.w_main_window, \
1744 1750 buttons = gtk.BUTTONS_OK, \
1745 1751 flags = gtk.DIALOG_MODAL, type = gtk.MESSAGE_INFO, \
1746 1752 message_format = self._("SUNWipkg and SUNWipkg-gui have been" + \
1747 1753 "updated and Package Manager will now be restarted.\n\nAfter" + \
1748 1754 "restart select Update All to continue."))
1749 1755 msgbox.set_title(self._("Update All"))
1750 1756 msgbox.run()
1751 1757 msgbox.destroy()
1752 1758 self.__main_application_quit(restart_app = True)
1753 1759
1754 1760 def shutdown_after_image_update(self):
1755 1761
1756 1762 msgbox = gtk.MessageDialog(parent = self.w_main_window, \
1757 1763 buttons = gtk.BUTTONS_OK, \
1758 1764 flags = gtk.DIALOG_MODAL, type = gtk.MESSAGE_INFO, \
1759 1765 message_format = self._("Update All has completed and Package" + \
1760 1766 "Manager will now exit.\n\nPlease review posted release notes" + \
1761 1767 "before rebooting:\n\n" + \
1762 1768 " http://opensolaris.org/os/project/indiana/resources/rn3/"))
1763 1769 msgbox.set_title(self._("Update All"))
|
↓ open down ↓ |
101 lines elided |
↑ open up ↑ |
1764 1770 msgbox.run()
1765 1771 msgbox.destroy()
1766 1772 self.__main_application_quit()
1767 1773
1768 1774 ###############################################################################
1769 1775 #-----------------------------------------------------------------------------#
1770 1776 # Test functions
1771 1777 #-----------------------------------------------------------------------------#
1772 1778 def fill_with_fake_data(self):
1773 1779 '''test data for gui'''
1774 - app1 = [False, self.__get_icon_pixbuf("locked"), \
1775 - self.__get_icon_pixbuf("None"), "acc", None, None, None, 4, "desc6", \
1780 + app1 = [False, self.get_icon_pixbuf("locked"), \
1781 + self.get_icon_pixbuf("None"), "acc", None, None, None, 4, "desc6", \
1776 1782 "Object Name1", None, True, None]
1777 - app2 = [False, self.__get_icon_pixbuf("update_available"), \
1778 - self.__get_icon_pixbuf(self._('All')), "acc_gam", \
1783 + app2 = [False, self.get_icon_pixbuf("update_available"), \
1784 + self.get_icon_pixbuf(self._('All')), "acc_gam", \
1779 1785 "2.3", None, "2.8", \
1780 1786 4, "desc7", "Object Name2", None, True, None]
1781 - app3 = [False, self.__get_icon_pixbuf("None"), \
1782 - self.__get_icon_pixbuf("Other"), "gam_grap", "2.3", None, None, 4, \
1787 + app3 = [False, self.get_icon_pixbuf("None"), \
1788 + self.get_icon_pixbuf("Other"), "gam_grap", "2.3", None, None, 4, \
1783 1789 "desc8", "Object Name3", None, True, None]
1784 - app4 = [False, self.__get_icon_pixbuf("update_locked"), \
1785 - self.__get_icon_pixbuf("Office"), "grap_gam", "2.3", None, "2.8", 4, \
1790 + app4 = [False, self.get_icon_pixbuf("update_locked"), \
1791 + self.get_icon_pixbuf("Office"), "grap_gam", "2.3", None, "2.8", 4, \
1786 1792 "desc9", "Object Name2", None, True, None]
1787 - app5 = [False, self.__get_icon_pixbuf("update_available"), \
1788 - self.__get_icon_pixbuf("None"), "grap", "2.3", None, "2.8", 4, \
1793 + app5 = [False, self.get_icon_pixbuf("update_available"), \
1794 + self.get_icon_pixbuf("None"), "grap", "2.3", None, "2.8", 4, \
1789 1795 "desc0", "Object Name3", None, True, None]
1790 1796 itr1 = self.application_list.append(app1)
1791 1797 itr2 = self.application_list.append(app2)
1792 1798 itr3 = self.application_list.append(app3)
1793 1799 itr4 = self.application_list.append(app4)
1794 1800 itr5 = self.application_list.append(app5)
1795 1801 # self.__add_package_to_category(_("All"),None,None,None);
1796 1802 self.__add_package_to_category(self._("Accessories"), None, None, itr1)
1797 1803 self.__add_package_to_category(self._("Accessories"), None, None, itr2)
1798 1804 self.__add_package_to_category(self._("Games"), None, None, itr3)
1799 1805 self.__add_package_to_category(self._("Graphics"), None, None, itr3)
1800 1806 self.__add_package_to_category(self._("Games"), None, None, itr2)
1801 1807 self.__add_package_to_category(self._("Graphics"), None, None, itr4)
1802 1808 self.__add_package_to_category(self._("Games"), None, None, itr4)
1803 1809 self.__add_package_to_category(self._("Graphics"), None, None, itr5)
1804 1810
1805 1811 # Category names until xdg is imported.
1806 1812 # from xdg.DesktopEntry import *
1807 1813 # entry = DesktopEntry ()
1808 1814 # directory = '/usr/share/desktop-directories'
1809 1815 # for root, dirs, files in os.walk (directory):
1810 1816 # for name in files:
1811 1817 # entry.parse (os.path.join (root, name))
1812 1818 # self.__add_category_to_section (entry.getName (), \
1813 1819 # self._('Applications Desktop'))
1814 1820
1815 1821 self.__add_category_to_section(self._("Accessories"), \
1816 1822 self._('Applications Desktop'))
1817 1823 self.__add_category_to_section(self._("Games"), \
1818 1824 self._('Applications Desktop'))
1819 1825 self.__add_category_to_section(self._("Graphics"), \
1820 1826 self._('Applications Desktop'))
1821 1827 self.__add_category_to_section(self._("Internet"), \
1822 1828 self._('Applications Desktop'))
1823 1829 self.__add_category_to_section(self._("Office"), \
1824 1830 self._('Applications Desktop'))
1825 1831 self.__add_category_to_section(self._("Sound & Video"), \
1826 1832 self._('Applications Desktop'))
1827 1833 self.__add_category_to_section(self._("System Tools"), \
1828 1834 self._('Applications Desktop'))
1829 1835 self.__add_category_to_section(self._("Universal Access"), \
1830 1836 self._('Applications Desktop'))
1831 1837 self.__add_category_to_section(self._("Developer Tools"), \
1832 1838 self._('Applications Desktop'))
1833 1839 self.__add_category_to_section(self._("Core"), self._('Operating System'))
1834 1840 self.__add_category_to_section(self._("Graphics"), \
1835 1841 self._('Operating System'))
1836 1842 self.__add_category_to_section(self._("Media"), \
1837 1843 self._('Operating System'))
1838 1844 #Can be twice :)
1839 1845 self.__add_category_to_section(self._("Developer Tools"), \
1840 1846 self._('Operating System'))
1841 1847 self.__add_category_to_section(self._("Office"), "Progs")
1842 1848 self.__add_category_to_section(self._("Office2"), "Progs")
1843 1849 self.__setup_repositories_combobox(self.image_o)
1844 1850 self.in_setup = False
1845 1851
1846 1852 ###############################################################################
1847 1853 #-----------------------------------------------------------------------------#
1848 1854 # Main
1849 1855 #-----------------------------------------------------------------------------#
1850 1856
1851 1857 def main():
1852 1858 gtk.main()
1853 1859 return 0
1854 1860
1855 1861 if __name__ == '__main__':
1856 1862 packagemanager = PackageManager()
1857 1863 passed_test_arg = False
1858 1864 passed_imagedir_arg = False
1859 1865
1860 1866 try:
1861 1867 opts, args = getopt.getopt(sys.argv[1:], "htR:", \
1862 1868 ["help", "test-gui", "image-dir="])
1863 1869 except getopt.error, msg:
1864 1870 print "%s, for help use --help" % msg
1865 1871 sys.exit(2)
1866 1872
1867 1873 cmd = os.path.join(os.getcwd(), sys.argv[0])
1868 1874 cmd = os.path.realpath(cmd)
1869 1875 packagemanager.application_path = cmd
1870 1876
1871 1877 for option, argument in opts:
1872 1878 if option in ("-h", "--help"):
1873 1879 print """\
1874 1880 Use -R (--image-dir) to specify image directory.
1875 1881 Use -t (--test-gui) to work on fake data."""
1876 1882 sys.exit(0)
1877 1883 if option in ("-t", "--test-gui"):
1878 1884 passed_test_arg = True
1879 1885 if option in ("-R", "--image-dir"):
1880 1886 packagemanager.image_dir_arg = argument
1881 1887 image_dir = argument
1882 1888 passed_imagedir_arg = True
1883 1889
1884 1890 if passed_test_arg and passed_imagedir_arg:
1885 1891 print "Options -R and -t can not be used together."
1886 1892 sys.exit(2)
1887 1893 if not passed_imagedir_arg:
1888 1894 try:
1889 1895 image_dir = os.environ["PKG_IMAGE"]
1890 1896 except KeyError:
1891 1897 image_dir = os.getcwd()
1892 1898
1893 1899 if not passed_test_arg:
1894 1900 packagemanager.setup_progressdialog_show()
1895 1901 packagemanager.init_sections()
1896 1902 packagemanager.process_package_list_start(image_dir)
1897 1903 else:
1898 1904 packagemanager.init_sections()
1899 1905 packagemanager.fill_with_fake_data()
1900 1906
1901 1907 packagemanager.init_package_view()
1902 1908 packagemanager.update_statusbar()
1903 1909 while gtk.events_pending():
1904 1910 gtk.main_iteration(False)
1905 1911
1906 1912 # Performance: Start this background thread after progress dialog thread has
1907 1913 # completed in init_package_view()->self.__setup_data_finished() or GUI will block
1908 1914 if not passed_test_arg:
1909 1915 Thread(target = packagemanager.get_manifests_for_packages,
1910 1916 args = ()).start()
1911 1917 main()
|
↓ open down ↓ |
113 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX