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 # 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 MAX_DESC_LEN = 60 # Max length of the description
41 41 MAX_INFO_CACHE_LIMIT = 100 # Max number of package descriptions to cache
42 42
43 43 CLIENT_API_VERSION = 4
44 44 PKG_CLIENT_NAME = "packagemanager"
45 45
46 46 import getopt
47 47 import os
48 48 import sys
49 49 import time
50 50 import locale
51 51 import urlparse
52 52 import socket
53 53 import gettext
54 54 from threading import Thread
55 55 from urllib2 import HTTPError, URLError
56 56
57 57 try:
58 58 import gobject
59 59 import gnome
60 60 gobject.threads_init()
61 61 import gtk
62 62 import gtk.glade
63 63 import pygtk
64 64 pygtk.require("2.0")
65 65 except ImportError:
66 66 sys.exit(1)
67 67 import pkg.client.history as history
68 68 import pkg.client.image as image
69 69 import pkg.client.progress as progress
70 70 import pkg.client.api_errors as api_errors
71 71 import pkg.client.api as api
72 72 import pkg.client.retrieve as retrieve
73 73 import pkg.portable as portable
74 74 import pkg.gui.repository as repository
75 75 import pkg.gui.beadmin as beadm
76 76 import pkg.gui.imageinfo as imageinfo
77 77 import pkg.gui.installupdate as installupdate
78 78 import pkg.gui.enumerations as enumerations
79 79 from pkg.client import global_settings
80 80
81 81 # Put _() in the global namespace
82 82 import __builtin__
83 83 __builtin__._ = gettext.gettext
84 84
85 85 class PackageManager:
86 86 def __init__(self):
87 87 self.api_o = None
88 88 socket.setdefaulttimeout(
89 89 int(os.environ.get("PKG_CLIENT_TIMEOUT", "30"))) # in seconds
90 90
91 91 # Override default PKG_TIMEOUT_MAX if a value has been specified
92 92 # in the environment.
93 93 global_settings.PKG_TIMEOUT_MAX = int(os.environ.get("PKG_TIMEOUT_MAX",
94 94 global_settings.PKG_TIMEOUT_MAX))
95 95
96 96 try:
97 97 self.application_dir = os.environ["PACKAGE_MANAGER_ROOT"]
98 98 except KeyError:
99 99 self.application_dir = "/"
100 100 locale.setlocale(locale.LC_ALL, '')
101 101 for module in (gettext, gtk.glade):
102 102 module.bindtextdomain("pkg", self.application_dir + \
103 103 "/usr/share/locale")
104 104 module.textdomain("pkg")
105 105 # XXX Remove and use _() where self._ and self.parent._ are being used
106 106 self._ = gettext.gettext
107 107 main_window_title = self._('Package Manager')
108 108 self.user_rights = portable.is_admin()
109 109 self.cancelled = False # For background processes
110 110 self.image_directory = None
111 111 self.description_thread_running = False # For background processes
112 112 self.pkginfo_thread = -1 # For background processes
113 113 gtk.rc_parse('~/.gtkrc-1.2-gnome2') # Load gtk theme
114 114 self.main_clipboard_text = None
115 115 self.ipkg_fmri = "SUNWipkg"
116 116 self.ipkggui_fmri = "SUNWipkg-gui"
117 117 self.progress_stop_timer_thread = False
118 118 self.progress_fraction_time_count = 0
119 119 self.progress_canceled = False
120 120 self.ips_uptodate = False
121 121 self.image_dir_arg = None
122 122 self.application_path = None
123 123 self.first_run = True
124 124 self.provided_image_dir = True
125 125 self.selected_pkgname = None
126 126 self.info_cache = {}
127 127
128 128 self.section_list = self.__get_new_section_liststore()
129 129 self.filter_list = self.__get_new_filter_liststore()
130 130 self.application_list = None
131 131 self.category_list = None
132 132 self.repositories_list = None
133 133
134 134 self.pr = progress.NullProgressTracker()
135 135
136 136 # Create Widgets and show gui
137 137
138 138 self.gladefile = self.application_dir + \
139 139 "/usr/share/package-manager/packagemanager.glade"
140 140 w_tree_main = gtk.glade.XML(self.gladefile, "mainwindow")
141 141 w_tree_progress = gtk.glade.XML(self.gladefile, "progressdialog")
142 142
143 143 self.w_main_window = w_tree_main.get_widget("mainwindow")
144 144 self.w_application_treeview = \
145 145 w_tree_main.get_widget("applicationtreeview")
146 146 self.w_categories_treeview = w_tree_main.get_widget("categoriestreeview")
147 147 self.w_info_notebook = w_tree_main.get_widget("notebook1")
148 148 self.w_generalinfo_textview = \
149 149 w_tree_main.get_widget("generalinfotextview")
150 150 self.w_installedfiles_textview = \
151 151 w_tree_main.get_widget("installedfilestextview")
152 152 self.w_license_textview = \
153 153 w_tree_main.get_widget("licensetextview")
154 154 self.w_dependencies_textview = \
155 155 w_tree_main.get_widget("dependenciestextview")
156 156 self.w_packagename_label = w_tree_main.get_widget("packagenamelabel")
157 157 self.w_shortdescription_label = \
158 158 w_tree_main.get_widget("shortdescriptionlabel")
159 159 self.w_searchentry_dialog = w_tree_main.get_widget("searchentry")
160 160 self.w_installupdate_button = \
161 161 w_tree_main.get_widget("install_update_button")
162 162 self.w_remove_button = w_tree_main.get_widget("remove_button")
163 163 self.w_updateall_button = w_tree_main.get_widget("update_all_button")
164 164 self.w_reload_button = w_tree_main.get_widget("reloadbutton")
165 165 self.w_repository_combobox = w_tree_main.get_widget("repositorycombobox")
166 166 self.w_sections_combobox = w_tree_main.get_widget("sectionscombobox")
167 167 self.w_filter_combobox = w_tree_main.get_widget("filtercombobox")
168 168 self.w_packageicon_image = w_tree_main.get_widget("packageimage")
169 169 self.w_main_statusbar = w_tree_main.get_widget("statusbar")
170 170 self.w_installupdate_menuitem = \
171 171 w_tree_main.get_widget("package_install_update")
172 172 self.w_remove_menuitem = w_tree_main.get_widget("package_remove")
173 173 self.w_updateall_menuitem = w_tree_main.get_widget("package_update_all")
174 174 self.w_cut_menuitem = w_tree_main.get_widget("edit_cut")
175 175 self.w_copy_menuitem = w_tree_main.get_widget("edit_copy")
176 176 self.w_paste_menuitem = w_tree_main.get_widget("edit_paste")
177 177 self.w_clear_menuitem = w_tree_main.get_widget("edit_clear")
178 178 self.w_selectall_menuitem = w_tree_main.get_widget("edit_select_all")
179 179 self.w_selectupdates_menuitem = \
180 180 w_tree_main.get_widget("edit_select_updates")
181 181 self.w_deselect_menuitem = w_tree_main.get_widget("edit_deselect")
182 182 self.w_main_clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
183 183
184 184 self.w_progress_dialog = w_tree_progress.get_widget("progressdialog")
185 185 self.w_progress_dialog.set_title(self._("Update All"))
186 186 self.w_progressinfo_label = w_tree_progress.get_widget("progressinfo")
187 187 self.w_progressinfo_label.set_text(self._( \
188 188 "Checking SUNWipkg and SUNWipkg-gui versions\n\nPlease wait ..."))
189 189 self.w_progressbar = w_tree_progress.get_widget("progressbar")
190 190 self.w_progressbar.set_pulse_step(0.1)
191 191 self.w_progress_cancel = w_tree_progress.get_widget("progresscancel")
192 192 self.progress_canceled = False
193 193 clear_search_image = w_tree_main.get_widget("clear_image")
194 194 clear_search_image.set_from_stock(gtk.STOCK_CLEAR, gtk.ICON_SIZE_MENU)
195 195 toolbar = w_tree_main.get_widget("toolbutton2")
196 196 toolbar.set_expand(True)
197 197
198 198 self.__update_reload_button()
199 199 self.w_main_clipboard.request_text(self.__clipboard_text_received)
200 200 self.w_main_window.set_title(main_window_title)
201 201
202 202 try:
203 203 dic_mainwindow = \
204 204 {
205 205 "on_mainwindow_delete_event": \
206 206 self.__on_mainwindow_delete_event,
207 207 "on_searchentry_changed":self.__on_searchentry_changed,
208 208 "on_searchentry_focus_in_event": \
209 209 self.__on_searchentry_focus_in,
210 210 "on_searchentry_focus_out_event": \
211 211 self.__on_searchentry_focus_out,
212 212 "on_searchentry_event":self.__on_searchentry_event,
213 213 "on_sectionscombobox_changed": \
214 214 self.__on_sectionscombobox_changed,
215 215 "on_filtercombobox_changed": \
216 216 self.__on_filtercombobox_changed,
217 217 "on_repositorycombobox_changed": \
218 218 self.__on_repositorycombobox_changed,
219 219 #menu signals
220 220 "on_file_quit_activate":self.__on_file_quit_activate,
221 221 "on_file_be_activate":self.__on_file_be_activate,
222 222 "on_package_install_update_activate": \
223 223 self.__on_install_update,
224 224 "on_settings_edit_repositories_activate": \
225 225 self.__on_edit_repositories_activate,
226 226 "on_package_remove_activate":self.__on_remove,
227 227 "on_help_about_activate":self.__on_help_about,
228 228 "on_help_help_activate":self.__on_help_help,
229 229 "on_edit_paste_activate":self.__on_edit_paste,
230 230 "on_edit_clear_activate":self.__on_clear_paste,
231 231 "on_edit_copy_activate":self.__on_copy,
232 232 "on_edit_cut_activate":self.__on_cut,
233 233 "on_clear_search_clicked":self.__on_clear_search,
234 234 "on_edit_select_all_activate":self.__on_select_all,
235 235 "on_edit_select_updates_activate": \
236 236 self.__on_select_updates,
237 237 "on_edit_deselect_activate":self.__on_deselect,
238 238 # XXX disabled until new API
239 239 "on_package_update_all_activate":self.__on_update_all,
240 240 #toolbar signals
241 241 # XXX disabled until new API
242 242 "on_update_all_button_clicked":self.__on_update_all,
243 243 "on_reload_button_clicked":self.__on_reload,
244 244 "on_install_update_button_clicked": \
245 245 self.__on_install_update,
246 246 "on_remove_button_clicked":self.__on_remove,
247 247 "on_notebook1_switch_page": \
248 248 self.__on_notebook_change,
249 249 }
250 250 dic_progress = \
251 251 {
252 252 "on_cancel_progressdialog_clicked": \
253 253 self.__on_cancel_progressdialog_clicked,
254 254 }
|
↓ open down ↓ |
254 lines elided |
↑ open up ↑ |
255 255 w_tree_main.signal_autoconnect(dic_mainwindow)
256 256 w_tree_progress.signal_autoconnect(dic_progress)
257 257 except AttributeError, error:
258 258 print self._( \
259 259 'GUI will not respond to any event! %s.' + \
260 260 'Check declare_signals()') \
261 261 % error
262 262
263 263 self.package_selection = None
264 264 self.category_list_filter = None
265 - self.application_list_filter = None
265 + self.application_list_filter = None
266 + self.application_refilter_id = 0
266 267 self.in_setup = True
267 268 self.w_main_window.show_all()
268 269
269 270 @staticmethod
270 271 def __get_new_application_liststore():
271 272 return gtk.ListStore(
272 273 gobject.TYPE_BOOLEAN, # enumerations.MARK_COLUMN
273 274 gtk.gdk.Pixbuf, # enumerations.STATUS_ICON_COLUMN
274 275 gtk.gdk.Pixbuf, # enumerations.ICON_COLUMN
275 276 gobject.TYPE_STRING, # enumerations.NAME_COLUMN
276 277 gobject.TYPE_STRING, # enumerations.INSTALLED_VERSION_COLUMN
277 278 gobject.TYPE_PYOBJECT, # enumerations.INSTALLED_OBJECT_COLUMN
278 279 gobject.TYPE_STRING, # enumerations.LATEST_AVAILABLE_COLUMN
279 280 gobject.TYPE_INT, # enumerations.RATING_COLUMN
280 281 gobject.TYPE_STRING, # enumerations.DESCRIPTION_COLUMN
281 282 gobject.TYPE_PYOBJECT, # enumerations.PACKAGE_OBJECT_COLUMN
282 283 gobject.TYPE_BOOLEAN, # enumerations.IS_VISIBLE_COLUMN
283 284 gobject.TYPE_PYOBJECT # enumerations.CATEGORY_LIST_OBJECT
284 285 )
285 286
286 287 @staticmethod
287 288 def __get_new_category_liststore():
288 289 return gtk.ListStore(
289 290 gobject.TYPE_INT, # enumerations.CATEGORY_ID
290 291 gobject.TYPE_STRING, # enumerations.CATEGORY_NAME
291 292 gobject.TYPE_STRING, # enumerations.CATEGORY_DESCRIPTION
292 293 gtk.gdk.Pixbuf, # enumerations.CATEGORY_ICON
293 294 gobject.TYPE_BOOLEAN, # enumerations.CATEGORY_VISIBLE
294 295 gobject.TYPE_PYOBJECT, # enumerations.SECTION_LIST_OBJECT
295 296 )
296 297
297 298 @staticmethod
298 299 def __get_new_section_liststore():
299 300 return gtk.ListStore(
300 301 gobject.TYPE_INT, # enumerations.SECTION_ID
301 302 gobject.TYPE_STRING, # enumerations.SECTION_NAME
302 303 )
303 304
304 305 @staticmethod
305 306 def __get_new_filter_liststore():
306 307 return gtk.ListStore(
307 308 gobject.TYPE_INT, # enumerations.FILTER_ID
308 309 gobject.TYPE_STRING, # enumerations.FILTER_NAME
309 310 )
310 311
311 312 @staticmethod
312 313 def __get_new_repositories_liststore():
313 314 return gtk.ListStore(
314 315 gobject.TYPE_INT, # enumerations.REPOSITORY_ID
315 316 gobject.TYPE_STRING, # enumerations.REPOSITORY_NAME
316 317 )
317 318
318 319 def __init_tree_views(self, application_list, category_list, repositories_list):
319 320 '''This function connects treeviews with their models and also applies
320 321 filters'''
321 322 self.__disconnect_models()
322 323 self.__remove_treeview_columns(self.w_application_treeview)
323 324 self.__remove_treeview_columns(self.w_categories_treeview)
324 325 ##APPLICATION MAIN TREEVIEW
325 326 application_list_filter = application_list.filter_new()
326 327 application_list_sort = \
327 328 gtk.TreeModelSort(application_list_filter)
328 329 application_list_sort.set_sort_column_id(\
329 330 enumerations.NAME_COLUMN, gtk.SORT_ASCENDING)
330 331 application_list_sort.set_sort_func(\
331 332 enumerations.STATUS_ICON_COLUMN, self.__status_sort_func)
332 333 toggle_renderer = gtk.CellRendererToggle()
333 334
334 335 column = gtk.TreeViewColumn("", toggle_renderer, \
335 336 active = enumerations.MARK_COLUMN)
336 337 column.set_sort_column_id(enumerations.MARK_COLUMN)
337 338 column.set_sort_indicator(True)
338 339 column.set_cell_data_func(toggle_renderer, self.cell_data_function, None)
339 340 self.w_application_treeview.append_column(column)
340 341 column = gtk.TreeViewColumn()
341 342 column.set_title("")
342 343 #Commented, since there was funny jumping of the icons
343 344 #column.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
344 345 render_pixbuf = gtk.CellRendererPixbuf()
345 346 column.pack_start(render_pixbuf, expand = False)
346 347 column.add_attribute(render_pixbuf, "pixbuf", enumerations.ICON_COLUMN)
347 348 column.set_fixed_width(32)
348 349 column.set_cell_data_func(render_pixbuf, self.cell_data_function, None)
349 350 self.w_application_treeview.append_column(column)
350 351 name_renderer = gtk.CellRendererText()
351 352 column = gtk.TreeViewColumn(self._("Name"), name_renderer, \
352 353 text = enumerations.NAME_COLUMN)
353 354 column.set_resizable(True)
354 355 column.set_sort_column_id(enumerations.NAME_COLUMN)
355 356 column.set_sort_indicator(True)
356 357 column.set_cell_data_func(name_renderer, self.cell_data_function, None)
357 358 self.w_application_treeview.append_column(column)
358 359 column = gtk.TreeViewColumn()
359 360 column.set_title(self._("Status"))
360 361 #Commented, since there was funny jumping of the icons
361 362 #column.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
362 363 render_pixbuf = gtk.CellRendererPixbuf()
363 364 column.pack_start(render_pixbuf, expand = True)
364 365 column.add_attribute(render_pixbuf, "pixbuf", \
365 366 enumerations.STATUS_ICON_COLUMN)
366 367 column.set_fixed_width(32)
367 368 column.set_sort_column_id(enumerations.STATUS_ICON_COLUMN)
368 369 column.set_sort_indicator(True)
369 370 column.set_cell_data_func(render_pixbuf, self.cell_data_function, None)
370 371 self.w_application_treeview.append_column(column)
371 372 installed_version_renderer = gtk.CellRendererText()
372 373 column = gtk.TreeViewColumn(self._('Installed Version'), \
373 374 installed_version_renderer, \
374 375 text = enumerations.INSTALLED_VERSION_COLUMN)
375 376 column.set_sort_column_id(enumerations.INSTALLED_VERSION_COLUMN)
376 377 column.set_sort_indicator(True)
377 378 column.set_cell_data_func(installed_version_renderer, \
378 379 self.cell_data_function, None)
379 380 latest_available_renderer = gtk.CellRendererText()
380 381 column = gtk.TreeViewColumn(self._('Latest Version'), \
381 382 latest_available_renderer, \
382 383 text = enumerations.LATEST_AVAILABLE_COLUMN)
383 384 column.set_sort_column_id(enumerations.LATEST_AVAILABLE_COLUMN)
384 385 column.set_sort_indicator(True)
385 386 column.set_cell_data_func(latest_available_renderer, \
386 387 self.cell_data_function, None)
387 388 rating_renderer = gtk.CellRendererText()
388 389 column = gtk.TreeViewColumn(self._('Rating'), rating_renderer, \
389 390 text = enumerations.RATING_COLUMN)
390 391 column.set_cell_data_func(rating_renderer, self.cell_data_function, None)
391 392 description_renderer = gtk.CellRendererText()
392 393 column = gtk.TreeViewColumn(self._('Description'), \
393 394 description_renderer, text = enumerations.DESCRIPTION_COLUMN)
394 395 column.set_resizable(True)
395 396 column.set_sort_column_id(enumerations.DESCRIPTION_COLUMN)
396 397 column.set_sort_indicator(True)
397 398 column.set_cell_data_func(description_renderer, \
398 399 self.cell_data_function, None)
399 400 self.w_application_treeview.append_column(column)
400 401 #Added selection listener
401 402 self.package_selection = self.w_application_treeview.get_selection()
402 403
403 404 ##CATEGORIES TREEVIEW
404 405 #enumerations.CATEGORY_NAME
405 406 category_list_filter = category_list.filter_new()
406 407 enumerations.CATEGORY_NAME_renderer = gtk.CellRendererText()
407 408 column = gtk.TreeViewColumn(self._('Name'), \
408 409 enumerations.CATEGORY_NAME_renderer, \
409 410 text = enumerations.CATEGORY_NAME)
410 411 self.w_categories_treeview.append_column(column)
411 412 #Added selection listener
412 413 category_selection = self.w_categories_treeview.get_selection()
413 414 category_selection.set_mode(gtk.SELECTION_SINGLE)
414 415
415 416 if self.first_run:
416 417 ##SECTION COMBOBOX
417 418 #enumerations.SECTION_NAME
418 419 cell = gtk.CellRendererText()
419 420 self.w_sections_combobox.pack_start(cell, True)
420 421 self.w_sections_combobox.add_attribute(cell, 'text', \
421 422 enumerations.SECTION_NAME)
422 423 self.w_sections_combobox.set_row_separator_func( \
423 424 self.combobox_id_separator)
424 425 ##FILTER COMBOBOX
425 426 #enumerations.FILTER_NAME
426 427 cell = gtk.CellRendererText()
427 428 self.w_filter_combobox.pack_start(cell, True)
428 429 self.w_filter_combobox.add_attribute(cell, 'text', \
429 430 enumerations.FILTER_NAME)
430 431 self.w_filter_combobox.set_row_separator_func(\
431 432 self.combobox_id_separator)
432 433 ##FILTER COMBOBOX
433 434 #enumerations.FILTER_NAME
434 435 cell = gtk.CellRendererText()
435 436 self.w_repository_combobox.pack_start(cell, True)
436 437 self.w_repository_combobox.add_attribute(cell, 'text', \
437 438 enumerations.REPOSITORY_NAME)
438 439 self.w_repository_combobox.set_row_separator_func( \
439 440 self.combobox_id_separator)
440 441
441 442 self.application_list = application_list
442 443 self.category_list = category_list
443 444 self.repositories_list = repositories_list
444 445 self.category_list_filter = category_list_filter
445 446 self.application_list_filter = application_list_filter
446 447
447 448 self.w_sections_combobox.set_model(self.section_list)
448 449 self.w_sections_combobox.set_active(0)
449 450 self.w_filter_combobox.set_model(self.filter_list)
450 451 self.w_filter_combobox.set_active(0)
451 452 self.w_repository_combobox.set_model(repositories_list)
452 453 self.w_categories_treeview.set_model(category_list_filter)
453 454 self.w_application_treeview.set_model(application_list_sort)
454 455 application_list_filter.set_visible_func(self.__application_filter)
455 456 category_list_filter.set_visible_func(self.category_filter)
456 457 toggle_renderer.connect('toggled', self.__active_pane_toggle, \
457 458 application_list_sort)
458 459 category_selection.connect("changed", \
459 460 self.__on_category_selection_changed, None)
460 461 self.package_selection.set_mode(gtk.SELECTION_SINGLE)
461 462 self.package_selection.connect("changed", \
462 463 self.__on_package_selection_changed, None)
463 464 self.first_run = False
464 465
465 466 def __disconnect_models(self):
466 467 self.w_application_treeview.set_model(None)
467 468 self.w_categories_treeview.set_model(None)
468 469 self.w_repository_combobox.set_model(None)
469 470 self.w_sections_combobox.set_model(None)
470 471 self.w_filter_combobox.set_model(None)
471 472
472 473 @staticmethod
473 474 def __status_sort_func(treemodel, iter1, iter2, user_data=None):
474 475 get_val = treemodel.get_value
475 476 lat1 = get_val(iter1, enumerations.LATEST_AVAILABLE_COLUMN)
476 477 ins1 = get_val(iter1, enumerations.INSTALLED_VERSION_COLUMN)
477 478 lat2 = get_val(iter2, enumerations.LATEST_AVAILABLE_COLUMN)
478 479 ins2 = get_val(iter2, enumerations.INSTALLED_VERSION_COLUMN)
479 480 if ins1 and not ins2:
480 481 return -1
481 482 if ins2 and not ins1:
482 483 return 1
483 484 if lat1 and not lat2:
484 485 return -1
485 486 if lat2 and not lat1:
486 487 return 1
487 488 return 0
488 489
489 490 @staticmethod
490 491 def __remove_treeview_columns(treeview):
491 492 columns = treeview.get_columns()
492 493 if columns:
493 494 for column in columns:
494 495 treeview.remove_column(column)
495 496
496 497 def __init_sections(self):
497 498 '''This function is for initializing sections combo box, also adds "All"
498 499 Category. It sets active section combobox entry "All"'''
499 500 self.section_list.append([0, self._('All'), ])
500 501 self.section_list.append([-1, "", ])
501 502 self.section_list.append([2, self._('Meta Packages'), ])
502 503 self.section_list.append([3, self._('Applications'), ])
503 504 self.section_list.append([4, self._('Desktop (GNOME)'), ])
504 505 self.section_list.append([5, self._('Development'), ])
505 506 self.section_list.append([6, self._('Distributions'), ])
506 507 self.section_list.append([7, self._('Drivers'), ])
507 508 self.section_list.append([8, self._('System'), ])
508 509 self.section_list.append([9, self._('Web Services'), ])
509 510
510 511 def __init_show_filter(self):
511 512 self.filter_list.append([0, self._('All Packages'), ])
512 513 self.filter_list.append([-1, "", ])
513 514 self.filter_list.append([2, self._('Installed Packages'), ])
514 515 self.filter_list.append([3, self._('Updates'), ])
515 516 self.filter_list.append([4, self._('Non-installed Packages'), ])
516 517 self.filter_list.append([-1, "", ])
517 518 # self.filter_list.append([self._('Locked Packages'), ])
518 519 # self.filter_list.append(["", ])
519 520 self.filter_list.append([6, self._('Selected Packages'), ])
520 521
521 522 def __on_cancel_progressdialog_clicked(self, widget):
522 523 self.progress_canceled = True
523 524 self.progress_stop_timer_thread = True
524 525
525 526 def __on_mainwindow_delete_event(self, widget, event):
526 527 ''' handler for delete event of the main window '''
527 528 if self.__check_if_something_was_changed() == True:
528 529 # XXX Change this to not quit and show dialog
529 530 # XXX if some changes were applied:
530 531 self.__main_application_quit()
531 532 return True
532 533 else:
533 534 self.__main_application_quit()
534 535
535 536 def __on_file_quit_activate(self, widget):
536 537 ''' handler for quit menu event '''
537 538 self.__on_mainwindow_delete_event(None, None)
538 539
|
↓ open down ↓ |
263 lines elided |
↑ open up ↑ |
539 540 def __on_edit_repositories_activate(self, widget):
540 541 ''' handler for repository menu event '''
541 542 repository.Repository(self)
542 543
543 544 def __on_file_be_activate(self, widget):
544 545 ''' handler for be menu event '''
545 546 beadm.Beadmin(self)
546 547
547 548 def __on_searchentry_changed(self, widget):
548 549 '''On text search field changed we should refilter the main view'''
549 - Thread(target = self.__on_searchentry_threaded, args = ()).start()
550 + if self.application_refilter_id != 0:
551 + gobject.source_remove(self.application_refilter_id)
552 + self.application_refilter_id = 0
553 + if self.w_searchentry_dialog.get_text() == "":
554 + self.application_refilter_id = \
555 + gobject.idle_add(self.__application_refilter)
556 + else:
557 + self.application_refilter_id = \
558 + gobject.timeout_add(300, self.__application_refilter)
550 559
551 - def __on_searchentry_threaded(self):
552 - gobject.idle_add(self.application_list_filter.refilter)
560 + def __application_refilter(self):
561 + self.application_list_filter.refilter()
553 562 gobject.idle_add(self.__enable_disable_selection_menus)
563 + gobject.idle_add(self.update_statusbar)
564 + self.application_refilter_id = 0
565 + return False
554 566
555 567 def __on_edit_paste(self, widget):
556 568 self.w_searchentry_dialog.insert_text(self.main_clipboard_text, \
557 569 self.w_searchentry_dialog.get_position())
558 570
559 571 def __on_clear_paste(self, widget):
560 572 bounds = self.w_searchentry_dialog.get_selection_bounds()
561 573 self.w_searchentry_dialog.delete_text(bounds[0], bounds[1])
562 574 return
563 575
564 576 def __on_copy(self, widget):
565 577 bounds = self.w_searchentry_dialog.get_selection_bounds()
566 578 text = self.w_searchentry_dialog.get_chars(bounds[0], bounds[1])
567 579 self.w_main_clipboard.set_text(text)
568 580 return
569 581
570 582 def __on_cut(self, widget):
571 583 bounds = self.w_searchentry_dialog.get_selection_bounds()
572 584 text = self.w_searchentry_dialog.get_chars(bounds[0], bounds[1])
573 585 self.w_searchentry_dialog.delete_text(bounds[0], bounds[1])
574 586 self.w_main_clipboard.set_text(text)
575 587 return
576 588
577 589 def __on_clear_search(self, widget):
578 590 self.w_searchentry_dialog.delete_text(0, -1)
579 591 return
580 592
581 593 def __on_notebook_change(self, widget, event, pagenum):
582 594 if pagenum == 3:
583 595 licbuffer = self.w_license_textview.get_buffer()
584 596 leg_txt = self._("Fetching legal information...")
585 597 licbuffer.set_text(leg_txt)
586 598 Thread(target = self.__show_package_licenses, \
587 599 args = (self.pkginfo_thread,)).start()
588 600
589 601 def __on_select_all(self, widget):
590 602 sort_filt_model = \
591 603 self.w_application_treeview.get_model() #gtk.TreeModelSort
592 604 filt_model = sort_filt_model.get_model() #gtk.TreeModelFilter
593 605 model = filt_model.get_model() #gtk.ListStore
594 606 iter_next = sort_filt_model.get_iter_first()
595 607 list_of_paths = []
596 608 while iter_next != None:
597 609 sorted_path = sort_filt_model.get_path(iter_next)
598 610 filtered_path = \
599 611 sort_filt_model.convert_path_to_child_path(sorted_path)
600 612 path = filt_model.convert_path_to_child_path(filtered_path)
601 613 list_of_paths.append(path)
602 614 iter_next = sort_filt_model.iter_next(iter_next)
603 615 for path in list_of_paths:
604 616 itr = model.get_iter(path)
605 617 model.set_value(itr, enumerations.MARK_COLUMN, True)
606 618 self.__enable_disable_selection_menus()
607 619 self.update_statusbar()
608 620 self.__enable_disable_install_update()
609 621 self.__enable_disable_remove()
610 622
611 623 def __on_select_updates(self, widget):
612 624 sort_filt_model = \
613 625 self.w_application_treeview.get_model() #gtk.TreeModelSort
614 626 filt_model = sort_filt_model.get_model() #gtk.TreeModelFilter
615 627 model = filt_model.get_model() #gtk.ListStore
616 628 iter_next = sort_filt_model.get_iter_first()
617 629 list_of_paths = []
618 630 while iter_next != None:
619 631 sorted_path = sort_filt_model.get_path(iter_next)
620 632 filtered_iter = sort_filt_model.convert_iter_to_child_iter(None, \
621 633 iter_next)
622 634 app_iter = filt_model.convert_iter_to_child_iter(filtered_iter)
623 635
624 636 filtered_path = \
625 637 sort_filt_model.convert_path_to_child_path(sorted_path)
626 638 path = filt_model.convert_path_to_child_path(filtered_path)
627 639 if model.get_value(app_iter, \
628 640 enumerations.INSTALLED_VERSION_COLUMN):
629 641 if model.get_value(app_iter, \
630 642 enumerations.LATEST_AVAILABLE_COLUMN):
631 643 list_of_paths.append(path)
632 644 iter_next = sort_filt_model.iter_next(iter_next)
633 645 for path in list_of_paths:
634 646 itr = model.get_iter(path)
635 647 model.set_value(itr, enumerations.MARK_COLUMN, True)
636 648 self.__enable_disable_selection_menus()
637 649 self.update_statusbar()
638 650 self.__enable_disable_install_update()
639 651 self.__enable_disable_remove()
640 652
641 653 def __on_deselect(self, widget):
642 654 sort_filt_model = \
643 655 self.w_application_treeview.get_model() #gtk.TreeModelSort
644 656 filt_model = sort_filt_model.get_model() #gtk.TreeModelFilter
645 657 model = filt_model.get_model() #gtk.ListStore
646 658 iter_next = sort_filt_model.get_iter_first()
647 659 list_of_paths = []
648 660 while iter_next != None:
649 661 sorted_path = sort_filt_model.get_path(iter_next)
650 662 filtered_iter = sort_filt_model.convert_iter_to_child_iter(None, \
651 663 iter_next)
652 664 app_iter = filt_model.convert_iter_to_child_iter(filtered_iter)
653 665 filtered_path = \
654 666 sort_filt_model.convert_path_to_child_path(sorted_path)
655 667 path = filt_model.convert_path_to_child_path(filtered_path)
656 668 if model.get_value(app_iter, enumerations.MARK_COLUMN):
657 669 list_of_paths.append(path)
658 670 iter_next = sort_filt_model.iter_next(iter_next)
659 671 for path in list_of_paths:
660 672 itr = model.get_iter(path)
661 673 model.set_value(itr, enumerations.MARK_COLUMN, False)
662 674 self.__enable_disable_selection_menus()
663 675 self.update_statusbar()
664 676 self.__enable_disable_install_update()
665 677 self.__enable_disable_remove()
666 678
667 679 def __on_searchentry_focus_in(self, widget, event):
668 680 self.w_paste_menuitem.set_sensitive(True)
669 681
670 682 def __on_searchentry_focus_out(self, widget, event):
671 683 self.w_paste_menuitem.set_sensitive(False)
672 684
673 685 def __on_searchentry_event(self, widget, event):
674 686 self.w_main_clipboard.request_text(self.__clipboard_text_received)
675 687 if widget.get_selection_bounds():
676 688 #enable selection functions
677 689 self.w_cut_menuitem.set_sensitive(True)
678 690 self.w_copy_menuitem.set_sensitive(True)
679 691 self.w_clear_menuitem.set_sensitive(True)
680 692 else:
681 693 self.w_cut_menuitem.set_sensitive(False)
682 694 self.w_copy_menuitem.set_sensitive(False)
683 695 self.w_clear_menuitem.set_sensitive(False)
684 696
685 697 def __on_category_selection_changed(self, selection, widget):
686 698 '''This function is for handling category selection changes'''
687 699 self.application_list_filter.refilter()
688 700 self.__enable_disable_selection_menus()
689 701
690 702 def __on_package_selection_changed(self, selection, widget):
691 703 '''This function is for handling package selection changes'''
692 704 model, itr = selection.get_selected()
693 705 if itr:
694 706 self.pkginfo_thread += 1
695 707 self.selected_pkgname = \
696 708 model.get_value(itr, enumerations.NAME_COLUMN)
697 709 Thread(target = self.__show_package_info, \
698 710 args = (model, itr, self.pkginfo_thread)).start()
699 711 if self.w_info_notebook.get_current_page() == 3:
700 712 self.__on_notebook_change(None, None, 3)
701 713
702 714
703 715 def __on_filtercombobox_changed(self, widget):
704 716 '''On filter combobox changed'''
705 717 if self.in_setup:
706 718 return
707 719 self.application_list_filter.refilter()
708 720 self.__enable_disable_selection_menus()
709 721
710 722 def __on_sectionscombobox_changed(self, widget):
711 723 '''On section combobox changed'''
712 724 if self.in_setup:
713 725 return
714 726 selected_section = widget.get_active()
715 727 if selected_section == 0:
716 728 for category in self.category_list:
717 729 category[enumerations.CATEGORY_VISIBLE] = True
718 730 else:
719 731 for category in self.category_list:
720 732 if category[enumerations.CATEGORY_ID] == 0:
721 733 category[enumerations.CATEGORY_VISIBLE] = True
722 734 else:
723 735 category_list = \
724 736 category[enumerations.SECTION_LIST_OBJECT]
725 737 if not category_list:
726 738 category[enumerations.CATEGORY_VISIBLE] \
727 739 = False
728 740 else:
729 741 for section in category_list:
730 742 if section == selected_section:
731 743 category[enumerations. \
732 744 CATEGORY_VISIBLE] = \
733 745 True
734 746 else:
735 747 category[enumerations. \
736 748 CATEGORY_VISIBLE] = \
737 749 False
738 750 self.category_list_filter.refilter()
739 751 self.application_list_filter.refilter()
740 752 self.__enable_disable_selection_menus()
741 753
742 754 def __on_repositorycombobox_changed(self, widget):
743 755 '''On repository combobox changed'''
744 756 if self.in_setup:
745 757 return
746 758 self.application_list_filter.refilter()
747 759 self.__enable_disable_selection_menus()
748 760
749 761 def __on_install_update(self, widget):
750 762 self.api_o.reset()
751 763 install_update = []
752 764 for row in self.application_list:
753 765 if row[enumerations.MARK_COLUMN]:
754 766 install_update.append(row[\
755 767 enumerations.NAME_COLUMN])
756 768 installupdate.InstallUpdate(install_update, self, \
757 769 self.api_o, ips_update = False, \
758 770 action = enumerations.INSTALL_UPDATE)
759 771
760 772 def __on_update_all(self, widget):
761 773 opensolaris_image = True
762 774 self.progress_stop_timer_thread = False
763 775 notfound = self.__installed_fmris_from_args(self.api_o, \
764 776 ["SUNWipkg", "SUNWcs"])
765 777
766 778 if notfound:
767 779 opensolaris_image = False
768 780
769 781 if opensolaris_image:
770 782 # Load the catalogs from the repository, its a long
771 783 # running tasks so need a progress dialog
772 784 self.w_progress_dialog.set_title(self._("Update All"))
773 785 self.w_progressinfo_label.set_text(self._( \
774 786 "Checking SUNWipkg and SUNWipkg-gui versions\n" \
775 787 "\nPlease wait ..."))
776 788 Thread(target = self.__progressdialog_progress_pulse).start()
777 789 Thread(target = self.__do_ips_uptodate_check).start()
778 790 self.w_progress_dialog.run()
779 791 if self.progress_canceled:
780 792 return
781 793 else:
782 794 self.ips_uptodate = True
783 795
784 796 #2790: Make sure ipkg and ipkg-gui are up to date, if not update them and
785 797 # prompt user to restart
786 798 if not self.ips_uptodate:
787 799 # Prompt user
788 800 msgbox = gtk.MessageDialog(parent = self.w_main_window, \
789 801 buttons = gtk.BUTTONS_YES_NO, \
790 802 flags = gtk.DIALOG_MODAL, type = gtk.MESSAGE_QUESTION, \
791 803 message_format = self._("Newer versions of SUNWipkg and " \
792 804 "SUNWipkg-gui\n" + "are available and must be updated " \
793 805 "before\nrunning Update All.\n\nDo you want to update " \
794 806 "them now?"))
795 807 msgbox.set_title(self._("Update All"))
796 808 result = msgbox.run()
797 809 msgbox.destroy()
798 810 if result == gtk.RESPONSE_YES:
799 811 pkg_list = [self.ipkg_fmri, self.ipkggui_fmri]
800 812 self.api_o.reset()
801 813 installupdate.InstallUpdate(pkg_list, \
802 814 self, self.api_o, \
803 815 ips_update = True, \
804 816 action = enumerations.INSTALL_UPDATE)
805 817 else:
806 818 msgbox = gtk.MessageDialog(parent = self.w_main_window, \
807 819 buttons = gtk.BUTTONS_OK, \
808 820 flags = gtk.DIALOG_MODAL, type = gtk.MESSAGE_INFO, \
809 821 message_format = self._("Update All was not " \
810 822 "run.\n\nIt can not be run until SUNWipkg and " \
811 823 "SUNWipkg-gui have been updated."))
812 824 msgbox.set_title(self._("Update All"))
813 825 result = msgbox.run()
814 826 msgbox.destroy()
815 827 else:
816 828 self.api_o.reset()
817 829 installupdate.InstallUpdate([], self, \
818 830 self.api_o, ips_update = False, \
819 831 action = enumerations.IMAGE_UPDATE)
820 832
821 833 def __on_help_about(self, widget):
822 834 wTreePlan = gtk.glade.XML(self.gladefile, "aboutdialog")
823 835 aboutdialog = wTreePlan.get_widget("aboutdialog")
824 836 aboutdialog.connect("response", lambda x = None, \
825 837 y = None: aboutdialog.destroy())
826 838 aboutdialog.run()
827 839
828 840 def __on_help_help(self, widget):
829 841 props = { gnome.PARAM_APP_DATADIR : self.application_dir + \
830 842 '/usr/share/package-manager/help' }
831 843 gnome.program_init('package-manager', '0.1', properties=props)
832 844 gnome.help_display('package-manager')
833 845
834 846 def __on_remove(self, widget):
835 847 self.api_o.reset()
836 848 remove_list = []
837 849 for pkg in self.application_list:
838 850 if pkg[enumerations.MARK_COLUMN] and \
839 851 pkg[enumerations.INSTALLED_VERSION_COLUMN]:
840 852 remove_list.append(\
841 853 pkg[enumerations.NAME_COLUMN])
842 854 installupdate.InstallUpdate(remove_list, self, \
843 855 self.api_o, ips_update = False, \
844 856 action = enumerations.REMOVE)
845 857
846 858 def __on_reload(self, widget):
847 859 if self.description_thread_running:
848 860 self.cancelled = True
849 861 self.in_setup = True
850 862 self.w_progress_dialog.set_title(self._("Refreshing catalogs"))
851 863 self.w_progressinfo_label.set_text(self._("Refreshing catalogs..."))
852 864 self.progress_stop_timer_thread = False
853 865 Thread(target = self.__progressdialog_progress_pulse).start()
854 866 self.w_progress_dialog.show()
855 867 self.__disconnect_models()
856 868 Thread(target = self.__catalog_refresh).start()
857 869
858 870 def __catalog_refresh_done(self):
859 871 self.progress_stop_timer_thread = True
860 872 #Let the progress_pulse finish. This should be done other way, but at
861 873 #The moment this works fine
862 874 time.sleep(0.2)
863 875 self.process_package_list_start(self.image_directory)
864 876 self.__enable_disable_selection_menus()
865 877 self.update_statusbar()
866 878 self.__update_install_update_button(None, True)
867 879 self.__update_remove_button(None, True)
868 880
869 881 def __clipboard_text_received(self, clipboard, text, data):
870 882 self.main_clipboard_text = text
871 883 return
872 884
873 885 def __main_application_quit(self, restart_app = False):
874 886 '''quits the main gtk loop'''
875 887 self.cancelled = True
876 888 if self.in_setup:
877 889 return
878 890
879 891 if restart_app:
880 892 if self.image_dir_arg:
881 893 gobject.spawn_async([self.application_path, "-R", \
882 894 self.image_dir_arg])
883 895 else:
884 896 gobject.spawn_async([self.application_path])
885 897 gtk.main_quit()
886 898 sys.exit(0)
887 899 return True
888 900
889 901 def __check_if_something_was_changed(self):
890 902 ''' Returns True if any of the check boxes for package was changed, false
891 903 if not'''
892 904 for pkg in self.application_list:
893 905 if pkg[enumerations.MARK_COLUMN] == True:
894 906 return True
895 907 return False
896 908
897 909 def __setup_repositories_combobox(self, api_o, repositories_list):
898 910 img = api_o.img
899 911 if self.in_setup or img == None:
900 912 return
901 913 repositories = img.catalogs
902 914 default_authority = img.get_default_authority()
903 915 i = 0
904 916 active = 0
905 917 for repo in repositories:
906 918 if cmp(repo, default_authority) == 0:
907 919 active = i
908 920
909 921 repositories_list.append([i, repo, ])
910 922 i = i + 1
911 923 self.w_repository_combobox.set_model(repositories_list)
912 924 if default_authority:
913 925 self.w_repository_combobox.set_active(active)
914 926 else:
915 927 self.w_repository_combobox.set_active(0)
916 928
917 929 def __active_pane_toggle(self, cell, path, model_sort):
918 930 '''Toggle function for column enumerations.MARK_COLUMN'''
919 931 applicationModel = model_sort.get_model()
920 932 applicationPath = model_sort.convert_path_to_child_path(path)
921 933 filterModel = applicationModel.get_model()
922 934 child_path = applicationModel.convert_path_to_child_path(applicationPath)
923 935 itr = filterModel.get_iter(child_path)
924 936 if itr:
925 937 modified = filterModel.get_value(itr, enumerations.MARK_COLUMN)
926 938 filterModel.set_value(itr, enumerations.MARK_COLUMN, \
927 939 not modified)
928 940 latest_available = filterModel.get_value(itr, \
929 941 enumerations.LATEST_AVAILABLE_COLUMN)
930 942 installed_available = filterModel.get_value(itr, \
931 943 enumerations.INSTALLED_VERSION_COLUMN)
932 944 self.update_statusbar()
933 945 self.__update_install_update_button(latest_available, modified)
934 946 self.__update_remove_button(installed_available, modified)
935 947 self.__enable_disable_selection_menus()
936 948
937 949
938 950 def __update_install_update_button(self, latest_available, toggle_true):
939 951 if not toggle_true and self.user_rights:
940 952 if latest_available:
941 953 self.w_installupdate_button.set_sensitive(True)
942 954 self.w_installupdate_menuitem.set_sensitive(True)
943 955 else:
944 956 available = None
945 957 for row in self.application_list:
946 958 if row[enumerations.MARK_COLUMN]:
947 959 available = \
948 960 row[enumerations.LATEST_AVAILABLE_COLUMN]
949 961 if available:
950 962 return
951 963 if not available:
952 964 self.w_installupdate_button.set_sensitive(False)
953 965 self.w_installupdate_menuitem.set_sensitive(False)
954 966
955 967 def __update_reload_button(self):
956 968 if self.user_rights:
957 969 self.w_reload_button.set_sensitive(True)
958 970 else:
959 971 self.w_reload_button.set_sensitive(False)
960 972
961 973 def __update_remove_button(self, installed_available, toggle_true):
962 974 if not toggle_true and self.user_rights:
963 975 if installed_available:
964 976 self.w_remove_button.set_sensitive(True)
965 977 self.w_remove_menuitem.set_sensitive(True)
966 978 else:
967 979 available = None
968 980 for row in self.application_list:
969 981 if row[enumerations.MARK_COLUMN]:
970 982 installed = \
971 983 row[enumerations.INSTALLED_VERSION_COLUMN]
972 984 if installed:
973 985 return
974 986 if not available:
975 987 self.w_remove_button.set_sensitive(False)
976 988 self.w_remove_menuitem.set_sensitive(False)
977 989
978 990 def __show_fetching_package_info(self, pkg, icon):
979 991 pkg_name = pkg.get_name()
980 992 if icon and icon != pkg:
981 993 self.w_packageicon_image.set_from_pixbuf(icon)
982 994 else:
983 995 self.w_packageicon_image.set_from_pixbuf( \
984 996 self.__get_pixbuf_from_path("/usr/share/package-manager/", \
985 997 "PM_package_36x"))
986 998 self.w_packagename_label.set_markup("<b>" + pkg_name + "</b>")
987 999
988 1000 if self.__setting_from_cache(pkg_name):
989 1001 return
990 1002
991 1003 self.w_shortdescription_label.set_text( \
992 1004 self._("Fetching description..."))
993 1005 instbuffer = self.w_installedfiles_textview.get_buffer()
994 1006 depbuffer = self.w_dependencies_textview.get_buffer()
995 1007 infobuffer = self.w_generalinfo_textview.get_buffer()
996 1008 instbuffer.set_text(self._("Fetching information..."))
997 1009 depbuffer.set_text(self._("Fetching information..."))
998 1010 infobuffer.set_text(self._("Fetching information..."))
999 1011 return
1000 1012
1001 1013 def __setting_from_cache(self, pkg_name):
1002 1014 if len(self.info_cache) > MAX_INFO_CACHE_LIMIT:
1003 1015 self.info_cache = {}
1004 1016
1005 1017 if self.info_cache.has_key(pkg_name):
1006 1018 self.w_shortdescription_label.set_text(\
1007 1019 self.info_cache[pkg_name][0])
1008 1020 instbuffer = self.w_installedfiles_textview.get_buffer()
1009 1021 depbuffer = self.w_dependencies_textview.get_buffer()
1010 1022 infobuffer = self.w_generalinfo_textview.get_buffer()
1011 1023 infobuffer.set_text(self.info_cache[pkg_name][1])
1012 1024 instbuffer.set_text(self.info_cache[pkg_name][2])
1013 1025 depbuffer.set_text(self.info_cache[pkg_name][3])
1014 1026 return True
1015 1027 else:
1016 1028 return False
1017 1029
1018 1030 def __update_package_info(self, pkg, icon, installed, pkg_info):
1019 1031 pkg_name = pkg.get_name()
1020 1032 if icon and icon != pkg:
1021 1033 self.w_packageicon_image.set_from_pixbuf(icon)
1022 1034 else:
1023 1035 self.w_packageicon_image.set_from_pixbuf( \
1024 1036 self.__get_pixbuf_from_path("/usr/share/package-manager/", \
1025 1037 "PM_package_36x"))
1026 1038 self.w_packagename_label.set_markup("<b>" + pkg_name + "</b>")
1027 1039
1028 1040 if self.__setting_from_cache(pkg_name):
1029 1041 return
1030 1042
1031 1043 instbuffer = self.w_installedfiles_textview.get_buffer()
1032 1044 depbuffer = self.w_dependencies_textview.get_buffer()
1033 1045 infobuffer = self.w_generalinfo_textview.get_buffer()
1034 1046
1035 1047 if not pkg_info:
1036 1048 self.w_shortdescription_label.set_text( \
1037 1049 self._("Description not available for this package..."))
1038 1050 instbuffer.set_text( \
1039 1051 self._("Files Details not available for this package..."))
1040 1052 depbuffer.set_text(self._( \
1041 1053 "Dependencies info not available for this package..."))
1042 1054 infobuffer.set_text( \
1043 1055 self._("Information not available for this package..."))
1044 1056 return
1045 1057 description = pkg_info.summary
1046 1058 #XXX long term need to have something more robust here for multi byte
1047 1059 if len(description) > MAX_DESC_LEN:
1048 1060 description = description[:MAX_DESC_LEN] + " ..."
1049 1061 self.w_shortdescription_label.set_text(description)
1050 1062 inst_str = self._("Root: %s\n") % self.api_o.img.get_root()
1051 1063 dep_str = self._("Dependencies:\n")
1052 1064
1053 1065 if installed:
1054 1066 info_str = self._("Information for installed package:\n\n")
1055 1067 else:
1056 1068 info_str = self._("Information for latest available package:\n\n")
1057 1069 #Name: SUNWckr
1058 1070 #FMRI: pkg://opensolaris.org/SUNWckr@0.5.11,5.11-0.75:20071114T203148Z
1059 1071 #Version: 0.5.11
1060 1072 #Branch: 0.75
1061 1073 #Packaging Date: 2007-11-14 20:31:48
1062 1074 #Size: 293696981024
1063 1075 #Summary: Core Solaris Kernel (Root)
1064 1076
1065 1077 if pkg_info.dependencies:
1066 1078 dep_str += ''.join(["\t%s\n" % x for x in pkg_info.dependencies])
1067 1079 if pkg_info.dirs:
1068 1080 inst_str += ''.join(["\t%s\n" % x for x in pkg_info.dirs])
1069 1081 if pkg_info.files:
1070 1082 inst_str += ''.join(["\t%s\n" % x for x in pkg_info.files])
1071 1083 if pkg_info.hardlinks:
1072 1084 inst_str += ''.join(["\t%s\n" % x for x in pkg_info.hardlinks])
1073 1085 if pkg_info.links:
1074 1086 inst_str += ''.join(["\t%s\n" % x for x in pkg_info.links])
1075 1087
1076 1088 if description:
1077 1089 info_str += self._(" Description:\t%s\n") % description
1078 1090 info_str += self._(" Name:\t\t%s\n") % pkg_name
1079 1091 info_str += self._(" FMRI:\t\t%s\n") % pkg.get_fmri()
1080 1092 info_str += self._(" Version:\t\t%s\n") % \
1081 1093 pkg.version.get_short_version()
1082 1094 info_str += self._(" Packaged:\t%s\n") % \
1083 1095 self.get_datetime(pkg.version)
1084 1096
1085 1097 infobuffer.set_text(info_str)
1086 1098 instbuffer.set_text(inst_str)
1087 1099 depbuffer.set_text(dep_str)
1088 1100
1089 1101 self.info_cache[pkg_name] = \
1090 1102 (description, info_str, inst_str, dep_str)
1091 1103
1092 1104 def __update_package_license(self, licenses):
1093 1105 lic = ""
1094 1106 lic_u = ""
1095 1107 if licenses == None:
1096 1108 lic_u = self._("Not available")
1097 1109 else:
1098 1110 for licens in licenses:
1099 1111 lic += licens.get_text()
1100 1112 lic += "\n"
1101 1113 try:
1102 1114 lic_u = unicode(lic, "utf-8")
1103 1115 except UnicodeDecodeError:
1104 1116 lic_u += ""
1105 1117 licbuffer = self.w_license_textview.get_buffer()
1106 1118 licbuffer.set_text(lic_u)
1107 1119
1108 1120 def __update_description(self, description, package):
1109 1121 '''workaround function'''
1110 1122 for pkg in self.application_list:
1111 1123 p = pkg[enumerations.PACKAGE_OBJECT_COLUMN][0]
1112 1124 if p == package:
1113 1125 pkg[enumerations.DESCRIPTION_COLUMN] = description
1114 1126 return
1115 1127
1116 1128 def __show_package_licenses(self, th_no):
1117 1129 #XXX revisit this and replace with gobject.timer_add() instead of sleep
1118 1130 # sleep for a little time, this is done for the users who are
1119 1131 # fast browsing the list of the packages.
1120 1132 time.sleep(1)
1121 1133 if th_no != self.pkginfo_thread:
1122 1134 return
1123 1135 if self.selected_pkgname == None:
1124 1136 gobject.idle_add(self.__update_package_license, \
1125 1137 None)
1126 1138 return
1127 1139 info = self.api_o.info([self.selected_pkgname], True, True)
1128 1140 pkgs_info = None
1129 1141 package_info = None
1130 1142 no_licenses = 0
1131 1143 if info:
1132 1144 pkgs_info = info[0]
1133 1145 if pkgs_info:
1134 1146 package_info = pkgs_info[0]
1135 1147 if package_info:
1136 1148 no_licenses = len(package_info.licenses)
1137 1149 if no_licenses == 0:
1138 1150 gobject.idle_add(self.__update_package_license, \
1139 1151 None)
1140 1152 return
1141 1153 if th_no == self.pkginfo_thread:
1142 1154 gobject.idle_add(self.__update_package_license, \
1143 1155 package_info.licenses)
1144 1156 else:
1145 1157 return
1146 1158
1147 1159 def __get_pkg_info(self, pkg_name, installed):
1148 1160 info = self.api_o.info([pkg_name], installed, get_licenses=False, \
1149 1161 get_action_info=True)
1150 1162 pkgs_info = None
1151 1163 package_info = None
1152 1164 if info:
1153 1165 pkgs_info = info[0]
1154 1166 if pkgs_info:
1155 1167 package_info = pkgs_info[0]
1156 1168 if package_info:
1157 1169 return package_info
1158 1170 else:
1159 1171 return
1160 1172
1161 1173 def __show_package_info(self, model, itr, th_no):
1162 1174 pkg = model.get_value(itr, enumerations.INSTALLED_OBJECT_COLUMN)
1163 1175 icon = model.get_value(itr, enumerations.INSTALLED_OBJECT_COLUMN)
1164 1176 installed = False
1165 1177 if not pkg:
1166 1178 packages = model.get_value(itr, \
1167 1179 enumerations.PACKAGE_OBJECT_COLUMN)
1168 1180 pkg = max(packages)
1169 1181 gobject.idle_add( \
1170 1182 self.__show_fetching_package_info, pkg, icon)
1171 1183 else:
1172 1184 gobject.idle_add( \
1173 1185 self.__show_fetching_package_info, pkg, icon)
1174 1186 installed = True
1175 1187
1176 1188 if self.info_cache.has_key(pkg.get_name()):
1177 1189 return
1178 1190
1179 1191 # sleep for a little time, this is done for the users which are
1180 1192 # fast browsing the list of the packages.
1181 1193 time.sleep(1)
1182 1194 if th_no != self.pkginfo_thread:
1183 1195 return
1184 1196 man = None
1185 1197 img = self.api_o.img
1186 1198 img.history.operation_name = "info"
1187 1199
1188 1200 pkg_info = self.__get_pkg_info(pkg.get_name(), installed)
1189 1201 if th_no == self.pkginfo_thread:
1190 1202 if not pkg:
1191 1203 gobject.idle_add(self.__update_package_info, pkg, icon, \
1192 1204 installed, pkg_info)
1193 1205 else:
1194 1206 gobject.idle_add(self.__update_package_info, pkg, icon, \
1195 1207 installed, pkg_info)
1196 1208 img.history.operation_result = \
1197 1209 history.RESULT_SUCCEEDED
1198 1210 else:
1199 1211 img.history.operation_result = \
1200 1212 history.RESULT_SUCCEEDED
1201 1213 return
1202 1214
1203 1215 # This function is ported from pkg.actions.generic.distinguished_name()
1204 1216 def __locale_distinguished_name(self, action):
1205 1217 if action.key_attr == None:
1206 1218 return str(action)
1207 1219 return "%s: %s" % \
1208 1220 (self._(action.name), action.attrs.get(action.key_attr, "???"))
1209 1221
1210 1222 def __application_filter(self, model, itr):
1211 1223 '''This function is used to filter content in the main
1212 1224 application view'''
1213 1225 if self.in_setup or self.cancelled:
1214 1226 return False
1215 1227 # XXX Show filter, chenge text to integers
1216 1228 selected_category = 0
1217 1229 selection = self.w_categories_treeview.get_selection()
1218 1230 category_model, category_iter = selection.get_selected()
1219 1231 if not category_iter: #no category was selected, so select "All"
1220 1232 selection.select_path(0)
1221 1233 category_model, category_iter = selection.get_selected()
1222 1234 if category_iter:
1223 1235 selected_category = category_model.get_value(category_iter, \
1224 1236 enumerations.CATEGORY_ID)
1225 1237 category_list_iter = model.get_value(itr, \
1226 1238 enumerations.CATEGORY_LIST_OBJECT)
1227 1239 category = False
1228 1240 repo = self.__is_pkg_repository_visible(model, itr)
1229 1241 if category_list_iter:
1230 1242 sel = False
1231 1243 for category_iter in category_list_iter:
1232 1244 if category != True:
1233 1245 category = \
1234 1246 self.category_filter(self.category_list, \
1235 1247 category_iter)
1236 1248 if selected_category != 0:
1237 1249 if selected_category == \
1238 1250 self.category_list.get_value(category_iter, \
1239 1251 enumerations.CATEGORY_ID):
1240 1252 sel = True
1241 1253 category = sel
1242 1254 else:
1243 1255 if selected_category == 0:
1244 1256 selected_section = self.w_sections_combobox.get_active()
1245 1257 if selected_section == 0:
1246 1258 category = True
1247 1259 if (model.get_value(itr, enumerations.IS_VISIBLE_COLUMN) == False):
1248 1260 return False
1249 1261 if self.w_searchentry_dialog.get_text() == "":
1250 1262 return (repo & category & \
1251 1263 self.__is_package_filtered(model, itr))
1252 1264 if not model.get_value(itr, enumerations.NAME_COLUMN) == None:
1253 1265 if self.w_searchentry_dialog.get_text().lower() in \
1254 1266 model.get_value \
1255 1267 (itr, enumerations.NAME_COLUMN).lower():
1256 1268 return (repo & category & \
1257 1269 self.__is_package_filtered(model, itr))
1258 1270 if not model.get_value(itr, enumerations.DESCRIPTION_COLUMN) == None:
1259 1271 if self.w_searchentry_dialog.get_text().lower() in \
1260 1272 model.get_value \
1261 1273 (itr, enumerations.DESCRIPTION_COLUMN).lower():
1262 1274 return (repo & category & \
1263 1275 self.__is_package_filtered(model, itr))
1264 1276 else:
1265 1277 return False
1266 1278
1267 1279 def __is_package_filtered(self, model, itr):
1268 1280 '''Function for filtercombobox'''
1269 1281 # XXX Instead of string comparison, we should do it through integers.
1270 1282 # XXX It should be faster and better for localisations.
1271 1283 filter_text = self.w_filter_combobox.get_active()
1272 1284 if filter_text == 0:
1273 1285 return True
1274 1286 elif filter_text == 2:
1275 1287 return model.get_value(itr, \
1276 1288 enumerations.INSTALLED_VERSION_COLUMN) != None
1277 1289 elif filter_text == 3:
1278 1290 return (model.get_value(itr, \
1279 1291 enumerations.INSTALLED_VERSION_COLUMN) != None) & \
1280 1292 (model.get_value(itr, \
1281 1293 enumerations.LATEST_AVAILABLE_COLUMN) != None)
1282 1294 elif filter_text == 4:
1283 1295 return not model.get_value(itr, \
1284 1296 enumerations.INSTALLED_VERSION_COLUMN) != None
1285 1297 elif filter_text == 6:
1286 1298 return model.get_value(itr, enumerations.MARK_COLUMN)
1287 1299 elif filter_text == 8:
1288 1300 # XXX Locked support
1289 1301 return False
1290 1302
1291 1303
1292 1304 def __is_pkg_repository_visible(self, model, itr):
1293 1305 if len(self.repositories_list) <= 1:
1294 1306 return True
1295 1307 else:
1296 1308 auth_iter = self.w_repository_combobox.get_active_iter()
1297 1309 authority = self.repositories_list.get_value(auth_iter, \
1298 1310 enumerations.REPOSITORY_NAME)
1299 1311 packages = model.get_value(itr, \
1300 1312 enumerations.PACKAGE_OBJECT_COLUMN)
1301 1313 if not packages:
1302 1314 return False
1303 1315 pkg = max(packages)
1304 1316 if cmp(pkg.get_authority(), authority) == 0:
1305 1317 return True
1306 1318 else:
1307 1319 return False
1308 1320
1309 1321 def __do_ips_uptodate_check(self):
1310 1322 ret = self.__catalog_refresh(False)
1311 1323 if ret != -1:
1312 1324 self.ips_uptodate = self.__ipkg_ipkgui_uptodate()
1313 1325 else:
1314 1326 self.progress_canceled = True
1315 1327 self.progress_stop_timer_thread = True
1316 1328
1317 1329 def __ipkg_ipkgui_uptodate(self):
1318 1330 self.api_o.reset()
1319 1331 list_of_packages = [self.ipkg_fmri, self.ipkggui_fmri]
1320 1332 ret = True
1321 1333 try:
1322 1334 upgrade_needed, cre = self.api_o.plan_install(
1323 1335 list_of_packages, filters = [])
1324 1336 if upgrade_needed:
1325 1337 ret = False
1326 1338 except (api_errors.InvalidCertException, \
1327 1339 api_errors.PlanCreationException, \
1328 1340 api_errors.InventoryException):
1329 1341 raise
1330 1342 except api_errors.CanceledException:
1331 1343 raise
1332 1344 return ret
1333 1345
1334 1346 def __enable_disable_selection_menus(self):
1335 1347
1336 1348 if self.in_setup:
1337 1349 return
1338 1350 self.__enable_disable_select_all()
1339 1351 self.__enable_disable_select_updates()
1340 1352 self.__enable_disable_deselect()
1341 1353 # XXX disabled until new API
1342 1354 self.__enable_disable_update_all()
1343 1355
1344 1356 def __enable_disable_select_all(self):
1345 1357
1346 1358 if self.in_setup:
1347 1359 return
1348 1360 if len(self.w_application_treeview.get_model()) > 0:
1349 1361 for row in self.w_application_treeview.get_model():
1350 1362 if not row[enumerations.MARK_COLUMN]:
1351 1363 self.w_selectall_menuitem.set_sensitive(True)
1352 1364 return
1353 1365 self.w_selectall_menuitem.set_sensitive(False)
1354 1366 else:
1355 1367 self.w_selectall_menuitem.set_sensitive(False)
1356 1368
1357 1369 def __enable_disable_install_update(self):
1358 1370 for row in self.application_list:
1359 1371 if row[enumerations.MARK_COLUMN]:
1360 1372 if row[enumerations.LATEST_AVAILABLE_COLUMN] and \
1361 1373 self.user_rights:
1362 1374 self.w_installupdate_button.set_sensitive(True)
1363 1375 self.w_installupdate_menuitem.set_sensitive(True)
1364 1376 return
1365 1377 self.w_installupdate_button.set_sensitive(False)
1366 1378 self.w_installupdate_menuitem.set_sensitive(False)
1367 1379
1368 1380 def __enable_disable_remove(self):
1369 1381 for row in self.application_list:
1370 1382 if row[enumerations.MARK_COLUMN]:
1371 1383 if row[enumerations.INSTALLED_VERSION_COLUMN] and \
1372 1384 self.user_rights:
1373 1385 self.w_remove_button.set_sensitive(True)
1374 1386 self.w_remove_menuitem.set_sensitive(True)
1375 1387 return
1376 1388 self.w_remove_button.set_sensitive(False)
1377 1389 self.w_remove_menuitem.set_sensitive(False)
1378 1390
1379 1391 def __enable_disable_select_updates(self):
1380 1392 for row in self.w_application_treeview.get_model():
1381 1393 if row[enumerations.INSTALLED_VERSION_COLUMN]:
1382 1394 if row[enumerations.LATEST_AVAILABLE_COLUMN]:
1383 1395 if not row[enumerations.MARK_COLUMN]:
1384 1396 self.w_selectupdates_menuitem. \
1385 1397 set_sensitive(True)
1386 1398 return
1387 1399 self.w_selectupdates_menuitem.set_sensitive(False)
1388 1400 return
1389 1401
1390 1402 def __enable_disable_update_all(self):
1391 1403 for row in self.application_list:
1392 1404 if self.__is_pkg_repository_visible(self.application_list, \
1393 1405 row.iter):
1394 1406 if self.application_list.get_value(row.iter, \
1395 1407 enumerations.INSTALLED_VERSION_COLUMN):
1396 1408 if self.application_list.get_value(row.iter, \
1397 1409 enumerations.LATEST_AVAILABLE_COLUMN) and \
1398 1410 self.user_rights:
1399 1411 self.w_updateall_menuitem. \
1400 1412 set_sensitive(True)
1401 1413 self.w_updateall_button. \
1402 1414 set_sensitive(True)
1403 1415 return
1404 1416 self.w_updateall_button.set_sensitive(False)
1405 1417 self.w_updateall_menuitem.set_sensitive(False)
1406 1418
1407 1419 def __enable_disable_deselect(self):
1408 1420 for row in self.w_application_treeview.get_model():
1409 1421 if row[enumerations.MARK_COLUMN]:
1410 1422 self.w_deselect_menuitem.set_sensitive(True)
1411 1423 return
1412 1424 self.w_deselect_menuitem.set_sensitive(False)
1413 1425 return
1414 1426
1415 1427
1416 1428 def __catalog_refresh(self, reload_gui=True):
1417 1429 """Update image's catalogs."""
1418 1430 full_refresh = True
1419 1431 try:
1420 1432 self.api_o.refresh(full_refresh)
1421 1433 self.api_o.img.load_catalogs(self.pr)
1422 1434 except api_errors.UnrecognizedAuthorityException:
1423 1435 # In current implementation, this will never happen
1424 1436 # We are not refrehsing specific authority
1425 1437 self.__catalog_refresh_done()
1426 1438 raise
1427 1439 except api_errors.CatalogRefreshException, cre:
1428 1440 total = cre.total
1429 1441 succeeded = cre.succeeded
1430 1442 ermsg = self._("Network problem.\n\n")
1431 1443 ermsg += self._("Details:\n")
1432 1444 ermsg += "%s/%s" % (succeeded, total)
1433 1445 ermsg += self._(" catalogs successfully updated:\n")
1434 1446 for auth, err in cre.failed:
1435 1447 if isinstance(err, HTTPError):
1436 1448 ermsg += " %s: %s - %s\n" % \
1437 1449 (err.filename, err.code, err.msg)
1438 1450 elif isinstance(err, URLError):
1439 1451 if err.args[0][0] == 8:
1440 1452 ermsg += " %s: %s\n" % \
1441 1453 (urlparse.urlsplit(
1442 1454 auth["origin"])[1].split(":")[0],
1443 1455 err.args[0][1])
1444 1456 else:
1445 1457 if isinstance(err.args[0], \
1446 1458 socket.timeout):
1447 1459 ermsg += " %s: %s\n" % \
1448 1460 (auth["origin"], "timeout")
1449 1461 else:
1450 1462 ermsg += " %s: %s\n" % \
1451 1463 (auth["origin"], \
1452 1464 err.args[0][1])
1453 1465 elif err.data:
1454 1466 ermsg += err.data
1455 1467 else:
1456 1468 ermsg += self._("Unknown error")
1457 1469 ermsg += "\n"
1458 1470
1459 1471 gobject.idle_add(self.error_occured, ermsg)
1460 1472 self.__catalog_refresh_done()
1461 1473 return -1
1462 1474
1463 1475 except api_errors.UnrecognizedAuthorityException:
1464 1476 self.__catalog_refresh_done()
1465 1477 raise
1466 1478 except Exception:
1467 1479 self.__catalog_refresh_done()
1468 1480 raise
1469 1481 if reload_gui:
1470 1482 self.__catalog_refresh_done()
1471 1483 return 0
1472 1484
1473 1485 def __get_image_from_directory(self, api_o, progressdialog_progress):
1474 1486 """ This method set up image from the given directory and
1475 1487 returns the image object or None"""
1476 1488 application_list = self.__get_new_application_liststore()
1477 1489 category_list = self.__get_new_category_liststore()
1478 1490 repositories_list = self.__get_new_repositories_liststore()
1479 1491
1480 1492 try:
1481 1493 pkgs_known = [ pf[0] for pf in
1482 1494 sorted(api_o.img.inventory(all_known = True)) ]
1483 1495 except api_errors.InventoryException:
1484 1496 # Can't happen when all_known is true and no args,
1485 1497 # but here for completeness.
1486 1498 err = self._("Error occured while getting list of packages")
1487 1499 gobject.idle_add(self.w_progress_dialog.hide)
1488 1500 gobject.idle_add(self.error_occured, err)
1489 1501 return
1490 1502
1491 1503 #Only one instance of those icons should be in memory
1492 1504 update_available_icon = self.get_icon_pixbuf("status_newupdate")
1493 1505 installed_icon = self.get_icon_pixbuf("status_installed")
1494 1506 #Imageinfo for categories
1495 1507 imginfo = imageinfo.ImageInfo()
1496 1508 sectioninfo = imageinfo.ImageInfo()
1497 1509 catalogs = api_o.img.catalogs
1498 1510 categories = {}
1499 1511 sections = {}
1500 1512 for cat in catalogs:
1501 1513 category = imginfo.read(self.application_dir + \
1502 1514 "/usr/share/package-manager/data/" + cat)
1503 1515 categories[cat] = category
1504 1516 section = sectioninfo.read(self.application_dir + \
1505 1517 "/usr/share/package-manager/data/" + cat + ".sections")
1506 1518 sections[cat] = section
1507 1519 # Speedup, instead of checking if the pkg is already in the list,
1508 1520 # iterating through all elements, we will only compare to the previous
1509 1521 # package and if the package is the same (version difference) then we
1510 1522 # are adding to the first iterator for the set of those packages.
1511 1523 # We can do that, since the list pkgs_known is sorted
1512 1524 # This will give a sppedup from 18sec to ~3!!!
1513 1525 p_pkg_iter = None
1514 1526 p_pkg = None
1515 1527 insert_count = 0
1516 1528 icon_path = self.application_dir + \
1517 1529 "/usr/share/package-manager/data/pixmaps/"
1518 1530
1519 1531 pkg_count = 0
1520 1532 progress_percent = INITIAL_PROGRESS_TOTAL_PERCENTAGE
1521 1533 total_pkg_count = len(pkgs_known)
1522 1534 progress_increment = \
1523 1535 total_pkg_count / PACKAGE_PROGRESS_TOTAL_INCREMENTS
1524 1536
1525 1537 self.progress_stop_timer_thread = True
1526 1538 while gtk.events_pending():
1527 1539 gtk.main_iteration(False)
1528 1540 for pkg in pkgs_known:
1529 1541 if progress_increment > 0 and pkg_count % progress_increment == 0:
1530 1542 progress_percent += PACKAGE_PROGRESS_PERCENT_INCREMENT
1531 1543 if progress_percent <= PACKAGE_PROGRESS_PERCENT_TOTAL:
1532 1544 progressdialog_progress(progress_percent, \
1533 1545 pkg_count, total_pkg_count)
1534 1546 while gtk.events_pending():
1535 1547 gtk.main_iteration(False)
1536 1548 pkg_count += 1
1537 1549
1538 1550 #speedup hack, check only last package
1539 1551 already_in_model = \
1540 1552 self.check_if_pkg_have_row_in_model(pkg, p_pkg)
1541 1553 if not already_in_model: #Create new row
1542 1554 available_version = None
1543 1555 version_installed = None
1544 1556 status_icon = None
1545 1557 fmris = [pkg, ]
1546 1558 package_installed = \
1547 1559 self.get_installed_version(api_o, pkg)
1548 1560 if package_installed:
1549 1561 version_installed = \
1550 1562 package_installed.version.get_short_version()
1551 1563 #HACK, sometimes the package is installed but
1552 1564 #it's not in the pkgs_known
1553 1565 status_icon = installed_icon
1554 1566 if package_installed != pkg:
1555 1567 fmris.append(package_installed)
1556 1568 else:
1557 1569 dt = self.get_datetime(pkg.version)
1558 1570 dt_str = (":%02d%02d") % (dt.month, dt.day)
1559 1571 available_version = \
1560 1572 pkg.version.get_short_version() + dt_str
1561 1573 package_icon = self.__get_pixbuf_from_path(icon_path, \
1562 1574 pkg.get_name())
1563 1575 app = \
1564 1576 [
1565 1577 False, status_icon, package_icon, pkg.get_name(),
1566 1578 version_installed, package_installed,
1567 1579 available_version, -1, '...', fmris,
1568 1580 True, None
1569 1581 ]
1570 1582 # XXX Small hack, if this is not applied, first package
1571 1583 # is listed twice. Insert is ~0.5 sec faster than append
1572 1584 if insert_count == 0:
1573 1585 row_iter = application_list.append(app)
1574 1586 else:
1575 1587 row_iter = \
1576 1588 application_list.insert(insert_count, \
1577 1589 app)
1578 1590 # XXX Do not iterate through all the catalogs. Package
1579 1591 # should know what is package fmri prefix?
1580 1592 apc = self.__add_package_to_category
1581 1593 app_ls = application_list
1582 1594 for cat in categories:
1583 1595 if cat in categories:
1584 1596 name = pkg.get_name()
1585 1597 if name in categories[cat]:
1586 1598 pkg_categories = \
1587 1599 categories[cat][ \
1588 1600 name]
1589 1601 for pcat in \
1590 1602 pkg_categories.split(","):
1591 1603 if pcat:
1592 1604 apc(self._( \
1593 1605 pcat), None \
1594 1606 , None, \
1595 1607 row_iter, \
1596 1608 app_ls, \
1597 1609 category_list)
1598 1610 insert_count = insert_count + 1
1599 1611 p_pkg_iter = row_iter
1600 1612 p_pkg = pkg #The current become previous
1601 1613 else:
1602 1614 # XXX check versions in here. For all installed/not
1603 1615 # installed:
1604 1616 # if there is newer version, put it in the available
1605 1617 # field.
1606 1618 #
1607 1619 # XXXhack, since image_get_version_installed(pkg) is not
1608 1620 # working,as it should. For example package:
1609 1621 # SUNWarc@0.5.11,5.11-0.79:20080205T152309Z
1610 1622 # is not installed and it's newer version of installed
1611 1623 # package:
1612 1624 # SUNWarc@0.5.11,5.11-0.75:20071114T201151Z
1613 1625 # the function returns only proper installed version for
1614 1626 # the older package and None for the newer.
1615 1627 # The hack is a little bit slow since we are iterating
1616 1628 # for all known packages
1617 1629 list_of_pkgs = \
1618 1630 application_list.get_value(p_pkg_iter, \
1619 1631 enumerations.PACKAGE_OBJECT_COLUMN)
1620 1632 if pkg not in list_of_pkgs:
1621 1633 list_of_pkgs.append(pkg)
1622 1634 installed = application_list.get_value(p_pkg_iter, \
1623 1635 enumerations.INSTALLED_OBJECT_COLUMN)
1624 1636 latest = max(list_of_pkgs)
1625 1637 dt = self.get_datetime(latest.version)
1626 1638 dt_str = (":%02d%02d") % (dt.month, dt.day)
1627 1639 if not installed:
1628 1640 application_list.set_value(p_pkg_iter, \
1629 1641 enumerations.LATEST_AVAILABLE_COLUMN, \
1630 1642 latest.version.get_short_version() + \
1631 1643 dt_str)
1632 1644 else:
1633 1645 if installed < latest:
1634 1646 application_list.set_value( \
1635 1647 p_pkg_iter, \
1636 1648 enumerations. \
1637 1649 LATEST_AVAILABLE_COLUMN, \
1638 1650 latest.version.get_short_version() + \
1639 1651 dt_str)
1640 1652 application_list.set_value(\
1641 1653 p_pkg_iter, \
1642 1654 enumerations.STATUS_ICON_COLUMN, \
1643 1655 update_available_icon)
1644 1656 # XXX How to get descriptions without manifest?
1645 1657 # XXX Downloading manifest is slow and can not work without
1646 1658 # XXX Network connection
1647 1659 #if not image_obj.has_manifest(pkg):
1648 1660 # image_obj.get_manifest(pkg)#verify(pkg, pr)
1649 1661 #installed_version = None
1650 1662 #package_iter = None #the iterator which points for other package
1651 1663 for authority in sections:
1652 1664 for section in sections[authority]:
1653 1665 for category in sections[authority][section].split(","):
1654 1666 self.__add_category_to_section(self._(category), \
1655 1667 self._(section), category_list)
1656 1668
1657 1669 #1915 Sort the Categories into alphabetical order and prepend All Category
1658 1670 if len(category_list) > 0:
1659 1671 rows = [tuple(r) + (i,) for i, r in enumerate(category_list)]
1660 1672 rows.sort(self.__sort)
1661 1673 r = []
1662 1674 category_list.reorder([r[-1] for r in rows])
1663 1675 category_list.prepend([0, self._('All'), None, None, True, None])
1664 1676
1665 1677 progressdialog_progress(PACKAGE_PROGRESS_PERCENT_TOTAL, pkg_count, \
1666 1678 total_pkg_count)
1667 1679 gobject.idle_add(self.process_package_list_end, api_o, \
1668 1680 application_list, category_list, repositories_list)
1669 1681
1670 1682 def __add_package_to_category(self, category_name, category_description, \
1671 1683 category_icon, package, application_list, category_list):
1672 1684 if not package or category_name == self._('All'):
1673 1685 return
1674 1686 if not category_name:
1675 1687 return
1676 1688 # XXX check if needed
1677 1689 # category_name = self._('All')
1678 1690 # category_description = self._('All packages')
1679 1691 # category_icon = None
1680 1692 category_ref = None
1681 1693 for category in category_list:
1682 1694 if category[enumerations.CATEGORY_NAME] == category_name:
1683 1695 category_ref = category.iter
1684 1696 if not category_ref: # Category not exists
1685 1697 category_ref = category_list.append([len( \
1686 1698 category_list)+1, category_name, category_description, \
1687 1699 category_icon, True, None])
1688 1700 if category_ref:
1689 1701 if application_list.get_value(package, \
1690 1702 enumerations.CATEGORY_LIST_OBJECT):
1691 1703 a = application_list.get_value(package, \
1692 1704 enumerations.CATEGORY_LIST_OBJECT)
1693 1705 a.append(category_ref)
1694 1706 else:
1695 1707 category_list = []
1696 1708 category_list.append(category_ref)
1697 1709 application_list.set(package, \
1698 1710 enumerations.CATEGORY_LIST_OBJECT, category_list)
1699 1711
1700 1712 def __add_category_to_section(self, category_name, section_name, category_list):
1701 1713 '''Adds the section to section list in category. If there is no such
1702 1714 section, than it is not added. If there was already section than it
1703 1715 is skipped. Sections must be case sensitive'''
1704 1716 if not category_name:
1705 1717 return
1706 1718 for section in self.section_list:
1707 1719 if section[enumerations.SECTION_NAME] == section_name:
1708 1720 for category in category_list:
1709 1721 if category[enumerations.CATEGORY_NAME] == \
1710 1722 category_name:
1711 1723 if not category[ \
1712 1724 enumerations.SECTION_LIST_OBJECT]:
1713 1725 category[ \
1714 1726 enumerations. \
1715 1727 SECTION_LIST_OBJECT] = \
1716 1728 [section[ \
1717 1729 enumerations.SECTION_ID], ]
1718 1730 else:
1719 1731 if not section_name in \
1720 1732 category[ \
1721 1733 enumerations. \
1722 1734 SECTION_LIST_OBJECT]:
1723 1735 category[enumerations. \
1724 1736 SECTION_LIST_OBJECT \
1725 1737 ].append(section[ \
1726 1738 enumerations. \
1727 1739 SECTION_ID])
1728 1740
1729 1741 def __get_pixbuf_from_path(self, path, icon_name):
1730 1742 icon = icon_name.replace(' ', '_')
1731 1743
1732 1744 # Performance: Faster to check if files exist rather than catching
1733 1745 # exceptions when they do not. Picked up open failures using dtrace
1734 1746 png_exists = os.path.exists(self.application_dir + path + icon + ".png")
1735 1747 svg_exists = os.path.exists(self.application_dir + path + icon + ".svg")
1736 1748
1737 1749 if not png_exists and not svg_exists:
1738 1750 return None
1739 1751 try:
1740 1752 return gtk.gdk.pixbuf_new_from_file( \
1741 1753 self.application_dir + path + icon + ".png")
1742 1754 except gobject.GError:
1743 1755 try:
1744 1756 return gtk.gdk.pixbuf_new_from_file( \
1745 1757 self.application_dir + path + icon + ".svg")
1746 1758 except gobject.GError:
1747 1759 iconview = gtk.IconView()
1748 1760 icon = iconview.render_icon(getattr(gtk, \
1749 1761 "STOCK_MISSING_IMAGE"), \
1750 1762 size = gtk.ICON_SIZE_MENU,
1751 1763 detail = None)
1752 1764 # XXX Could return image-we don't want to show ugly icon.
1753 1765 return None
1754 1766
1755 1767 def __progressdialog_progress_pulse(self):
1756 1768 while not self.progress_stop_timer_thread:
1757 1769 gobject.idle_add(self.w_progressbar.pulse)
1758 1770 time.sleep(0.1)
1759 1771 gobject.idle_add(self.w_progress_dialog.hide)
1760 1772 self.progress_stop_timer_thread = False
1761 1773
1762 1774 # For initial setup before loading package entries allow 5% of progress bar
1763 1775 # update it on a time base as we have no other way to judge progress at this point
1764 1776 def __progressdialog_progress_time(self):
1765 1777 while not self.progress_stop_timer_thread and \
1766 1778 self.progress_fraction_time_count <= \
1767 1779 INITIAL_PROGRESS_TOTAL_PERCENTAGE:
1768 1780
1769 1781 gobject.idle_add(self.w_progressbar.set_fraction, \
1770 1782 self.progress_fraction_time_count)
1771 1783 self.progress_fraction_time_count += \
1772 1784 INITIAL_PROGRESS_TIME_PERCENTAGE
1773 1785 time.sleep(INITIAL_PROGRESS_TIME_INTERVAL)
1774 1786 self.progress_stop_timer_thread = False
1775 1787 self.progress_fraction_time_count = 0
1776 1788
1777 1789 def __progressdialog_progress_percent(self, fraction, count, total):
1778 1790 gobject.idle_add(self.w_progressinfo_label.set_text, self._( \
1779 1791 "Processing package entries: %d of %d") % (count, total) )
1780 1792 gobject.idle_add(self.w_progressbar.set_fraction, fraction)
1781 1793
1782 1794 def error_occured(self, error_msg, msg_title=None, msg_type=gtk.MESSAGE_ERROR):
1783 1795 msgbox = gtk.MessageDialog(parent = \
1784 1796 self.w_main_window, \
1785 1797 buttons = gtk.BUTTONS_CLOSE, \
1786 1798 flags = gtk.DIALOG_MODAL, \
1787 1799 type = msg_type, \
1788 1800 message_format = None)
1789 1801 msgbox.set_markup(error_msg)
1790 1802 title = None
1791 1803 if msg_title:
1792 1804 title = msg_title
1793 1805 else:
1794 1806 title = self._("Package Manager")
1795 1807 msgbox.set_title(title)
1796 1808 msgbox.run()
1797 1809 msgbox.destroy()
1798 1810
1799 1811 #-----------------------------------------------------------------------------#
1800 1812 # Static Methods
1801 1813 #-----------------------------------------------------------------------------#
1802 1814
1803 1815 @staticmethod
1804 1816 def N_(message):
1805 1817 return message
1806 1818
1807 1819 @staticmethod
1808 1820 def __sort(a, b):
1809 1821 return cmp(a[1], b[1])
1810 1822
1811 1823 @staticmethod
1812 1824 def __installed_fmris_from_args(api_o, args_f):
1813 1825 found = []
1814 1826 notfound = []
1815 1827 try:
1816 1828 for m in api_o.img.inventory(args_f):
1817 1829 found.append(m[0])
1818 1830 except api_errors.InventoryException, e:
1819 1831 notfound = e.notfound
1820 1832
1821 1833 return notfound
1822 1834
1823 1835 @staticmethod
1824 1836 def cell_data_function(column, renderer, model, itr, data):
1825 1837 '''Function which sets the background colour to black if package is
1826 1838 selected'''
1827 1839 if itr:
1828 1840 if model.get_value(itr, enumerations.MARK_COLUMN):
1829 1841 renderer.set_property("cell-background", "#ffe5cc")
1830 1842 renderer.set_property("cell-background-set", True)
1831 1843 else:
1832 1844 renderer.set_property("cell-background-set", False)
1833 1845
1834 1846 @staticmethod
1835 1847 def combobox_separator(model, itr):
1836 1848 return model.get_value(itr, enumerations.FILTER_NAME) == ""
1837 1849
1838 1850 @staticmethod
1839 1851 def combobox_id_separator(model, itr):
1840 1852 return model.get_value(itr, 0) == -1
1841 1853
1842 1854 @staticmethod
1843 1855 def check_if_pkg_have_row_in_model(pkg, p_pkg):
1844 1856 """Returns True if package is already in model or False if not"""
1845 1857 if p_pkg:
1846 1858 if pkg.is_same_pkg(p_pkg):
1847 1859 return True
1848 1860 else:
1849 1861 return False
1850 1862 return False
1851 1863
1852 1864 @staticmethod
1853 1865 def category_filter(model, itr):
1854 1866 '''This function filters category in the main application view'''
1855 1867 return model.get_value(itr, enumerations.CATEGORY_VISIBLE)
1856 1868
1857 1869 @staticmethod
1858 1870 def get_datetime(version):
1859 1871 dt = None
1860 1872 try:
1861 1873 dt = version.get_datetime()
1862 1874 except AttributeError:
1863 1875 dt = version.get_timestamp()
1864 1876 return dt
1865 1877
1866 1878 @staticmethod
1867 1879 def get_installed_version(api_o, pkg):
1868 1880 return api_o.img.get_version_installed(pkg)
1869 1881
1870 1882 @staticmethod
1871 1883 def get_manifest(img, package, filtered = True):
1872 1884 '''helper function'''
1873 1885 # XXX Should go to the -> imageinfo.py
1874 1886 manifest = None
1875 1887
1876 1888 # 3087 shutdown time is too long when closing down soon after startup
1877 1889 if packagemanager.cancelled:
1878 1890 return manifest
1879 1891 try:
1880 1892 manifest = img.get_manifest(package, filtered)
1881 1893 except OSError:
1882 1894 # XXX It is possible here that the user doesn't have network con,
1883 1895 # XXX proper permissions to save manifest, should we do something
1884 1896 # XXX and popup information dialog?
1885 1897 pass
1886 1898 except (retrieve.ManifestRetrievalError,
1887 1899 retrieve.DatastreamRetrievalError, NameError):
1888 1900 pass
1889 1901 return manifest
1890 1902
1891 1903 @staticmethod
1892 1904 def update_desc(description, pkg, package):
1893 1905 p = pkg[enumerations.PACKAGE_OBJECT_COLUMN][0]
1894 1906 if p == package:
1895 1907 pkg[enumerations.DESCRIPTION_COLUMN] = description
1896 1908 return
1897 1909
1898 1910 #-----------------------------------------------------------------------------#
1899 1911 # Public Methods
1900 1912 #-----------------------------------------------------------------------------#
1901 1913 def setup_progressdialog_show(self):
1902 1914 self.w_progress_dialog.set_title(self._("Loading Repository Information"))
1903 1915 self.w_progressinfo_label.set_text(
1904 1916 self._( "Fetching package entries ..."))
1905 1917 self.w_progress_cancel.hide()
1906 1918 self.w_progress_dialog.show()
1907 1919 Thread(target = self.__progressdialog_progress_time).start()
1908 1920
1909 1921 def init_sections(self):
1910 1922 self.__init_sections() #Initiates sections
1911 1923
1912 1924 def init_show_filter(self):
1913 1925 self.__init_show_filter() #Initiates filter
1914 1926
1915 1927 def reload_packages(self):
1916 1928 self.api_o = self.__get_api_object(self.image_directory, self.pr)
1917 1929 self.__on_reload(None)
1918 1930
1919 1931 def process_package_list_start(self, image_directory):
1920 1932 self.cancelled = True
1921 1933 self.setup_progressdialog_show()
1922 1934 while gtk.events_pending():
1923 1935 gtk.main_iteration(False)
1924 1936 self.image_directory = image_directory
1925 1937 # Create our image object based on image directory.
1926 1938 api_o = self.__get_api_object(image_directory, self.pr)
1927 1939 api_o.img.load_catalogs(self.pr)
1928 1940 self.api_o = api_o
1929 1941 # Acquire image contents and update progress bar as you do so.
1930 1942 Thread(target = self.__get_image_from_directory, args = (api_o,
1931 1943 self.__progressdialog_progress_percent)).start()
1932 1944
1933 1945 @staticmethod
1934 1946 def __get_api_object(img_dir, progtrack):
1935 1947 api_o = None
1936 1948 try:
1937 1949 api_o = api.ImageInterface(img_dir, \
1938 1950 CLIENT_API_VERSION, \
1939 1951 progtrack, None, PKG_CLIENT_NAME)
1940 1952 except (api_errors.VersionException,\
1941 1953 api_errors.ImageNotFoundException):
1942 1954 raise
1943 1955 return api_o
1944 1956
1945 1957 def process_package_list_end(self, api_o, application_list, \
1946 1958 category_list, repositories_list):
1947 1959 self.__init_tree_views(application_list, category_list, repositories_list)
1948 1960 self.update_statusbar()
1949 1961 self.in_setup = False
1950 1962 self.__setup_repositories_combobox(api_o, repositories_list)
1951 1963 self.cancelled = False
1952 1964 while gtk.events_pending():
1953 1965 gtk.main_iteration(False)
1954 1966 self.w_categories_treeview.expand_all()
1955 1967 self.w_categories_treeview.grab_focus()
1956 1968 self.w_categories_treeview.set_cursor(0, \
1957 1969 None, start_editing=False)
1958 1970 self.w_application_treeview.expand_all()
1959 1971 while gtk.events_pending():
1960 1972 gtk.main_iteration(False)
1961 1973 self.__get_manifests_thread()
1962 1974 self.w_progress_dialog.hide()
1963 1975
1964 1976 def __get_manifests_thread(self):
1965 1977 Thread(target = self.get_manifests_for_packages,
1966 1978 args = ()).start()
1967 1979
1968 1980 def get_icon_pixbuf(self, icon_name):
1969 1981 #2821: The get_icon_pixbuf should use PACKAGE_MANAGER_ROOT
1970 1982 return self.__get_pixbuf_from_path(self.application_dir + \
1971 1983 "/usr/share/icons/package-manager/", icon_name)
1972 1984
1973 1985 def get_manifests_for_packages(self):
1974 1986 ''' Function, which get's manifest for packages. If the manifest is not
1975 1987 locally tries to retrieve it. For installed packages gets manifest
1976 1988 for the particular version (local operation only), if the package is
1977 1989 not installed than the newest one'''
1978 1990 time.sleep(3)
1979 1991 self.description_thread_running = True
1980 1992 img = self.api_o.img
1981 1993 img.history.operation_name = "info"
1982 1994 for pkg in self.application_list:
1983 1995 if self.cancelled:
1984 1996 self.description_thread_running = False
1985 1997 return
1986 1998 info = None
1987 1999 img = self.api_o.img
1988 2000 package = pkg[enumerations.PACKAGE_OBJECT_COLUMN][0]
1989 2001 if (img and package):
1990 2002 version = img.has_version_installed(package)
1991 2003 if version:
1992 2004 version = \
1993 2005 self.get_installed_version(self.api_o, \
1994 2006 package)
1995 2007 man = self.get_manifest(img, version, \
1996 2008 filtered = True)
1997 2009 if man:
1998 2010 info = man.get("description", "")
1999 2011 else:
2000 2012 newest = max( \
2001 2013 pkg[enumerations.PACKAGE_OBJECT_COLUMN])
2002 2014 man = self.get_manifest(img, newest, \
2003 2015 filtered = True)
2004 2016 if man:
2005 2017 info = man.get("description", "")
2006 2018 # XXX workaround, this should be done nicer
2007 2019 gobject.idle_add(self.update_desc, info, pkg, package)
2008 2020 time.sleep(0.01)
2009 2021 img.history.operation_name = "info"
2010 2022 img = self.api_o.img
2011 2023 img.history.operation_result = history.RESULT_SUCCEEDED
2012 2024 self.description_thread_running = False
2013 2025
2014 2026 def update_statusbar(self):
2015 2027 '''Function which updates statusbar'''
2016 2028 installed = 0
2017 2029 selected = 0
2018 2030 broken = 0
2019 2031 for pkg in self.application_list:
2020 2032 if pkg[enumerations.INSTALLED_VERSION_COLUMN]:
2021 2033 installed = installed + 1
2022 2034 if pkg[enumerations.MARK_COLUMN]:
2023 2035 selected = selected + 1
2024 2036 listed_str = self._('%d packages listed') % len(self.application_list)
2025 2037 inst_str = self._('%d installed') % installed
2026 2038 sel_str = self._('%d selected') % selected
2027 2039 broken_str = self._('%d broken') % broken
2028 2040 self.w_main_statusbar.push(0, listed_str + ', ' + inst_str + ', ' + \
2029 2041 sel_str + ', ' + broken_str + '.')
2030 2042
2031 2043
2032 2044 def update_package_list(self, update_list):
2033 2045 img = self.api_o.img
2034 2046 img.clear_pkg_state()
2035 2047 img.load_catalogs(self.pr)
2036 2048 installed_icon = self.get_icon_pixbuf("status_installed")
2037 2049 for row in self.application_list:
2038 2050 status_icon = None
2039 2051 if row[enumerations.MARK_COLUMN] or \
2040 2052 row[enumerations.NAME_COLUMN] in update_list:
2041 2053 pkg = row[enumerations.PACKAGE_OBJECT_COLUMN][0]
2042 2054 package_installed = \
2043 2055 self.get_installed_version(self.api_o, pkg)
2044 2056 version_installed = None
2045 2057 if package_installed:
2046 2058 status_icon = installed_icon
2047 2059 version_installed = \
2048 2060 package_installed.version.get_short_version()
2049 2061 row[enumerations.MARK_COLUMN] = False
2050 2062 row[enumerations.INSTALLED_VERSION_COLUMN] = \
2051 2063 version_installed
2052 2064 row[enumerations.INSTALLED_OBJECT_COLUMN] = \
2053 2065 package_installed
2054 2066 row[enumerations.STATUS_ICON_COLUMN] = \
2055 2067 status_icon
2056 2068 if not package_installed:
2057 2069 pkg = max(row[enumerations.PACKAGE_OBJECT_COLUMN])
2058 2070 dt = self.get_datetime(pkg.version)
2059 2071 dt_str = (":%02d%02d") % (dt.month, dt.day)
2060 2072 available_version = \
2061 2073 pkg.version.get_short_version() + dt_str
2062 2074 row[enumerations.LATEST_AVAILABLE_COLUMN] = \
2063 2075 available_version
2064 2076 else:
2065 2077 row[enumerations.LATEST_AVAILABLE_COLUMN] = None
2066 2078 self.w_installupdate_button.set_sensitive(False)
2067 2079 self.w_installupdate_menuitem.set_sensitive(False)
2068 2080 self.w_remove_button.set_sensitive(False)
2069 2081 self.w_remove_menuitem.set_sensitive(False)
2070 2082 self.__enable_disable_selection_menus()
2071 2083 self.update_statusbar()
2072 2084
2073 2085 def shutdown_after_ips_update(self):
2074 2086
2075 2087 # 2790: As IPS and IPS-GUI have been updated the IPS GUI must be shutdown
2076 2088 # and restarted
2077 2089 msgbox = gtk.MessageDialog(parent = self.w_main_window, \
2078 2090 buttons = gtk.BUTTONS_OK, \
2079 2091 flags = gtk.DIALOG_MODAL, type = gtk.MESSAGE_INFO, \
2080 2092 message_format = self._("SUNWipkg and SUNWipkg-gui have been " \
2081 2093 "updated and Package Manager will now be restarted.\n\nAfter " \
2082 2094 "restart select Update All to continue."))
2083 2095 msgbox.set_title(self._("Update All"))
2084 2096 msgbox.run()
2085 2097 msgbox.destroy()
2086 2098 self.__main_application_quit(restart_app = True)
2087 2099
2088 2100 def shutdown_after_image_update(self):
2089 2101
2090 2102 msgbox = gtk.MessageDialog(parent = self.w_main_window, \
2091 2103 buttons = gtk.BUTTONS_OK, \
2092 2104 flags = gtk.DIALOG_MODAL, type = gtk.MESSAGE_INFO, \
2093 2105 message_format = self._("Update All has completed and Package " \
2094 2106 "Manager will now exit.\n\nPlease reboot after reviewing the " \
2095 2107 "release notes posted at:\n\n" \
2096 2108 "http://opensolaris.org/os/project/indiana/resources/" \
2097 2109 "relnotes/200811/x86/"))
2098 2110 msgbox.set_title(self._("Update All"))
2099 2111 msgbox.run()
2100 2112 msgbox.destroy()
2101 2113 self.__main_application_quit()
2102 2114
2103 2115 ###############################################################################
2104 2116 #-----------------------------------------------------------------------------#
2105 2117 # Test functions
2106 2118 #-----------------------------------------------------------------------------#
2107 2119 def fill_with_fake_data(self):
2108 2120 '''test data for gui'''
2109 2121 self.application_list = self.__get_new_application_liststore()
2110 2122 self.category_list = self.__get_new_category_liststore()
2111 2123 self.section_list = self.__get_new_section_liststore()
2112 2124 self.filter_list = self.__get_new_filter_liststore()
2113 2125 self.repositories_list = self.__get_new_repositories_liststore()
2114 2126
2115 2127 app1 = [False, self.get_icon_pixbuf("locked"), \
2116 2128 self.get_icon_pixbuf("None"), "acc", None, None, None, 4, "desc6", \
2117 2129 "Object Name1", None, True, None]
2118 2130 app2 = [False, self.get_icon_pixbuf("update_available"), \
2119 2131 self.get_icon_pixbuf(self._('All')), "acc_gam", \
2120 2132 "2.3", None, "2.8", \
2121 2133 4, "desc7", "Object Name2", None, True, None]
2122 2134 app3 = [False, self.get_icon_pixbuf("None"), \
2123 2135 self.get_icon_pixbuf("Other"), "gam_grap", "2.3", None, None, 4, \
2124 2136 "desc8", "Object Name3", None, True, None]
2125 2137 app4 = [False, self.get_icon_pixbuf("update_locked"), \
2126 2138 self.get_icon_pixbuf("Office"), "grap_gam", "2.3", None, "2.8", 4, \
2127 2139 "desc9", "Object Name2", None, True, None]
2128 2140 app5 = [False, self.get_icon_pixbuf("update_available"), \
2129 2141 self.get_icon_pixbuf("None"), "grap", "2.3", None, "2.8", 4, \
2130 2142 "desc0", "Object Name3", None, True, None]
2131 2143 itr1 = self.application_list.append(app1)
2132 2144 itr2 = self.application_list.append(app2)
2133 2145 itr3 = self.application_list.append(app3)
2134 2146 itr4 = self.application_list.append(app4)
2135 2147 itr5 = self.application_list.append(app5)
2136 2148 # self.__add_package_to_category(_("All"),None,None,None);
2137 2149 self.__add_package_to_category(self._("Accessories"), \
2138 2150 None, None, itr1, self.application_list, self.category_list)
2139 2151 self.__add_package_to_category(self._("Accessories"), None, None, itr2, \
2140 2152 self.application_list, self.category_list)
2141 2153 self.__add_package_to_category(self._("Games"), None, None, itr3, \
2142 2154 self.application_list, self.category_list)
2143 2155 self.__add_package_to_category(self._("Graphics"), None, None, itr3, \
2144 2156 self.application_list, self.category_list)
2145 2157 self.__add_package_to_category(self._("Games"), None, None, itr2, \
2146 2158 self.application_list, self.category_list)
2147 2159 self.__add_package_to_category(self._("Graphics"), None, None, itr4, \
2148 2160 self.application_list, self.category_list)
2149 2161 self.__add_package_to_category(self._("Games"), None, None, itr4, \
2150 2162 self.application_list, self.category_list)
2151 2163 self.__add_package_to_category(self._("Graphics"), None, None, itr5, \
2152 2164 self.application_list, self.category_list)
2153 2165
2154 2166 # Category names until xdg is imported.
2155 2167 # from xdg.DesktopEntry import *
2156 2168 # entry = DesktopEntry ()
2157 2169 # directory = '/usr/share/desktop-directories'
2158 2170 # for root, dirs, files in os.walk (directory):
2159 2171 # for name in files:
2160 2172 # entry.parse (os.path.join (root, name))
2161 2173 # self.__add_category_to_section (entry.getName (), \
2162 2174 # self._('Applications Desktop'))
2163 2175
2164 2176 self.__add_category_to_section(self._("Accessories"), \
2165 2177 self._('Applications Desktop'), self.category_list)
2166 2178 self.__add_category_to_section(self._("Games"), \
2167 2179 self._('Applications Desktop'), self.category_list)
2168 2180 self.__add_category_to_section(self._("Graphics"), \
2169 2181 self._('Applications Desktop'), self.category_list)
2170 2182 self.__add_category_to_section(self._("Internet"), \
2171 2183 self._('Applications Desktop'), self.category_list)
2172 2184 self.__add_category_to_section(self._("Office"), \
2173 2185 self._('Applications Desktop'), self.category_list)
2174 2186 self.__add_category_to_section(self._("Sound & Video"), \
2175 2187 self._('Applications Desktop'), self.category_list)
2176 2188 self.__add_category_to_section(self._("System Tools"), \
2177 2189 self._('Applications Desktop'), self.category_list)
2178 2190 self.__add_category_to_section(self._("Universal Access"), \
2179 2191 self._('Applications Desktop'), self.category_list)
2180 2192 self.__add_category_to_section(self._("Developer Tools"), \
2181 2193 self._('Applications Desktop'), self.category_list)
2182 2194 self.__add_category_to_section(self._("Core"), \
2183 2195 self._('Operating System'), self.category_list)
2184 2196 self.__add_category_to_section(self._("Graphics"), \
2185 2197 self._('Operating System'), self.category_list)
2186 2198 self.__add_category_to_section(self._("Media"), \
2187 2199 self._('Operating System'), self.category_list)
2188 2200 #Can be twice :)
2189 2201 self.__add_category_to_section(self._("Developer Tools"), \
2190 2202 self._('Operating System'), self.category_list)
2191 2203 self.__add_category_to_section(self._("Office"), "Progs", \
2192 2204 self.category_list)
2193 2205 self.__add_category_to_section(self._("Office2"), "Progs", \
2194 2206 self.category_list)
2195 2207 self.__setup_repositories_combobox(self.api_o)
2196 2208 self.in_setup = False
2197 2209
2198 2210 ###############################################################################
2199 2211 #-----------------------------------------------------------------------------#
2200 2212 # Main
2201 2213 #-----------------------------------------------------------------------------#
2202 2214
2203 2215 def main():
2204 2216 gtk.main()
2205 2217 return 0
2206 2218
2207 2219 if __name__ == '__main__':
2208 2220 packagemanager = PackageManager()
2209 2221 passed_test_arg = False
2210 2222 passed_imagedir_arg = False
2211 2223 packagemanager.provided_image_dir = True
2212 2224
2213 2225 try:
2214 2226 opts, args = getopt.getopt(sys.argv[1:], "htR:", \
2215 2227 ["help", "test-gui", "image-dir="])
2216 2228 except getopt.error, msg:
2217 2229 print "%s, for help use --help" % msg
2218 2230 sys.exit(2)
2219 2231
2220 2232 cmd = os.path.join(os.getcwd(), sys.argv[0])
2221 2233 cmd = os.path.realpath(cmd)
2222 2234 packagemanager.application_path = cmd
2223 2235
2224 2236 for option, argument in opts:
2225 2237 if option in ("-h", "--help"):
2226 2238 print """\
2227 2239 Use -R (--image-dir) to specify image directory.
2228 2240 Use -t (--test-gui) to work on fake data."""
2229 2241 sys.exit(0)
2230 2242 if option in ("-t", "--test-gui"):
2231 2243 passed_test_arg = True
2232 2244 if option in ("-R", "--image-dir"):
2233 2245 packagemanager.image_dir_arg = argument
2234 2246 image_dir = argument
2235 2247 passed_imagedir_arg = True
2236 2248
2237 2249 if passed_test_arg and passed_imagedir_arg:
2238 2250 print "Options -R and -t can not be used together."
2239 2251 sys.exit(2)
2240 2252 if not passed_imagedir_arg:
2241 2253 try:
2242 2254 image_dir = os.environ["PKG_IMAGE"]
2243 2255 except KeyError:
2244 2256 image_dir = os.getcwd()
2245 2257 packagemanager.provided_image_dir = False
2246 2258
2247 2259 while gtk.events_pending():
2248 2260 gtk.main_iteration(False)
2249 2261
2250 2262 packagemanager.init_sections()
2251 2263 packagemanager.init_show_filter()
2252 2264
2253 2265 if not passed_test_arg:
2254 2266 packagemanager.process_package_list_start(image_dir)
2255 2267 else:
2256 2268 packagemanager.fill_with_fake_data()
2257 2269
2258 2270 main()
|
↓ open down ↓ |
1695 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX