src/updatemanagernotifier.py
author Padraig O'Briain <padraig.obriain@sun.com>
Fri, 02 Jan 2009 08:32:07 +0000
changeset 810 4f4620272b7a
parent 808 6c89385ac9ff
child 1024 e83271f2e133
permissions -rw-r--r--
5263 UMN notification icon inconsistent behavior
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
     1
#!/usr/bin/python2.4 
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
     2
# 
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
     3
# CDDL HEADER START 
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
     4
# 
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the 
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").  
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.  
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
     8
#
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    12
# and limitations under the License.
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    13
#
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    19
#
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    20
# CDDL HEADER END
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    21
#
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    22
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    23
# Use is subject to license terms.
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    24
#
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    25
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    26
import os
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    27
import errno
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    28
import sys
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    29
import time
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    30
import socket
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    31
import locale
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    32
import gettext
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    33
import getopt
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    34
try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    35
        import gobject
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    36
        gobject.threads_init()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    37
        import gconf
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    38
        import gtk
675
6dbb72c42ff4 4549 UMNotifier missing gtk.glade import
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 660
diff changeset
    39
        import gtk.glade
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    40
        import pygtk
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    41
        pygtk.require("2.0")
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    42
except ImportError:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    43
        sys.exit(1)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    44
try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    45
        import pynotify
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    46
except ImportError:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    47
        print "SUNWpython-notify package must be installed"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    48
        sys.exit(1)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    49
import pkg.client.image as image
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    50
import pkg.client.progress as progress
791
123e9401e939 5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents: 766
diff changeset
    51
import pkg.misc as misc
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    52
660
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    53
# Put _() in the global namespace
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    54
import __builtin__
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    55
__builtin__._ = gettext.gettext
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    56
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    57
START_DELAY_DEFAULT = 120
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    58
REFRESH_PERIOD_DEFAULT = "Never"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    59
SHOW_NOTIFY_ICON_DEFAULT = True
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    60
IMAGE_DIRECTORY_DEFAULT = "/"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    61
LASTCHECK_DIR_NAME = os.path.expanduser("~") + '/.updatemanager/notify/'
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    62
IMAGE_DIR_COMMAND = "svcprop -p update/image_dir svc:/application/pkg/update"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    63
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    64
NOTIFY_ICON_PATH = "/usr/share/icons/update-manager/notify_update.png"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    65
GKSU_PATH = "/usr/bin/gksu"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    66
UPDATEMANAGER = "updatemanager"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    67
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
    68
UPDATEMANAGER_PREFERENCES = "/apps/updatemanager/preferences"
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    69
START_DELAY_PREFERENCES = "/apps/updatemanager/preferences/start_delay"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    70
REFRESH_PERIOD_PREFERENCES = "/apps/updatemanager/preferences/refresh_period"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    71
SHOW_NOTIFY_MESSAGE_PREFERENCES = "/apps/updatemanager/preferences/show_notify_message"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    72
SHOW_ICON_ON_STARTUP_PREFERENCES = "/apps/updatemanager/preferences/show_icon_on_startup"
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
    73
TERMINATE_AFTER_ICON_ACTIVATE_PREFERENCES = \
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
    74
    "/apps/updatemanager/preferences/terminate_after_icon_activate"
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    75
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    76
DAILY = "Daily"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    77
WEEKLY = "Weekly"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    78
MONTHLY = "Monthly"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    79
NEVER = "Never"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    80
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    81
DAILY_SECS = 24*60*60
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    82
WEEKLY_SECS = 7*24*60*60
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    83
# We asssume that a month has 30 days
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    84
MONTHLY_SECS = 30*24*60*60
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
    85
NEVER_SECS = 365*24*60*60
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    86
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    87
class UpdateManagerNotifier:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    88
        def __init__(self):
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
    89
                os.nice(20)
660
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    90
                try:
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    91
                        self.application_dir = os.environ["UPDATE_MANAGER_NOTIFIER_ROOT"]
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    92
                except KeyError:
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    93
                        self.application_dir = "/"
791
123e9401e939 5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents: 766
diff changeset
    94
                misc.setlocale(locale.LC_ALL, "")
660
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    95
                for module in (gettext, gtk.glade):
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    96
                        module.bindtextdomain("pkg", self.application_dir + \
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    97
                            "/usr/share/locale")
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    98
                        module.textdomain("pkg")
