src/gui/modules/misc.py
author John Rice <john.rice@sun.com>
Fri, 12 Feb 2010 16:41:23 +0000
changeset 1761 b2d8237ac690
parent 1744 04532a16c1ac
child 1791 b2a37ff09e8c
permissions -rw-r--r--
14481 Package version Info image lock exception not handled 14437 pm traceback in update_all on startup
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1516
8c950a3b4171 10485 move pkg(5) to Python 2.6
Rich Burridge <rich.burridge@sun.com>
parents: 1487
diff changeset
     1
#!/usr/bin/python
869
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     2
#
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     3
# CDDL HEADER START
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     4
#
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     8
#
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    12
# and limitations under the License.
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    13
#
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    19
#
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    20
# CDDL HEADER END
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    21
#
1650
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    22
# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
869
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    23
# Use is subject to license terms.
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    24
#
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    25
1031
5c130cc07e44 7037 GUI to cut last all but part of new Category Path
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 985
diff changeset
    26
SPECIAL_CATEGORIES = ["locale", "plugin"] # We should cut all, but last part of the
5c130cc07e44 7037 GUI to cut last all but part of new Category Path
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 985
diff changeset
    27
                                          # new name scheme as part of fix for #7037.
5c130cc07e44 7037 GUI to cut last all but part of new Category Path
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 985
diff changeset
    28
                                          # However we need to have an exception rule
5c130cc07e44 7037 GUI to cut last all but part of new Category Path
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 985
diff changeset
    29
                                          # where we will cut all but three last parts.
5c130cc07e44 7037 GUI to cut last all but part of new Category Path
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 985
diff changeset
    30
1487
2c36e9347c4f 12099 Change the be rename sequence in Update All.
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1482
diff changeset
    31
RELEASE_URL = "http://www.opensolaris.org" # Fallback url for release notes if api
2c36e9347c4f 12099 Change the be rename sequence in Update All.
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1482
diff changeset
    32
                                           # does not gave us one.
2c36e9347c4f 12099 Change the be rename sequence in Update All.
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1482
diff changeset
    33
869
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    34
import os
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    35
import sys
1478
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
    36
import urllib2
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
    37
import urlparse
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
    38
import socket
1761
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
    39
import traceback
869
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    40
try:
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    41
        import gobject
942
cb2774668721 6707 Text change for Update Manager dialog
John Rice <john.rice@sun.com>
parents: 927
diff changeset
    42
        import gnome
869
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    43
        import gtk
1366
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
    44
        import pango
869
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    45
except ImportError:
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    46
        sys.exit(1)
1366
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
    47
import pkg.misc as misc
1168
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
    48
import pkg.client.api_errors as api_errors
1366
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
    49
import pkg.client.api as api
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
    50
from pkg.gui.misc_non_gui import get_api_object as ngao
1573
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1566
diff changeset
    51
from pkg.gui.misc_non_gui import setup_logging as su_logging
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1566
diff changeset
    52
from pkg.gui.misc_non_gui import shutdown_logging as sd_logging
1649
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    53
from pkg.gui.misc_non_gui import get_version as g_version
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    54
1675
8caa149137be 13975 Transport errors should be logged rather than displayed in a dialog
John Rice <john.rice@sun.com>
parents: 1667
diff changeset
    55
from pkg.gui.misc_non_gui import get_log_dir as ge_log_dir
8caa149137be 13975 Transport errors should be logged rather than displayed in a dialog
John Rice <john.rice@sun.com>
parents: 1667
diff changeset
    56
from pkg.gui.misc_non_gui import get_log_error_ext as ge_log_error_ext
8caa149137be 13975 Transport errors should be logged rather than displayed in a dialog
John Rice <john.rice@sun.com>
parents: 1667
diff changeset
    57
from pkg.gui.misc_non_gui import get_log_info_ext as ge_log_info_ext
8caa149137be 13975 Transport errors should be logged rather than displayed in a dialog
John Rice <john.rice@sun.com>
parents: 1667
diff changeset
    58
8caa149137be 13975 Transport errors should be logged rather than displayed in a dialog
John Rice <john.rice@sun.com>
parents: 1667
diff changeset
    59
from pkg.client import global_settings
8caa149137be 13975 Transport errors should be logged rather than displayed in a dialog
John Rice <john.rice@sun.com>
parents: 1667
diff changeset
    60
8caa149137be 13975 Transport errors should be logged rather than displayed in a dialog
John Rice <john.rice@sun.com>
parents: 1667
diff changeset
    61
PKG_CLIENT_NAME_PM = "packagemanager"
8caa149137be 13975 Transport errors should be logged rather than displayed in a dialog
John Rice <john.rice@sun.com>
parents: 1667
diff changeset
    62
PKG_CLIENT_NAME_WI = "packagemanager-webinstall"
8caa149137be 13975 Transport errors should be logged rather than displayed in a dialog
John Rice <john.rice@sun.com>
parents: 1667
diff changeset
    63
PKG_CLIENT_NAME_UM = "updatemanager"
8caa149137be 13975 Transport errors should be logged rather than displayed in a dialog
John Rice <john.rice@sun.com>
parents: 1667
diff changeset
    64
8caa149137be 13975 Transport errors should be logged rather than displayed in a dialog
John Rice <john.rice@sun.com>
parents: 1667
diff changeset
    65
