src/checkforupdates.py
author Padraig O'Briain <padraig.obriain@sun.com>
Thu, 16 Jul 2009 18:19:39 +0100
changeset 1228 07ef6e279231
parent 1217 1e2405e83d3a
child 1277 fb41b4b4c476
permissions -rw-r--r--
9852 UMN and PM check for updates should use plan_update_all
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     1
#!/usr/bin/python2.4 
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     2
# 
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     3
# CDDL HEADER START 
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     4
# 
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the 
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").  
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.  
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     8
#
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    12
# and limitations under the License.
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    13
#
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    19
#
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    20
# CDDL HEADER END
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    21
#
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    22
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    23
# Use is subject to license terms.
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    24
#
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    25
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    26
import os
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    27
import sys
1228
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    28
import time
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    29
import getopt
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    30
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    31
import pkg.client.progress as progress
1228
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    32
import pkg.client.api_errors as api_errors
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    33
import pkg.gui.misc as gui_misc
1228
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    34
import pkg.gui.enumerations as enumerations
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    35
from pkg.client import global_settings
1228
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    36
from cPickle import UnpicklingError
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    37
1228
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    38
PKG_CLIENT_NAME = "check_for_updates"
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    39
CACHE_VERSION =  1
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    40
CACHE_NAME = ".last_refresh_cache"
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    41
1228
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    42
def __check_for_updates(image_directory, nice):
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    43
        if nice:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    44
                os.nice(20)
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    45
        global_settings.client_name = PKG_CLIENT_NAME
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    46
        pr = progress.NullProgressTracker()
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    47
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    48
        api_obj = gui_misc.get_api_object(image_directory, pr, None)
1228
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    49
        if api_obj == None:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    50
                return enumerations.UPDATES_UNDETERMINED
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    51
        ret = __check_last_refresh(api_obj)
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    52
        if ret != enumerations.UPDATES_UNDETERMINED:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    53
                return ret
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    54
        elif debug:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    55
                print "Updates undetermined in check_last_refresh"
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    56
1228
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    57
        try:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    58
                stuff_to_do, opensolaris_image, cre = \
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    59
                    api_obj.plan_update_all(sys.argv[0],
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    60
                    refresh_catalogs = True,
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    61
                    noexecute = True, force = True, verbose = False) 
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    62
        except api_errors.ApiException, e:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    63
                if debug:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    64
                        print "Exception occurred: ", str(e)
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    65
                return enumerations.UPDATES_UNDETERMINED
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    66
        if debug:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    67
                print "stuff_to_do: ", stuff_to_do
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    68
                print "opensolaris_image: ", opensolaris_image
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    69
                print "cre: ", cre
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    70
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    71
        if cre and not cre.succeeded:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    72
                if debug:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    73
                        print "Error occurred in plan_update_all"
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    74
                return enumerations.UPDATES_UNDETERMINED
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    75
        __dump_updates_available(api_obj, stuff_to_do)
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    76
        if stuff_to_do:
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    77
                if debug:
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    78
                        print "Updates Available"
1228
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    79
                return enumerations.UPDATES_AVAILABLE
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    80
        else:
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    81
                if debug:
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
    82
                        print "No updates Available"
1228
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    83
                return enumerations.NO_UPDATES_AVAILABLE
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    84
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    85
def __check_last_refresh(api_obj):
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    86
        cache_dir = gui_misc.get_cache_dir(api_obj)
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    87
        if not cache_dir:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    88
                return enumerations.UPDATES_UNDETERMINED
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    89
        try:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    90
                info = gui_misc.read_cache_file(os.path.join(
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    91
                    cache_dir, CACHE_NAME + '.cpl'))
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    92
                if info.get("version") != CACHE_VERSION:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    93
                        return enumerations.UPDATES_UNDETERMINED
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    94
                old_publishers = info.get("publishers")
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    95
                count = 0
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    96
                for p in api_obj.get_publishers():
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    97
                        if p.disabled:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    98
                                continue
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
    99
                        try:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   100
                                if old_publishers[p.prefix] != p.last_refreshed:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   101
                                        return enumerations.UPDATES_UNDETERMINED
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   102
                        except KeyError:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   103
                                return enumerations.UPDATES_UNDETERMINED
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   104
                        count += 1
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   105
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   106
                if count != len(old_publishers):
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   107
                        return enumerations.UPDATES_UNDETERMINED
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   108
                if info.get("updates_available"):
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   109
                        return enumerations.UPDATES_AVAILABLE
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   110
                else:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   111
                        return enumerations.NO_UPDATES_AVAILABLE
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   112
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   113
        except (UnpicklingError, IOError):
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   114
                return enumerations.UPDATES_UNDETERMINED
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   115
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   116
def __dump_updates_available(api_obj, stuff_to_do):
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   117
        cache_dir = gui_misc.get_cache_dir(api_obj)
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   118
        if not cache_dir:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   119
                return
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   120
        publisher_list = {}
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   121
        for p in api_obj.get_publishers():
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   122
                if p.disabled:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   123
                        continue
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   124
                publisher_list[p.prefix] = p.last_refreshed
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   125
        if debug:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   126
                print "publisher_list:", publisher_list
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   127
        dump_info = {}
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   128
        dump_info["version"] = CACHE_VERSION
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   129
        dump_info["updates_available"] = stuff_to_do
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   130
        dump_info["publishers"] = publisher_list
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   131
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   132
        try:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   133
                gui_misc.dump_cache_file(os.path.join(
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   134
                    cache_dir, CACHE_NAME + '.cpl'), dump_info)
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   135
        except IOError, e:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   136
                if debug:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   137
                        print "Failed to dump cache: %s" % str(e)
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   138
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   139
        return
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   140
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   141
###############################################################################
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   142
#-----------------------------------------------------------------------------#
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   143
# Main
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   144
#-----------------------------------------------------------------------------#
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   145
1228
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   146
def main(image_directory, nice):
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   147
        return __check_for_updates(image_directory, nice)
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   148
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   149
if __name__ == '__main__':
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff changeset
   150
        debug = False
1228
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   151
        set_nice = False
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   152
        try:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   153
                opts, pargs = getopt.getopt(sys.argv[1:], "n", ["nice"])
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   154
        except getopt.GetoptError, ex:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   155
                print "Usage: illegal option -- %s" % ex.opt
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   156
                sys.exit(enumerations.UPDATES_UNDETERMINED)
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   157
        if len(pargs) != 1:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   158
                print "Usage: One argument, image directory must be specified"
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   159
                sys.exit(enumerations.UPDATES_UNDETERMINED)
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   160
        image_dir = pargs[0]
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   161
        for opt, args in opts:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   162
                if debug:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   163
                        print "opt: ", opt
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   164
                        print "args: ", args
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   165
                if opt in ( "-n", "--nice"):
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   166
                        set_nice = True
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   167
        if debug:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   168
                print "Start check_for_updates for: ", image_dir, set_nice
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   169
                a = time.time()
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   170
        return_value = main(image_dir, set_nice)
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   171
        if debug:
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   172
                print "time taken: ", time.time() - a
07ef6e279231 9852 UMN and PM check for updates should use plan_update_all
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1217
diff changeset
   173
        sys.exit(return_value)