603
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
    99
                self.pr = None
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   100
                self.last_check_filename = None
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   101
                self.time_until_next_check = 0
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   102
                self.status_icon = None
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   103
                self.notify = None
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   104
                self.host = None
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   105
                self.last_check_time = 0
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   106
                self.refresh_period = 0
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   107
                self.timeout_id = 0
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   108
                self.terminate_after_activate = False
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   109
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   110
                self.client = gconf.client_get_default()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   111
                self.start_delay  =  self.get_start_delay()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   112
                # Allow gtk.main loop to start as quickly as possible
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   113
                gobject.timeout_add(self.start_delay * 1000, self.check_and_start)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   114
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   115
        def check_and_start(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   116
                self.check_already_running()
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   117
                self.client.add_dir(UPDATEMANAGER_PREFERENCES, 
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   118
                    gconf.CLIENT_PRELOAD_NONE)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   119
                self.client.notify_add(REFRESH_PERIOD_PREFERENCES, 
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   120
                    self.refresh_period_changed)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   121
                self.client.notify_add(SHOW_ICON_ON_STARTUP_PREFERENCES, 
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   122
                    self.show_icon_changed)
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   123
                self.refresh_period  =  self.get_refresh_period()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   124
                self.host = socket.gethostname()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   125
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   126
                self.last_check_time = self.get_last_check_time()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   127
                self.pr = progress.NullProgressTracker()
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   128
                if self.get_show_icon_on_startup():
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   129
                        self.client.set_bool(SHOW_ICON_ON_STARTUP_PREFERENCES, False)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   130
                        gobject.idle_add(self.check_for_updates)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   131
                else:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   132
                        gobject.idle_add(self.do_next_check)
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   133
                return False
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   134
                
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   135
        def refresh_period_changed(self, client, connection_id, entry, arguments):
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   136
                old_delta = self.get_delta_for_refresh_period()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   137
                if entry.get_value().type == gconf.VALUE_STRING:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   138
                        self.refresh_period = entry.get_value().get_string()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   139
                new_delta = self.get_delta_for_refresh_period()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   140
                if debug == True:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   141
                        print "old_delta %d" % old_delta
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   142
                        print "new_delta %d" % new_delta
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   143
                if old_delta > new_delta:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   144
                        if self.timeout_id > 0:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   145
                                gobject.source_remove(self.timeout_id)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   146
                                self.timeout_id = 0
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   147
                        self.do_next_check()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   148
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   149
        def show_icon_changed(self, client, connection_id, entry, arguments):
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   150
                if entry.get_value().type == gconf.VALUE_BOOL:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   151
                        show_icon = entry.get_value().get_bool()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   152
                if self.status_icon != None:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   153
                        self.status_icon.set_visible(show_icon)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   154
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   155
        def get_start_delay(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   156
                start_delay  =  self.client.get_int(START_DELAY_PREFERENCES)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   157
                if start_delay == 0:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   158
                        start_delay = START_DELAY_DEFAULT
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   159
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   160
                        print "start_delay: %d" % start_delay
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   161
                return start_delay
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   162
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   163
        def get_refresh_period(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   164
                refresh_period  =  self.client.get_string(REFRESH_PERIOD_PREFERENCES)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   165
                if refresh_period == None:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   166
                        refresh_period = REFRESH_PERIOD_DEFAULT
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   167
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   168
                        print "refresh_period: %s" % refresh_period
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   169
                return refresh_period
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   170
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   171
        def get_show_notify_message(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   172
                show_notify_message  =  \
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   173
                        self.client.get_bool(SHOW_NOTIFY_MESSAGE_PREFERENCES)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   174
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   175
                        print "show_notify_message: %d" % show_notify_message
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   176
                return show_notify_message
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   177
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   178
        def get_show_icon_on_startup(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   179
                show_icon_on_startup  =  \
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   180
                        self.client.get_bool(SHOW_ICON_ON_STARTUP_PREFERENCES)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   181
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   182
                        print "show_icon_on_startup: %d" % show_icon_on_startup
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   183
                return show_icon_on_startup
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   184
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   185
        def get_terminate_after_activate(self):
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   186
                terminate_after_activate  =  \
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   187
                        self.client.get_bool(TERMINATE_AFTER_ICON_ACTIVATE_PREFERENCES)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   188
                if debug == True:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   189
                        print "terminate_after_activate: %d" % terminate_after_activate
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   190
                return terminate_after_activate
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   191
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   192
        def get_last_check_time(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   193
                if (self.last_check_filename == None):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   194
                        self.last_check_filename = \
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   195
                                LASTCHECK_DIR_NAME + self.host + '-lastcheck'
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   196
                try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   197
                        f = open(self.last_check_filename, "r")
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   198
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   199
                        try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   200
                                return float(f.read(64))
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   201
                        finally:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   202
                                f.close()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   203
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   204
                except IOError, strerror:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   205
                        if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   206
                                print "Unable to get last check time error %s" % strerror
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   207
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   208
                return 0
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   209
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   210
        def set_last_check_time(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   211
                self.last_check_time = time.time()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   212
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   213
                try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   214
                        os.makedirs(LASTCHECK_DIR_NAME)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   215
                except os.error, eargs:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   216
                        if eargs[0] != errno.EEXIST: # File exists
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   217
                                raise os.error, args
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   218
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   219
                try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   220
                        f = open(self.last_check_filename, "w")
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   221
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   222
                        try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   223
                                f.write(str(self.last_check_time))
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   224
                        finally:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   225
                                f.close()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   226
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   227
                except IOError, strerror:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   228
                        print "I/O error: %s opening %s" \
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   229
                                % (strerror, self.last_check_filename)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   230
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   231
        def get_delta_for_refresh_period(self):
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   232
                if self.refresh_period == DAILY:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   233
                        delta = DAILY_SECS
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   234
                elif self.refresh_period == WEEKLY:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   235
                        delta = WEEKLY_SECS
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   236
                elif self.refresh_period == MONTHLY:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   237
                        delta = MONTHLY_SECS
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   238
                else:
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   239
                        delta = NEVER_SECS
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   240
                return delta
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   241
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   242
        def is_check_required(self):
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   243
                delta = self.get_delta_for_refresh_period()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   244
                if delta == NEVER_SECS:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   245
                        self.time_until_next_check = NEVER_SECS
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   246
                        return False
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   247
                if self.last_check_time == 0:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   248
                        return True
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   249
                current_time = time.time()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   250
                if debug == True:
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   251
                        print "current time %f " % current_time
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   252
                        print "last check time %f " % self.last_check_time
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   253
                self.time_until_next_check = self.last_check_time + delta - current_time
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   254
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   255
                        print "time until next check %f " % self.time_until_next_check
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   256
                if self.time_until_next_check <= 0:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   257
                        return True
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   258
                else:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   259
                        return False
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   260
810
4f4620272b7a 5263 UMN notification icon inconsistent behavior
Padraig O'Briain <padraig.obriain@sun.com>
parents: 808
diff changeset
   261
        def show_status_icon(self, value):
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   262
                if self.status_icon == None:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   263
                        self.status_icon = self.create_status_icon()
810
4f4620272b7a 5263 UMN notification icon inconsistent behavior
Padraig O'Briain <padraig.obriain@sun.com>
parents: 808
diff changeset
   264
                self.client.set_bool(SHOW_ICON_ON_STARTUP_PREFERENCES, value)
4f4620272b7a 5263 UMN notification icon inconsistent behavior
Padraig O'Briain <padraig.obriain@sun.com>
parents: 808
diff changeset
   265
                self.status_icon.set_visible(value)
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   266
603
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   267
        def check_for_updates(self):
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   268
                image_directory = os.popen(IMAGE_DIR_COMMAND).readline().rstrip()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   269
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   270
                        print "image_directory: %s" % image_directory
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   271
                if len(image_directory) == 0:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   272
                        image_directory = IMAGE_DIRECTORY_DEFAULT
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   273
                image_obj = self.__get_image_obj_from_directory(image_directory)
585
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   274
                
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   275
                pkg_upgradeable = None
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   276
                for pkg, state in image_obj.inventory(all_known = True):
585
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   277
                        if state["upgradable"] and state["state"] == "installed":
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   278
                                pkg_upgradeable = pkg
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   279
                                break
585
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   280
                        
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   281
                if debug == True:
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   282
                        if pkg_upgradeable != None:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   283
                                print "Packages to be updated"
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   284
                        else:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   285
                                print "No packages to be updated"
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   286
                self.set_last_check_time()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   287
                if pkg_upgradeable != None:
810
4f4620272b7a 5263 UMN notification icon inconsistent behavior
Padraig O'Briain <padraig.obriain@sun.com>
parents: 808
diff changeset
   288
                        self.show_status_icon(True)
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   289
                else:
810
4f4620272b7a 5263 UMN notification icon inconsistent behavior
Padraig O'Briain <padraig.obriain@sun.com>
parents: 808
diff changeset
   290
                        self.show_status_icon(False)
4f4620272b7a 5263 UMN notification icon inconsistent behavior
Padraig O'Briain <padraig.obriain@sun.com>
parents: 808
diff changeset
   291
                self.schedule_next_check_for_checks()
585
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   292
                return False                                
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   293
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   294
        # This is copied from a similar function in packagemanager.py 
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   295
        def __get_image_obj_from_directory(self, image_directory):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   296
                image_obj = image.Image()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   297
                dr = "/"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   298
                try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   299
                        image_obj.find_root(image_directory)
585
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   300
                        while gtk.events_pending():
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   301
                                gtk.main_iteration(False)
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   302
                        image_obj.load_config()
585
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   303
                        while gtk.events_pending():
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   304
                                gtk.main_iteration(False)
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   305
                        image_obj.load_catalogs(self.pr)
585
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   306
                        while gtk.events_pending():
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   307
                                gtk.main_iteration(False)
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   308
                except ValueError:
808
6c89385ac9ff 4463 Change PM and UM to use _() as opposed to self._()
Padraig O'Briain <padraig.obriain@sun.com>
parents: 791
diff changeset
   309
                        print _('%s is not valid image, trying root image') \
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   310
                            % image_directory
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   311
                        try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   312
                                dr = os.environ["PKG_IMAGE"]
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   313
                        except KeyError:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   314
                                print
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   315
                        try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   316
                                image_obj.find_root(dr)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   317
                                image_obj.load_config()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   318
                        except ValueError:
808
6c89385ac9ff 4463 Change PM and UM to use _() as opposed to self._()
Padraig O'Briain <padraig.obriain@sun.com>
parents: 791
diff changeset
   319
                                print _('%s is not valid root image, return None') \
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   320
                                    % dr
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   321
                                image_obj = None
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   322
                return image_obj
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   323
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   324
        def create_status_icon(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   325
                status_icon = gtk.status_icon_new_from_file(NOTIFY_ICON_PATH)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   326
                status_icon.set_visible(False)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   327
                status_icon.connect('activate', self.activate_status_icon)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   328
                status_icon.connect('notify', self.notify_status_icon)
808
6c89385ac9ff 4463 Change PM and UM to use _() as opposed to self._()
Padraig O'Briain <padraig.obriain@sun.com>
parents: 791
diff changeset
   329
                status_icon.set_tooltip(_("Updates are available"))
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   330
                return status_icon
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   331
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   332
        def notify_status_icon(self, status_icon, paramspec):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   333
                if paramspec.name == "embedded" and self.status_icon.is_embedded():
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   334
                        if self.get_show_notify_message():
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   335
                                gobject.idle_add(self.show_notify_message)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   336
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   337
        def activate_status_icon(self, status_icon):
810
4f4620272b7a 5263 UMN notification icon inconsistent behavior
Padraig O'Briain <padraig.obriain@sun.com>
parents: 808
diff changeset
   338
                self.show_status_icon(False)
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   339
                gobject.spawn_async([GKSU_PATH, UPDATEMANAGER])
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   340
                if self.get_terminate_after_activate():
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   341
                        gtk.main_quit()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   342
                        sys.exit(0)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   343
                else:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   344
                        self.schedule_next_check_for_checks()
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   345
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   346
        def show_notify_message(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   347
                if self.notify == None:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   348
                        if pynotify.init("UpdateManager"):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   349
                                self.notify = pynotify.Notification(\
808
6c89385ac9ff 4463 Change PM and UM to use _() as opposed to self._()
Padraig O'Briain <padraig.obriain@sun.com>
parents: 791
diff changeset
   350
                _("Update Manager"), \
6c89385ac9ff 4463 Change PM and UM to use _() as opposed to self._()
Padraig O'Briain <padraig.obriain@sun.com>
parents: 791
diff changeset
   351
                _("Updates available\nPlease click on icon to update."))
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   352
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   353
                if self.notify != None:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   354
                        self.set_notify_position()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   355
                        self.notify.show()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   356
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   357
        def set_notify_position(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   358
                geometry = self.status_icon.get_geometry()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   359
                rectangle = geometry[1]
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   360
                orientation = geometry[2]
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   361
                x = rectangle.x
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   362
                y = rectangle.y
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   363
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   364
                if orientation == gtk.ORIENTATION_HORIZONTAL and y > 200:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   365
                        x += 10
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   366
                        y += 5
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   367
                elif orientation == gtk.ORIENTATION_HORIZONTAL and y <=200:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   368
                        x += 10
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   369
                        y += 25
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   370
                elif orientation == gtk.ORIENTATION_VERTICAL and x >200:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   371
                        x -= 5
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   372
                        y += 10
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   373
                else:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   374
                        x += 25
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   375
                        y += 10
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   376
                self.notify.set_hint_int32("x", x)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   377
                self.notify.set_hint_int32("y", y)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   378
730
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   379
        def schedule_next_check_for_checks(self):
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   380
                """This schedules the next time to wake up to check if it's
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   381
                necessary to check for updates yet."""
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   382
                if self.time_until_next_check <= 0:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   383
                        next_check_time = self.get_delta_for_refresh_period()
730
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   384
                else:
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   385
                        next_check_time = self.time_until_next_check
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   386
                if debug == True:
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   387
                        print "scheduling next check: %s" % next_check_time
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   388
                self.timeout_id = gobject.timeout_add(int(next_check_time * 1000),
730
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   389
                    self.do_next_check)
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   390
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   391
        def do_next_check(self):
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   392
                self.timeout_id = 0
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   393
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   394
                        print "Called do_next_check"
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   395
                        print "time for check: %f - %f \n" % (time.time(), \
603
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   396
                                self.last_check_time)
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   397
                if self.is_check_required():
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   398
                        gobject.idle_add(self.check_for_updates)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   399
                else:
730
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   400
                        self.schedule_next_check_for_checks()
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   401
                return False
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   402
808
6c89385ac9ff 4463 Change PM and UM to use _() as opposed to self._()
Padraig O'Briain <padraig.obriain@sun.com>
parents: 791
diff changeset
   403
        @staticmethod
6c89385ac9ff 4463 Change PM and UM to use _() as opposed to self._()
Padraig O'Briain <padraig.obriain@sun.com>
parents: 791
diff changeset
   404
        def check_already_running():
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   405
                atom = gtk.gdk.atom_intern("UPDATEMANAGERNOTIFIER",
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   406
                                           only_if_exists = False)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   407
                pid = os.getpid()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   408
                atom_args = [pid, ]
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   409
                fail = True
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   410
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   411
                is_running = gtk.gdk.get_default_root_window().property_get(atom)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   412
                if is_running != None:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   413
                        old_pid = is_running[2][0]
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   414
                        try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   415
                                os.kill(old_pid, 0)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   416
                        except os.error, eargs:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   417
                                if eargs[0] != errno.ESRCH: # No such process
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   418
                                        raise os.error, args
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   419
                                # Old process no longer exists
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   420
                                fail = False
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   421
                else:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   422
                        # Atom does not exist
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   423
                        fail = False
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   424
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   425
                if fail == True:
808
6c89385ac9ff 4463 Change PM and UM to use _() as opposed to self._()
Padraig O'Briain <padraig.obriain@sun.com>
parents: 791
diff changeset
   426
                        print _("Another instance of UpdateManagerNotify is running")
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   427
                        sys.exit(1)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   428
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   429
                gtk.gdk.get_default_root_window().property_change(atom,
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   430
                        "INTEGER", 16, gtk.gdk.PROP_MODE_REPLACE, atom_args)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   431
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   432
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   433
###############################################################################
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   434
#-----------------------------------------------------------------------------#
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   435
# Main
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   436
#-----------------------------------------------------------------------------#
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   437
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   438
def main():
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   439
        gtk.main()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   440
        return 0
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   441
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   442
if __name__ == '__main__':
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   443
        debug = False
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   444
        try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   445
                opts, args = getopt.getopt(sys.argv[1:], "hd", ["help", "debug"])
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   446
        except getopt.error, msg:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   447
                print "%s, for help use --help" % msg
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   448
                sys.exit(2)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   449
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   450
        for option, argument in opts:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   451
                if option in ("-h", "--help"):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   452
                        print "Use -d (--debug) to run in debug mode."
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   453
                        sys.exit(0)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   454
                if option in ("-d", "--debug"):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   455
                        debug = True
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   456
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   457
        updatemanager_notifier = UpdateManagerNotifier()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   458
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   459
        main()