logger = global_settings.logger
8caa149137be 13975 Transport errors should be logged rather than displayed in a dialog
John Rice <john.rice@sun.com>
parents: 1667
diff changeset
    66
1649
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    67
def get_version():
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    68
        return g_version()        
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    69
                
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    70
def get_publishers_for_output(api_o):
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    71
        publisher_str = ""
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    72
        fmt = "\n%s\t%s\t%s (%s)"
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    73
        try:
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    74
                pref_pub = api_o.get_preferred_publisher()
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    75
                for pub in api_o.get_publishers():
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    76
                        pstatus = " "
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    77
                        if pub == pref_pub:
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    78
                                # Preferred
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    79
                                pstatus = "P"
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    80
                        elif pub.disabled:
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    81
                                # Disabled
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    82
                                pstatus = "D"
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    83
                        else:
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    84
                                # Enabled, but not preferred
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    85
                                pstatus = "E"
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    86
                        r = pub.selected_repository
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    87
                        for uri in r.origins:
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    88
                                # Origin
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    89
                                publisher_str += fmt % \
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    90
                                        (pstatus, "O", pub.prefix, uri)
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    91
                        for uri in r.mirrors:
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    92
                                # Mirror
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    93
                                publisher_str += fmt % \
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    94
                                        (pstatus, "M", pub.prefix, uri)
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    95
        except api_errors.ApiException:
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    96
                pass
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    97
        except Exception:
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    98
                pass
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1647
diff changeset
    99
        return publisher_str
942
cb2774668721 6707 Text change for Update Manager dialog
John Rice <john.rice@sun.com>
parents: 927
diff changeset
   100
1650
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   101
def get_log_dir():
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   102
        return ge_log_dir()
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   103
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   104
def get_log_error_ext():
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   105
        return ge_log_error_ext()
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   106
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   107
def get_log_info_ext():
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   108
        return ge_log_info_ext()
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   109
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   110
def get_pm_name():
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   111
        return PKG_CLIENT_NAME_PM
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   112
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   113
def get_wi_name():
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   114
        return PKG_CLIENT_NAME_WI
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   115
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   116
def get_um_name():
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   117
        return PKG_CLIENT_NAME_UM
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   118
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   119
def notify_log_error(app):
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   120
        if global_settings.client_name == PKG_CLIENT_NAME_PM:
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   121
                gobject.idle_add(__notify_log_error, app)
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   122
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   123
def __notify_log_error(app):
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   124
        app.error_logged = True
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   125
        app.w_infosearch_frame.show()
1667
88ac0910cb61 13918 PM notification icon truncated when error logged
John Rice <john.rice@sun.com>
parents: 1650
diff changeset
   126
        app.w_infosearch_frame.set_tooltip_text(_("Errors logged: click to view"))
1650
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
   127
1573
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1566
diff changeset
   128
def setup_logging(client_name):
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1566
diff changeset
   129
        su_logging(client_name)
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1566
diff changeset
   130
        
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1566
diff changeset
   131
def shutdown_logging():
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1566
diff changeset
   132
        sd_logging()
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1566
diff changeset
   133
        
869
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   134
def get_icon_pixbuf(application_dir, icon_name):
1137
f6c7c39981aa 8660 packagemanager traceback if PACKAGE_MANAGER_ROOT missing trailing '/'
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1087
diff changeset
   135
        return get_pixbuf_from_path(os.path.join(application_dir,
f6c7c39981aa 8660 packagemanager traceback if PACKAGE_MANAGER_ROOT missing trailing '/'
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1087
diff changeset
   136
            "usr/share/icons/package-manager"), icon_name)
869
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   137
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   138
def get_pixbuf_from_path(path, icon_name):
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   139
        icon = icon_name.replace(' ', '_')
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   140
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   141
        # Performance: Faster to check if files exist rather than catching
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   142
        # exceptions when they do not. Picked up open failures using dtrace
1137
f6c7c39981aa 8660 packagemanager traceback if PACKAGE_MANAGER_ROOT missing trailing '/'
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1087
diff changeset
   143
        png_path = os.path.join(path, icon + ".png")
f6c7c39981aa 8660 packagemanager traceback if PACKAGE_MANAGER_ROOT missing trailing '/'
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1087
diff changeset
   144
        png_exists = os.path.exists(png_path)
f6c7c39981aa 8660 packagemanager traceback if PACKAGE_MANAGER_ROOT missing trailing '/'
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1087
diff changeset
   145
        svg_path = os.path.join(path, icon + ".png")
f6c7c39981aa 8660 packagemanager traceback if PACKAGE_MANAGER_ROOT missing trailing '/'
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1087
diff changeset
   146
        svg_exists = os.path.exists(png_path)
869
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   147
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   148
        if not png_exists and not svg_exists:
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   149
                return None
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   150
        try:
1137
f6c7c39981aa 8660 packagemanager traceback if PACKAGE_MANAGER_ROOT missing trailing '/'
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1087
diff changeset
   151
                return gtk.gdk.pixbuf_new_from_file(png_path)
869
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   152
        except gobject.GError:
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   153
                try:
