src/gui/modules/misc_non_gui.py
author Padraig O'Briain <padraig.obriain@sun.com>
Thu, 25 Feb 2010 11:45:01 +0000
changeset 1788 e43ea4447c6b
parent 1736 727dda1e7968
child 1795 1b3bed835773
permissions -rw-r--r--
14699 packagemanager traceback during cache load
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: 1505
diff changeset
     1
#!/usr/bin/python
1336
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     2
#
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     3
# CDDL HEADER START
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     4
#
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     8
#
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    12
# and limitations under the License.
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    13
#
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    19
#
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    20
# CDDL HEADER END
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
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.
1336
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    23
# Use is subject to license terms.
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    24
#
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    25
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    26
import os
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    27
import cPickle
1573
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    28
import logging
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    29
import logging.handlers
1585
fe17b1cf5774 13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1573
diff changeset
    30
import sys
1336
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    31
1649
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1618
diff changeset
    32
import pkg
1336
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    33
import pkg.client.api as api
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    34
from pkg.client import global_settings
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    35
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    36
# The current version of the Client API the PM, UM and
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    37
# WebInstall GUIs have been tested against and are known to work with.
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
    38
CLIENT_API_VERSION = 32
1650
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    39
LOG_DIR = "/var/tmp"
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    40
LOG_ERROR_EXT = "_error.log"
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    41
LOG_INFO_EXT = "_info.log"
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    42
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    43
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
    44
        return 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
    45
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    46
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
    47
        return 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
    48
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    49
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
    50
        return LOG_INFO_EXT
1336
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    51
1573
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    52
class _LogFilter(logging.Filter):
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    53
        def __init__(self, max_level=logging.CRITICAL):
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    54
                logging.Filter.__init__(self)
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    55
                self.max_level = max_level
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    56
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    57
        def filter(self, record):
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    58
                return record.levelno <= self.max_level
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    59
1649
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1618
diff changeset
    60
def get_version():
aab234a49e34 13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents: 1618
diff changeset
    61
        return pkg.VERSION
1573
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    62
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    63
def setup_logging(client_name):
1650
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    64
        log_path = os.path.join(LOG_DIR, client_name)
1573
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    65
        log_fmt = logging.Formatter(
1650
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    66
            "<b>%(levelname)s:</b> " + client_name + \
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    67
            "\n%(asctime)s: %(filename)s: %(module)s: %(lineno)s:\n%(message)s")
1573
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    68
1650
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    69
        infolog_path = log_path + LOG_INFO_EXT
1585
fe17b1cf5774 13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1573
diff changeset
    70
        try:
1650
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    71
                info_h = logging.handlers.RotatingFileHandler(infolog_path,
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    72
                    maxBytes=1000000, backupCount=1)
1585
fe17b1cf5774 13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1573
diff changeset
    73
        except IOError:
fe17b1cf5774 13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1573
diff changeset
    74
                info_h = logging.StreamHandler(sys.stdout)
fe17b1cf5774 13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1573
diff changeset
    75
1573
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    76
        info_t = _LogFilter(logging.INFO)
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    77
        info_h.addFilter(info_t)
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    78
        info_h.setFormatter(log_fmt)
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    79
        info_h.setLevel(logging.INFO)
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    80
        global_settings.info_log_handler = info_h
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    81
1650
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    82
        errlog_path = log_path + LOG_ERROR_EXT
1585
fe17b1cf5774 13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1573
diff changeset
    83
        try:
1650
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    84
                err_h = logging.handlers.RotatingFileHandler(errlog_path,
4538ffc7c034 13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents: 1649
diff changeset
    85
                    maxBytes=1000000, backupCount=1)
1585
fe17b1cf5774 13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1573
diff changeset
    86
        except IOError:
fe17b1cf5774 13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1573
diff changeset
    87
                err_h = logging.StreamHandler(sys.stderr)
fe17b1cf5774 13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 1573
diff changeset
    88
1573
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    89
        err_h.setFormatter(log_fmt)
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    90
        err_h.setLevel(logging.WARNING)
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    91
        global_settings.error_log_handler = err_h
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    92
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    93
def shutdown_logging():
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    94
        global_settings.reset_logging()
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    95
        logging.shutdown()
ae7488fbff6a 12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents: 1538
diff changeset
    96
1336
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    97
def get_cache_dir(api_object):
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    98
        img = api_object.img
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    99
        cache_dir = os.path.join(img.imgdir, "gui_cache")
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   100
        try:
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   101
                __mkdir(cache_dir)
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   102
        except OSError:
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   103
                cache_dir = None
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   104
        return cache_dir
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   105
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   106
def __mkdir(directory_path):
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   107
        if not os.path.isdir(directory_path):
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   108
                os.makedirs(directory_path)
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   109
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   110
def get_api_object(img_dir, progtrack):
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   111
        api_o = None
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   112
        api_o = api.ImageInterface(img_dir,
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   113
            CLIENT_API_VERSION,
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   114
            progtrack, None, global_settings.client_name)
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   115
        return api_o
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   116
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   117
def read_cache_file(file_path):
1686
c3ce86de2702 13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents: 1685
diff changeset
   118
        data = []
c3ce86de2702 13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents: 1685
diff changeset
   119
        try:
c3ce86de2702 13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents: 1685
diff changeset
   120
                fh = open(file_path, 'r')
c3ce86de2702 13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents: 1685
diff changeset
   121
                data = cPickle.load(fh)
c3ce86de2702 13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents: 1685
diff changeset
   122
                fh.close()
1788
e43ea4447c6b 14699 packagemanager traceback during cache load
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1736
diff changeset
   123
        except:
1686
c3ce86de2702 13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents: 1685
diff changeset
   124
                pass
1336
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   125
        return data
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   126
2ea22dad29e3 10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   127
def dump_cache_file(file_path, data):
1686
c3ce86de2702 13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents: 1685
diff changeset
   128
        try:
c3ce86de2702 13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents: 1685
diff changeset
   129
                fh = open(file_path,"w")
c3ce86de2702 13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents: 1685
diff changeset
   130
                cPickle.dump(data, fh, True)
c3ce86de2702 13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents: 1685
diff changeset
   131
                fh.close()
1788
e43ea4447c6b 14699 packagemanager traceback during cache load
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1736
diff changeset
   132
        except:
1686
c3ce86de2702 13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents: 1685
diff changeset
   133
                pass