1137
f6c7c39981aa 8660 packagemanager traceback if PACKAGE_MANAGER_ROOT missing trailing '/'
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1087
diff changeset
   154
                        return gtk.gdk.pixbuf_new_from_file(svg_path)
869
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   155
                except gobject.GError:
0197953cd88a 5398 UM not following steps consistently
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   156
                        return None
1137
f6c7c39981aa 8660 packagemanager traceback if PACKAGE_MANAGER_ROOT missing trailing '/'
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1087
diff changeset
   157
1164
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1141
diff changeset
   158
def get_icon(icon_theme, name, size=16):
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1141
diff changeset
   159
        try:
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1141
diff changeset
   160
                return icon_theme.load_icon(name, size, 0)
1217
1e2405e83d3a 9788 pylint errors in Package Manager and Update Manager should be fixed
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1168
diff changeset
   161
        except gobject.GError:
1164
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1141
diff changeset
   162
                return None
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1141
diff changeset
   163
1220
81379363d2ca 9889 Help doesn't work on UpdateManager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   164
def init_for_help(application_dir="/"):
1164
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1141
diff changeset
   165
        props = { gnome.PARAM_APP_DATADIR : os.path.join(application_dir,
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1141
diff changeset
   166
                    'usr/share/package-manager/help') }
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1141
diff changeset
   167
        gnome.program_init('package-manager', '0.1', properties=props)
1220
81379363d2ca 9889 Help doesn't work on UpdateManager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   168
81379363d2ca 9889 Help doesn't work on UpdateManager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   169
def display_help(help_id=None):
1217
1e2405e83d3a 9788 pylint errors in Package Manager and Update Manager should be fixed
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1168
diff changeset
   170
        if help_id != None:
1e2405e83d3a 9788 pylint errors in Package Manager and Update Manager should be fixed
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1168
diff changeset
   171
                gnome.help_display('package-manager', link_id=help_id)
1164
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1141
diff changeset
   172
        else:
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1141
diff changeset
   173
                gnome.help_display('package-manager')
942
cb2774668721 6707 Text change for Update Manager dialog
John Rice <john.rice@sun.com>
parents: 927
diff changeset
   174
1744
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   175
def add_pkgname_to_dic(dic, name, special_table):
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   176
        """Adds the original name of the package to the
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   177
        dictionary of names.
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   178
        
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   179
        'dic' is the dictionary, which holds all the names
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   180
        
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   181
        'name' is the original package name
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   182
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   183
        'special_table' table with special names. Special name is when the full name
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   184
        is part of another name. Example package/name another/package/name. package/name
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   185
        is the special name in this situation."""
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   186
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   187
        table = name.split("/")
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   188
        if len(table) == 1:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   189
                if table[0] in dic:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   190
                        return
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   191
                else:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   192
                        dic[table[0]] = {}
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   193
        table.reverse()
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   194
        i = 0
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   195
        j = len(table)
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   196
        for entry in table:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   197
                dictionary = dic.get(entry)
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   198
                if dictionary == None:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   199
                        dic[entry] = {}
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   200
                        i += 1
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   201
                dic = dic[entry]
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   202
        if i == 0 and j > 1:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   203
                special_table.append(name)
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   204
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   205
def __is_recursion_gr_then_one(dic):
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   206
        if not isinstance(dic, dict):
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   207
                return False
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   208
        keys = dic.keys()
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   209
        if len(keys) == 1:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   210
                return __is_recursion_gr_then_one(dic.get(keys[0]))
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   211
        elif len(keys) > 1:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   212
                return True
1031
5c130cc07e44 7037 GUI to cut last all but part of new Category Path
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 985
diff changeset
   213
        else:
1744
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   214
                return False
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   215
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   216
def get_minimal_unique_name(dic, name, special_table):
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   217
        name_table = name.split("/")
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   218
        len_name_table = len(name_table)
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   219
        if len_name_table == 1 and name_table[0] in dic:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   220
                # Special case. The name doesn't contain any "/"
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   221
                return name_table[0]
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   222
        elif len_name_table == 1:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   223
                return name
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   224
        max_special_level = 0
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   225
        for special_name in special_table:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   226
                if name.endswith(special_name):
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   227
                        level = len(special_name.split("/"))
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   228
                        if level > max_special_level:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   229
                                max_special_level = level
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   230
        for special_category in SPECIAL_CATEGORIES:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   231
                pos = name.find(special_category)
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   232
                if pos != -1:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   233
                        level = len(name[pos:].split("/"))
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   234
                        if level > max_special_level:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   235
                                max_special_level = level
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   236
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   237
        if len_name_table < max_special_level:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   238
                return name
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   239
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   240
        name_table.reverse()
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   241
        new_name = []
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   242
        i = 0
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   243
        for entry in name_table:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   244
                dictionary = dic.get(entry)
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   245
                recursion = __is_recursion_gr_then_one(dictionary)
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   246
                if dictionary and recursion:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   247
                        new_name.append(entry)
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   248
                        dic = dictionary
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   249
                        i += 1
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   250
                elif dictionary != None:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   251
                        new_name.append(entry)
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   252
                        dic = dictionary
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   253
                        i += 1
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   254
                        if i > max_special_level:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   255
                                break
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   256
        n = ""
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   257
        new_name.reverse()
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   258
        for part in new_name:
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   259
                n += part + "/"
04532a16c1ac 9437 current multi-part name algorithm is goofy
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1722
diff changeset
   260
        return n.strip("/")
1031
5c130cc07e44 7037 GUI to cut last all but part of new Category Path
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 985
diff changeset
   261
1168
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   262
def get_api_object(img_dir, progtrack, parent_dialog):
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   263
        api_o = None
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   264
        message = None
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   265
        try:
1336
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1271
diff changeset
   266
                api_o = ngao(img_dir, progtrack)
1168
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   267
        except api_errors.VersionException, ex:
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   268
                message = _("Version mismatch: expected version %d, got version %d") % \
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   269
                    (ex.expected_version, ex.received_version)
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   270
        except api_errors.ImageNotFoundException, ex:
1217
1e2405e83d3a 9788 pylint errors in Package Manager and Update Manager should be fixed
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1168
diff changeset
   271
                message = _("%s is not an install image") % ex.user_dir
1761
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   272
        except api_errors.ImageLockedError, ex:
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   273
                message = str(ex)
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   274
        except api_errors.ApiException, ex:
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   275
                message = _("An unknown error occurred") + "\n\n" + _("Error details:\n")
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   276
                message += str(ex)
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   277
        except Exception:
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   278
                traceback_lines = traceback.format_exc().splitlines()
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   279
                traceback_str = ""
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   280
                for line in traceback_lines:
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   281
                        traceback_str += line + "\n"
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   282
                message = _("An unknown error occurred")
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   283
                if traceback_str != "":
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   284
                        message += "\n\n" + _("Error details:\n") + traceback_str
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   285
        if api_o == None or message != None:
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   286
                if message == None:
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   287
                        message = _("An unknown error occurred")
b2d8237ac690 14481 Package version Info image lock exception not handled
John Rice <john.rice@sun.com>
parents: 1744
diff changeset
   288
                raise Exception(message)
1168
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   289
        return api_o
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   290
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   291
def error_occurred(parent, error_msg, msg_title = None,
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   292
    msg_type=gtk.MESSAGE_ERROR, use_markup = False):
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   293
        msgbox = gtk.MessageDialog(parent =
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   294
            parent,
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   295
            buttons = gtk.BUTTONS_CLOSE,
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   296
            flags = gtk.DIALOG_MODAL,
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   297
            type = msg_type,
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   298
            message_format = None)
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   299
        if use_markup:
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   300
                msgbox.set_markup(error_msg)
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   301
        else:
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   302
                msgbox.set_property('text', error_msg)
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   303
        if msg_title != None:
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   304
                title = msg_title
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   305
        else:
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   306
                title = _("Error")
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   307
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   308
        msgbox.set_title(title)
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   309
        msgbox.run()
6ca02b55d252 5197 gui should not manipulate image objects
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1164
diff changeset
   310
        msgbox.destroy()
1366
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   311
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   312
def set_package_details(pkg_name, local_info, remote_info, textview,
1566
367d13217341 9801 PM Manage Installed Packages
John Rice <john.rice@sun.com>
parents: 1550
diff changeset
   313
    installed_icon, not_installed_icon, update_available_icon, 
1696
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   314
    is_all_publishers_installed=None, pubs_info=None):
1366
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   315
        installed = True
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   316
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   317
        if not local_info:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   318
                # Package is not installed
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   319
                local_info = remote_info
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   320
                installed = False
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   321
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   322
        if not remote_info:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   323
                remote_info = local_info
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   324
                installed = True
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   325
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   326
        labs = {}
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   327
        labs["name"] = _("Name:")
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   328
        labs["desc"] = _("Description:")
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   329
        labs["size"] = _("Size:")
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   330
        labs["cat"] = _("Category:")
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   331
        labs["ins"] = _("Installed:")
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   332
        labs["available"] = _("Version Available:")
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   333
        labs["lat"] = _("Latest Version:")
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   334
        labs["repository"] = _("Publisher:")
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   335
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   336
        description = _("None")
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   337
        if local_info.summary:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   338
                description = local_info.summary
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   339
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   340
        text = {}
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   341
        text["name"] = pkg_name
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   342
        text["desc"] = description
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   343
        if installed:
1646
8d443e763338 13492 Latest Version looks wrong for packages with updates
John Rice <john.rice@sun.com>
parents: 1611
diff changeset
   344
                ver_text = _("%(version)s (Build %(build)s-%(branch)s)")
8d443e763338 13492 Latest Version looks wrong for packages with updates
John Rice <john.rice@sun.com>
parents: 1611
diff changeset
   345
                text["ins"] = ver_text % \
1381
1abf1c22cf33 11445 packagemanager does not display main package version string in General tab.
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1366
diff changeset
   346
                    {"version": local_info.version,
1abf1c22cf33 11445 packagemanager does not display main package version string in General tab.
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1366
diff changeset
   347
                    "build": local_info.build_release,
1abf1c22cf33 11445 packagemanager does not display main package version string in General tab.
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1366
diff changeset
   348
                    "branch": local_info.branch}
1550
14df4437e8d2 12101 Package version information dialog
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1516
diff changeset
   349
                labs["available"] =  _("Latest Version:")
1592
bb8305c64143 13320 Status indicates Updates Available, however General tab indicates No
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1573
diff changeset
   350
                if not same_pkg_versions(local_info, remote_info):
1646
8d443e763338 13492 Latest Version looks wrong for packages with updates
John Rice <john.rice@sun.com>
parents: 1611
diff changeset
   351
                        text["available"] = ver_text % \
1381
1abf1c22cf33 11445 packagemanager does not display main package version string in General tab.
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1366
diff changeset
   352
                            {"version": remote_info.version,
1abf1c22cf33 11445 packagemanager does not display main package version string in General tab.
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1366
diff changeset
   353
                            "build": remote_info.build_release,
1abf1c22cf33 11445 packagemanager does not display main package version string in General tab.
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1366
diff changeset
   354
                            "branch": remote_info.branch}
1366
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   355
                else:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   356
                        text["available"] = _("No")
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   357
        else:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   358
                text["ins"] = _("No")
1550
14df4437e8d2 12101 Package version information dialog
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1516
diff changeset
   359
                labs["available"] =  _("Latest Version:")
1381
1abf1c22cf33 11445 packagemanager does not display main package version string in General tab.
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1366
diff changeset
   360
                text["available"] = _(
1abf1c22cf33 11445 packagemanager does not display main package version string in General tab.
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1366
diff changeset
   361
                    "%(version)s (Build %(build)s-%(branch)s)") % \
1abf1c22cf33 11445 packagemanager does not display main package version string in General tab.
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1366
diff changeset
   362
                    {"version": remote_info.version,
1abf1c22cf33 11445 packagemanager does not display main package version string in General tab.
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1366
diff changeset
   363
                    "build": remote_info.build_release,
1abf1c22cf33 11445 packagemanager does not display main package version string in General tab.
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1366
diff changeset
   364
                    "branch": remote_info.branch}
1444
5cdbe05012bd 12105 Package with dependencies only should not show size in details
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1412
diff changeset
   365
        if local_info.size != 0:
5cdbe05012bd 12105 Package with dependencies only should not show size in details
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1412
diff changeset
   366
                text["size"] = misc.bytes_to_str(local_info.size)
5cdbe05012bd 12105 Package with dependencies only should not show size in details
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1412
diff changeset
   367
        else:
5cdbe05012bd 12105 Package with dependencies only should not show size in details
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1412
diff changeset
   368
                text["size"] = "0"
1366
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   369
        categories = _("None")
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   370
        if local_info.category_info_list:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   371
                verbose = len(local_info.category_info_list) > 1
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   372
                categories = ""
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   373
                categories += local_info.category_info_list[0].__str__(verbose)
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   374
                if len(local_info.category_info_list) > 1:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   375
                        for ci in local_info.category_info_list[1:]:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   376
                                categories += ", " + ci.__str__(verbose)
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   377
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   378
        text["cat"] = categories
1696
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   379
        pub_name = local_info.publisher
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   380
        if pubs_info != None:
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   381
                try:
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   382
                        item = pubs_info[local_info.publisher]
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   383
                except KeyError:
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   384
                        item = None
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   385
                if item:
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   386
                        alias = item[1]
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   387
                        if alias != None and len(alias) > 0:
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   388
                                pub_name = "%s (%s)" % (
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   389
                                    alias, local_info.publisher)
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   390
        text["repository"] = pub_name
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   391
        # pubs_info: dict of publisher disabled status and aliases:
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   392
        # pub_info[pub_name][0] = True disabled or False enabled
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   393
        # pub_info[pub_name][1] = Alias
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   394
        if is_all_publishers_installed and pubs_info != None:
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   395
                if local_info.publisher in pubs_info:
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   396
                        if pubs_info[local_info.publisher][0]:
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   397
                                text["repository"] = pub_name + \
1566
367d13217341 9801 PM Manage Installed Packages
John Rice <john.rice@sun.com>
parents: 1550
diff changeset
   398
                                _(" (disabled)")
367d13217341 9801 PM Manage Installed Packages
John Rice <john.rice@sun.com>
parents: 1550
diff changeset
   399
                else:
1696
36542108f3a7 14003 PM Publisher alias is not visible in the Publisher dropdown
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1675
diff changeset
   400
                        text["repository"] = pub_name + _(" (removed)")
1366
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   401
        set_package_details_text(labs, text, textview, installed_icon,
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   402
                not_installed_icon, update_available_icon)
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   403
        return (labs, text)
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   404
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   405
def set_package_details_text(labs, text, textview, installed_icon,
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   406
    not_installed_icon, update_available_icon):
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   407
        style = textview.get_style()
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   408
        font_size_in_pango_unit = style.font_desc.get_size()
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   409
        font_size_in_pixel = font_size_in_pango_unit / pango.SCALE
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   410
        tab_array = pango.TabArray(2, True)
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   411
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   412
        infobuffer = textview.get_buffer()
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   413
        infobuffer.set_text("")
1720
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   414
        max_test_len = 0
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   415
        for lab in labs:
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   416
                __add_label_to_generalinfo(infobuffer, 0, labs[lab])
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   417
                bounds = infobuffer.get_bounds()
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   418
                start = textview.get_iter_location(bounds[0])
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   419
                end = textview.get_iter_location(bounds[1])
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   420
                test_len = end[0] - start[0]
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   421
                if test_len > max_test_len:
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   422
                        max_test_len = test_len
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   423
                infobuffer.set_text("")
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   424
        tab_array.set_tab(1, pango.TAB_LEFT, max_test_len + font_size_in_pixel)
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   425
        textview.set_tabs(tab_array)
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   426
        infobuffer.set_text("")
1366
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   427
        i = 0
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   428
        __add_line_to_generalinfo(infobuffer, i, labs["name"], text["name"])
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   429
        i += 1
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   430
        __add_line_to_generalinfo(infobuffer, i, labs["desc"], text["desc"])
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   431
        i += 1
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   432
        installed = False
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   433
        if text["ins"] == _("No"):
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   434
                icon = not_installed_icon
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   435
        else:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   436
                icon = installed_icon
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   437
                installed = True
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   438
        __add_line_to_generalinfo(infobuffer, i, labs["ins"],
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   439
            text["ins"], icon, font_size_in_pixel)
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   440
        i += 1
1611
9545d7d75841 13443 Latest Version looks wrong for package without updates
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1603
diff changeset
   441
        if installed:
9545d7d75841 13443 Latest Version looks wrong for package without updates
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1603
diff changeset
   442
                if text["available"] != _("No"):
9545d7d75841 13443 Latest Version looks wrong for package without updates
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1603
diff changeset
   443
                        __add_line_to_generalinfo(infobuffer, i,
9545d7d75841 13443 Latest Version looks wrong for package without updates
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1603
diff changeset
   444
                            labs["available"], text["available"],
9545d7d75841 13443 Latest Version looks wrong for package without updates
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1603
diff changeset
   445
                            update_available_icon, font_size_in_pixel)
1366
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   446
        else:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   447
                __add_line_to_generalinfo(infobuffer, i,
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   448
                    labs["available"], text["available"])
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   449
        i += 1
1444
5cdbe05012bd 12105 Package with dependencies only should not show size in details
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1412
diff changeset
   450
        if text["size"] != "0":
5cdbe05012bd 12105 Package with dependencies only should not show size in details
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1412
diff changeset
   451
                __add_line_to_generalinfo(infobuffer, i, labs["size"], text["size"])
5cdbe05012bd 12105 Package with dependencies only should not show size in details
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1412
diff changeset
   452
                i += 1
1366
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   453
        __add_line_to_generalinfo(infobuffer, i, labs["cat"], text["cat"])
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   454
        i += 1
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   455
        __add_line_to_generalinfo(infobuffer, i, labs["repository"],
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   456
            text["repository"])
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   457
1720
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   458
def __add_label_to_generalinfo(text_buffer, index, label):
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   459
        itr = text_buffer.get_iter_at_line(index)
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   460
        text_buffer.insert_with_tags_by_name(itr, label, "bold")
6dad52face47 14233 Modify Publisher dialog is too wide
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1696
diff changeset
   461
1366
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   462
def __add_line_to_generalinfo(text_buffer, index, label, text,
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   463
    icon = None, font_size = 1):
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   464
        itr = text_buffer.get_iter_at_line(index)
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   465
        text_buffer.insert_with_tags_by_name(itr, label, "bold")
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   466
        end_itr = text_buffer.get_end_iter()
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   467
        if icon == None:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   468
                text_buffer.insert(end_itr, "\t%s\n" % text)
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   469
        else:
1412
c948dbc8a1a5 5321 package manager dependencies tab could show installation status
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1381
diff changeset
   470
                resized_icon = resize_icon(icon, font_size)
1458
a6f813dbcc3e 12100 Update icons for next release of OpenSolaris
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1456
diff changeset
   471
                text_buffer.insert(end_itr, "\t")
1366
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   472
                text_buffer.get_end_iter()
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   473
                text_buffer.insert_pixbuf(end_itr, resized_icon)
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   474
                text_buffer.insert(end_itr, " %s\n" % text)
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   475
1592
bb8305c64143 13320 Status indicates Updates Available, however General tab indicates No
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1573
diff changeset
   476
def same_pkg_versions(info1, info2):
bb8305c64143 13320 Status indicates Updates Available, however General tab indicates No
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1573
diff changeset
   477
        if info1 == None or info2 == None:
bb8305c64143 13320 Status indicates Updates Available, however General tab indicates No
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1573
diff changeset
   478
                return False
bb8305c64143 13320 Status indicates Updates Available, however General tab indicates No
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1573
diff changeset
   479
bb8305c64143 13320 Status indicates Updates Available, however General tab indicates No
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1573
diff changeset
   480
        return info1.version == info2.version and \
bb8305c64143 13320 Status indicates Updates Available, however General tab indicates No
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1573
diff changeset
   481
                info1.build_release == info2.build_release and \
bb8305c64143 13320 Status indicates Updates Available, however General tab indicates No
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1573
diff changeset
   482
                info1.branch == info2.branch
bb8305c64143 13320 Status indicates Updates Available, however General tab indicates No
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1573
diff changeset
   483
1412
c948dbc8a1a5 5321 package manager dependencies tab could show installation status
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1381
diff changeset
   484
def resize_icon(icon, font_size):
c948dbc8a1a5 5321 package manager dependencies tab could show installation status
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1381
diff changeset
   485
        width = icon.get_width()
c948dbc8a1a5 5321 package manager dependencies tab could show installation status
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1381
diff changeset
   486
        height = icon.get_height()
c948dbc8a1a5 5321 package manager dependencies tab could show installation status
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1381
diff changeset
   487
        return icon.scale_simple(
c948dbc8a1a5 5321 package manager dependencies tab could show installation status
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1381
diff changeset
   488
            (font_size * width) / height,
c948dbc8a1a5 5321 package manager dependencies tab could show installation status
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1381
diff changeset
   489
            font_size,
c948dbc8a1a5 5321 package manager dependencies tab could show installation status
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1381
diff changeset
   490
            gtk.gdk.INTERP_BILINEAR)
c948dbc8a1a5 5321 package manager dependencies tab could show installation status
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1381
diff changeset
   491
1675
8caa149137be 13975 Transport errors should be logged rather than displayed in a dialog
John Rice <john.rice@sun.com>
parents: 1667
diff changeset
   492
def get_pkg_info(app, api_o, pkg_stem, local):
1366
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   493
        info = None
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   494
        try:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   495
                info = api_o.info([pkg_stem], local,
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   496
                    api.PackageInfo.ALL_OPTIONS -
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   497
                    frozenset([api.PackageInfo.LICENSES]))
1722
e6721cb76674 14281 packagemanager doesn't catch ApiException when showing info
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1720
diff changeset
   498
        except api_errors.ApiException, ex:
e6721cb76674 14281 packagemanager doesn't catch ApiException when showing info
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1720
diff changeset
   499
                err = str(ex)
1675
8caa149137be 13975 Transport errors should be logged rather than displayed in a dialog
John Rice <john.rice@sun.com>
parents: 1667
diff changeset
   500
                logger.error(err)
8caa149137be 13975 Transport errors should be logged rather than displayed in a dialog
John Rice <john.rice@sun.com>
parents: 1667
diff changeset
   501
                notify_log_error(app)
1456
9eb0d782440f 12295 Package Manager does not deal properly with getting descriptions if no connection
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1446
diff changeset
   502
                return info
9eb0d782440f 12295 Package Manager does not deal properly with getting descriptions if no connection
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1446
diff changeset
   503
 
1366
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   504
        pkgs_info = None
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   505
        package_info = None
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   506
        if info:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   507
                pkgs_info = info[0]
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   508
        if pkgs_info:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   509
                package_info = pkgs_info[0]
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   510
        if package_info:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   511
                return package_info
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   512
        else:
23cf80f57e61 11163 Rework needed for details panel for Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1336
diff changeset
   513
                return None
1469
30f9e05c523d 12458 Webinstall sub dialogs not getting focus
John Rice <john.rice@sun.com>
parents: 1458
diff changeset
   514
1487
2c36e9347c4f 12099 Change the be rename sequence in Update All.
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1482
diff changeset
   515
def restart_system():
2c36e9347c4f 12099 Change the be rename sequence in Update All.
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1482
diff changeset
   516
        # "init 6" performs reboot in a clean and orderly manner informing
2c36e9347c4f 12099 Change the be rename sequence in Update All.
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1482
diff changeset
   517
        # the svc.startd daemon of the change in runlevel which subsequently
2c36e9347c4f 12099 Change the be rename sequence in Update All.
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1482
diff changeset
   518
        # achieves the appropriate milestone and ultimately executes
2c36e9347c4f 12099 Change the be rename sequence in Update All.
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1482
diff changeset
   519
        # the rc0 kill scripts.
2c36e9347c4f 12099 Change the be rename sequence in Update All.
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1482
diff changeset
   520
        command = "init 6"
2c36e9347c4f 12099 Change the be rename sequence in Update All.
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1482
diff changeset
   521
        return os.system(command)
2c36e9347c4f 12099 Change the be rename sequence in Update All.
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1482
diff changeset
   522
1469
30f9e05c523d 12458 Webinstall sub dialogs not getting focus
John Rice <john.rice@sun.com>
parents: 1458
diff changeset
   523
def set_modal_and_transient(top_window, parent_window = None):
30f9e05c523d 12458 Webinstall sub dialogs not getting focus
John Rice <john.rice@sun.com>
parents: 1458
diff changeset
   524
        if parent_window:
30f9e05c523d 12458 Webinstall sub dialogs not getting focus
John Rice <john.rice@sun.com>
parents: 1458
diff changeset
   525
                top_window.set_transient_for(parent_window)
30f9e05c523d 12458 Webinstall sub dialogs not getting focus
John Rice <john.rice@sun.com>
parents: 1458
diff changeset
   526
        top_window.set_modal(True)
1478
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   527
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   528
def get_catalogrefresh_exception_msg(cre):
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   529
        if not isinstance(cre, api_errors.CatalogRefreshException):
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   530
                return ""
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   531
        msg = _("Catalog refresh error:\n")
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   532
        if cre.succeeded < cre.total:
1597
cad7238f86d9 13431 translatable message should use mapping to enable swap of parameters (GUI part)
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1592
diff changeset
   533
                msg += _(
cad7238f86d9 13431 translatable message should use mapping to enable swap of parameters (GUI part)
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1592
diff changeset
   534
                    "Only %(suc)s out of %(tot)s catalogs successfully updated.\n") % \
cad7238f86d9 13431 translatable message should use mapping to enable swap of parameters (GUI part)
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1592
diff changeset
   535
                    {"suc": cre.succeeded, "tot": cre.total}
1478
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   536
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   537
        for pub, err in cre.failed:
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   538
                if isinstance(err, urllib2.HTTPError):
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   539
                        msg += "%s: %s - %s" % \
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   540
                            (err.filename, err.code, err.msg)
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   541
                elif isinstance(err, urllib2.URLError):
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   542
                        if err.args[0][0] == 8:
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   543
                                msg += "%s: %s" % \
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   544
                                    (urlparse.urlsplit(
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   545
                                        pub["origin"])[1].split(":")[0],
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   546
                                    err.args[0][1])
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   547
                        else:
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   548
                                if isinstance(err.args[0], socket.timeout):
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   549
                                        msg += "%s: %s" % \
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   550
                                            (pub["origin"], "timeout")
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   551
                                else:
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   552
                                        msg += "%s: %s" % \
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   553
                                            (pub["origin"], err.args[0][1])
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   554
                else:
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   555
                        msg += str(err)
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   556
1603
84bd53597209 13019 DeprecationWarnings seen after python 2.6 migration
Dan Price <dp@eng.sun.com>
parents: 1597
diff changeset
   557
        if cre.errmessage:
84bd53597209 13019 DeprecationWarnings seen after python 2.6 migration
Dan Price <dp@eng.sun.com>
parents: 1597
diff changeset
   558
                msg += cre.errmessage
1478
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   559
1e51eaebc8ee 12178 PM support Export Selections in .p5i format
John Rice <john.rice@sun.com>
parents: 1469
diff changeset
   560
        return msg
1482
db83e3f4b9aa 12457 Inconsistency with icons in buttons
John Rice <john.rice@sun.com>
parents: 1478
diff changeset
   561
1647
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   562
def __get_stockbutton_label(button):
1482
db83e3f4b9aa 12457 Inconsistency with icons in buttons
John Rice <john.rice@sun.com>
parents: 1478
diff changeset
   563
        # Gtk.Button->Gtk.Alignment->Gtk.HBox->[Gtk.Image, Gtk.Label]
db83e3f4b9aa 12457 Inconsistency with icons in buttons
John Rice <john.rice@sun.com>
parents: 1478
diff changeset
   564
        # Drill into Button widget to get Gtk.Label and set its text
db83e3f4b9aa 12457 Inconsistency with icons in buttons
John Rice <john.rice@sun.com>
parents: 1478
diff changeset
   565
        children = button.get_children()
db83e3f4b9aa 12457 Inconsistency with icons in buttons
John Rice <john.rice@sun.com>
parents: 1478
diff changeset
   566
        if len(children) == 0:
1647
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   567
                return None
1482
db83e3f4b9aa 12457 Inconsistency with icons in buttons
John Rice <john.rice@sun.com>
parents: 1478
diff changeset
   568
        align = children[0]
db83e3f4b9aa 12457 Inconsistency with icons in buttons
John Rice <john.rice@sun.com>
parents: 1478
diff changeset
   569
        if not align or not isinstance(align, gtk.Alignment):
1647
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   570
                return None
1482
db83e3f4b9aa 12457 Inconsistency with icons in buttons
John Rice <john.rice@sun.com>
parents: 1478
diff changeset
   571
        children = align.get_children()
db83e3f4b9aa 12457 Inconsistency with icons in buttons
John Rice <john.rice@sun.com>
parents: 1478
diff changeset
   572
        if len(children) == 0:
1647
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   573
                return None
1482
db83e3f4b9aa 12457 Inconsistency with icons in buttons
John Rice <john.rice@sun.com>
parents: 1478
diff changeset
   574
        hbox = children[0]
db83e3f4b9aa 12457 Inconsistency with icons in buttons
John Rice <john.rice@sun.com>
parents: 1478
diff changeset
   575
        if not hbox or not isinstance(hbox, gtk.HBox):
1647
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   576
                return None
1482
db83e3f4b9aa 12457 Inconsistency with icons in buttons
John Rice <john.rice@sun.com>
parents: 1478
diff changeset
   577
        children = hbox.get_children()
db83e3f4b9aa 12457 Inconsistency with icons in buttons
John Rice <john.rice@sun.com>
parents: 1478
diff changeset
   578
        if not (len(children) > 1):
1647
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   579
                return None
1482
db83e3f4b9aa 12457 Inconsistency with icons in buttons
John Rice <john.rice@sun.com>
parents: 1478
diff changeset
   580
        button_label = children[1]
db83e3f4b9aa 12457 Inconsistency with icons in buttons
John Rice <john.rice@sun.com>
parents: 1478
diff changeset
   581
        if not button_label or not isinstance(button_label, gtk.Label):
1647
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   582
                return None
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   583
        return button_label
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   584
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   585
def get_stockbutton_label_label(button):
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   586
        button_label = __get_stockbutton_label(button)
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   587
        if button_label != None:
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   588
                return button_label.get_label()
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   589
        else:
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   590
                return None
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   591
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   592
def change_stockbutton_label(button, text):
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   593
        button_label = __get_stockbutton_label(button)
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   594
        if button_label != None:
ac0345b3ef83 5732 packagemanager should have support for click-thru license
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1646
diff changeset
   595
                button_label.set_label(text)