src/updatemanagernotifier.py
author Rich Burridge <rich.burridge@sun.com>
Mon, 30 Nov 2009 13:01:40 -0800
changeset 1516 8c950a3b4171
parent 1228 07ef6e279231
child 1577 010ca8cee4d2
permissions -rw-r--r--
10485 move pkg(5) to Python 2.6 10482 upgrade to cherrypy 3.1.2 11836 shebang line for python modules should be python version-agnostic 11950 ldtp used by pkg build process not setup to easily use Python 2.6 11989 pkg python dependency analysis tests fail
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1516
8c950a3b4171 10485 move pkg(5) to Python 2.6
Rich Burridge <rich.burridge@sun.com>
parents: 1228
diff changeset
     1
#!/usr/bin/python2.6
578
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
#
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1169
diff changeset
    22
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
578
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
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1169
diff changeset
    27
import subprocess
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    28
import errno
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    29
import sys
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    30
import time
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    31
import socket
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    32
import locale
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    33
import gettext
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    34
import getopt
1159
69d2bf8dd8df 9401 UMN should introduce a dither for update time checks to spread server load
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1137
diff changeset
    35
import random
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    36
try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    37
        import gobject
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    38
        gobject.threads_init()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    39
        import gconf
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    40
        import gtk
675
6dbb72c42ff4 4549 UMNotifier missing gtk.glade import
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 660
diff changeset
    41
        import gtk.glade
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    42
        import pygtk
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    43
        pygtk.require("2.0")
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    44
except ImportError:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    45
        sys.exit(1)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    46
try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    47
        import pynotify
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    48
except ImportError:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    49
        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
    50
        sys.exit(1)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    51
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
    52
import pkg.misc as misc
1164
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1159
diff changeset
    53
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
    54
import pkg.gui.enumerations as enumerations
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    55
660
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    56
# 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
    57
import __builtin__
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    58
__builtin__._ = gettext.gettext
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    59
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    60
START_DELAY_DEFAULT = 120
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    61
REFRESH_PERIOD_DEFAULT = "Never"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    62
SHOW_NOTIFY_ICON_DEFAULT = True
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    63
IMAGE_DIRECTORY_DEFAULT = "/"
1137
f6c7c39981aa 8660 packagemanager traceback if PACKAGE_MANAGER_ROOT missing trailing '/'
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1045
diff changeset
    64
LASTCHECK_DIR_NAME = os.path.join(os.path.expanduser("~"),'.updatemanager/notify')
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    65
IMAGE_DIR_COMMAND = "svcprop -p update/image_dir svc:/application/pkg/update"
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
    66
CHECK_FOR_UPDATES = "/usr/lib/pm-checkforupdates"
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    67
1164
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1159
diff changeset
    68
ICON_LOCATION = "/usr/share/update-manager/icons"
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1159
diff changeset
    69
NOTIFY_ICON_NAME = "notify_update"
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    70
GKSU_PATH = "/usr/bin/gksu"
1024
e83271f2e133 7645 Man page required for Package Manager and Update Manager
Padraig O'Briain <padraig.obriain@sun.com>
parents: 810
diff changeset
    71
UPDATEMANAGER = "pm-updatemanager"
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    72
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
    73
UPDATEMANAGER_PREFERENCES = "/apps/updatemanager/preferences"
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    74
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
    75
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
    76
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
    77
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
    78
TERMINATE_AFTER_ICON_ACTIVATE_PREFERENCES = \
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
    79
    "/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
    80
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    81
DAILY = "Daily"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    82
WEEKLY = "Weekly"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    83
MONTHLY = "Monthly"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    84
NEVER = "Never"
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    85
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    86
DAILY_SECS = 24*60*60
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    87
WEEKLY_SECS = 7*24*60*60
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    88
# 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
    89
MONTHLY_SECS = 30*24*60*60
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
    90
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
    91
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    92
class UpdateManagerNotifier:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    93
        def __init__(self):
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
    94
                os.nice(20)
660
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    95
                try:
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    96
                        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
    97
                except KeyError:
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
    98
                        self.application_dir = "/"
791
123e9401e939 5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents: 766
diff changeset
    99
                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
   100
                for module in (gettext, gtk.glade):
1137
f6c7c39981aa 8660 packagemanager traceback if PACKAGE_MANAGER_ROOT missing trailing '/'
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1045
diff changeset
   101
                        module.bindtextdomain("pkg", os.path.join(
f6c7c39981aa 8660 packagemanager traceback if PACKAGE_MANAGER_ROOT missing trailing '/'
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1045
diff changeset
   102
                            self.application_dir,
f6c7c39981aa 8660 packagemanager traceback if PACKAGE_MANAGER_ROOT missing trailing '/'
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1045
diff changeset
   103
                            "usr/share/locale"))
660
ea2809ad4582 4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents: 641
diff changeset
   104
                        module.textdomain("pkg")
603
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   105
                self.pr = None
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   106
                self.last_check_filename = None
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   107
                self.time_until_next_check = 0
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   108
                self.status_icon = None
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   109
                self.notify = None
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   110
                self.host = None
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   111
                self.last_check_time = 0
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   112
                self.refresh_period = 0
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   113
                self.timeout_id = 0
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   114
                self.terminate_after_activate = False
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   115
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   116
                self.client = gconf.client_get_default()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   117
                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
   118
                # 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
   119
                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
   120
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   121
        def check_and_start(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   122
                self.check_already_running()
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   123
                self.client.add_dir(UPDATEMANAGER_PREFERENCES, 
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   124
                    gconf.CLIENT_PRELOAD_NONE)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   125
                self.client.notify_add(REFRESH_PERIOD_PREFERENCES, 
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   126
                    self.refresh_period_changed)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   127
                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
   128
                    self.show_icon_changed)
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   129
                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
   130
                self.host = socket.gethostname()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   131
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   132
                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
   133
                self.pr = progress.NullProgressTracker()
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   134
                if self.get_show_icon_on_startup():
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   135
                        self.client.set_bool(SHOW_ICON_ON_STARTUP_PREFERENCES, False)
1159
69d2bf8dd8df 9401 UMN should introduce a dither for update time checks to spread server load
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1137
diff changeset
   136
                        self.schedule_check_for_updates()
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   137
                else:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   138
                        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
   139
                return False
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   140
                
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   141
        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
   142
                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
   143
                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
   144
                        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
   145
                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
   146
                if debug == True:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   147
                        print "old_delta %d" % old_delta
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   148
                        print "new_delta %d" % new_delta
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   149
                if old_delta > new_delta:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   150
                        if self.timeout_id > 0:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   151
                                gobject.source_remove(self.timeout_id)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   152
                                self.timeout_id = 0
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   153
                        self.do_next_check()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   154
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   155
        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
   156
                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
   157
                        show_icon = entry.get_value().get_bool()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   158
                if self.status_icon != None:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   159
                        self.status_icon.set_visible(show_icon)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   160
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   161
        def get_start_delay(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   162
                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
   163
                if start_delay == 0:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   164
                        start_delay = START_DELAY_DEFAULT
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   165
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   166
                        print "start_delay: %d" % start_delay
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   167
                return start_delay
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   168
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   169
        def get_refresh_period(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   170
                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
   171
                if refresh_period == None:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   172
                        refresh_period = REFRESH_PERIOD_DEFAULT
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   173
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   174
                        print "refresh_period: %s" % refresh_period
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   175
                return refresh_period
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   176
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   177
        def get_show_notify_message(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   178
                show_notify_message  =  \
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   179
                        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
   180
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   181
                        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
   182
                return show_notify_message
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   183
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   184
        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
   185
                show_icon_on_startup  =  \
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   186
                        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
   187
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   188
                        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
   189
                return show_icon_on_startup
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   190
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   191
        def get_terminate_after_activate(self):
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   192
                terminate_after_activate  =  \
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   193
                        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
   194
                if debug == True:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   195
                        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
   196
                return terminate_after_activate
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   197
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   198
        def get_last_check_time(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   199
                if (self.last_check_filename == None):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   200
                        self.last_check_filename = \
1137
f6c7c39981aa 8660 packagemanager traceback if PACKAGE_MANAGER_ROOT missing trailing '/'
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1045
diff changeset
   201
                                os.path.join(LASTCHECK_DIR_NAME,
f6c7c39981aa 8660 packagemanager traceback if PACKAGE_MANAGER_ROOT missing trailing '/'
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1045
diff changeset
   202
                                    self.host + '-lastcheck')
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   203
                try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   204
                        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
   205
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   206
                        try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   207
                                return float(f.read(64))
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   208
                        finally:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   209
                                f.close()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   210
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   211
                except IOError, strerror:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   212
                        if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   213
                                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
   214
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   215
                return 0
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   216
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   217
        def set_last_check_time(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   218
                try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   219
                        os.makedirs(LASTCHECK_DIR_NAME)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   220
                except os.error, eargs:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   221
                        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
   222
                                raise os.error, args
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   223
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   224
                try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   225
                        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
   226
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   227
                        try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   228
                                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
   229
                        finally:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   230
                                f.close()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   231
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   232
                except IOError, strerror:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   233
                        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
   234
                                % (strerror, self.last_check_filename)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   235
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   236
        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
   237
                if self.refresh_period == DAILY:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   238
                        delta = DAILY_SECS
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   239
                elif self.refresh_period == WEEKLY:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   240
                        delta = WEEKLY_SECS
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   241
                elif self.refresh_period == MONTHLY:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   242
                        delta = MONTHLY_SECS
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   243
                else:
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   244
                        delta = NEVER_SECS
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   245
                return delta
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   246
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   247
        def is_check_required(self):
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   248
                delta = self.get_delta_for_refresh_period()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   249
                if delta == NEVER_SECS:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   250
                        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
   251
                        return False
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   252
                if self.last_check_time == 0:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   253
                        return True
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   254
                current_time = time.time()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   255
                if debug == True:
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   256
                        print "current time %f " % current_time
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   257
                        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
   258
                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
   259
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   260
                        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
   261
                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
   262
                        return True
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   263
                else:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   264
                        return False
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   265
810
4f4620272b7a 5263 UMN notification icon inconsistent behavior
Padraig O'Briain <padraig.obriain@sun.com>
parents: 808
diff changeset
   266
        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
   267
                if self.status_icon == None:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   268
                        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
   269
                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
   270
                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
   271
1159
69d2bf8dd8df 9401 UMN should introduce a dither for update time checks to spread server load
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1137
diff changeset
   272
        def schedule_check_for_updates(self):
69d2bf8dd8df 9401 UMN should introduce a dither for update time checks to spread server load
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1137
diff changeset
   273
                self.last_check_time = time.time()
69d2bf8dd8df 9401 UMN should introduce a dither for update time checks to spread server load
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1137
diff changeset
   274
                # Add random delay so that servers will not be hit 
69d2bf8dd8df 9401 UMN should introduce a dither for update time checks to spread server load
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1137
diff changeset
   275
                # all at once
69d2bf8dd8df 9401 UMN should introduce a dither for update time checks to spread server load
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1137
diff changeset
   276
                if debug:
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1169
diff changeset
   277
                        random_delay = 0
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1169
diff changeset
   278
                else:
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1169
diff changeset
   279
                        random_delay = random.randint(0, 1800)
1159
69d2bf8dd8df 9401 UMN should introduce a dither for update time checks to spread server load
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1137
diff changeset
   280
                gobject.timeout_add(random_delay * 1000, self.check_for_updates)
69d2bf8dd8df 9401 UMN should introduce a dither for update time checks to spread server load
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1137
diff changeset
   281
603
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   282
        def check_for_updates(self):
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   283
                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
   284
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   285
                        print "image_directory: %s" % image_directory
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   286
                if len(image_directory) == 0:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   287
                        image_directory = IMAGE_DIRECTORY_DEFAULT
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1169
diff changeset
   288
                return_code = subprocess.call([CHECK_FOR_UPDATES,
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
   289
                    '--nice', image_directory])
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1169
diff changeset
   290
                if debug:
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1169
diff changeset
   291
                        print "return from subprocess is %d" % return_code
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   292
                self.set_last_check_time()
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
   293
                if return_code == enumerations.UPDATES_AVAILABLE:
810
4f4620272b7a 5263 UMN notification icon inconsistent behavior
Padraig O'Briain <padraig.obriain@sun.com>
parents: 808
diff changeset
   294
                        self.show_status_icon(True)
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   295
                else:
810
4f4620272b7a 5263 UMN notification icon inconsistent behavior
Padraig O'Briain <padraig.obriain@sun.com>
parents: 808
diff changeset
   296
                        self.show_status_icon(False)
4f4620272b7a 5263 UMN notification icon inconsistent behavior
Padraig O'Briain <padraig.obriain@sun.com>
parents: 808
diff changeset
   297
                self.schedule_next_check_for_checks()
585
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   298
                return False                                
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   299
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   300
        def create_status_icon(self):
1164
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1159
diff changeset
   301
                icon_theme = gtk.IconTheme()
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1159
diff changeset
   302
                icon_theme.append_search_path(ICON_LOCATION)
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1159
diff changeset
   303
                icon = gui_misc.get_icon(icon_theme, NOTIFY_ICON_NAME, 24)
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1159
diff changeset
   304
                status_icon = gtk.status_icon_new_from_pixbuf(icon)
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   305
                status_icon.set_visible(False)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   306
                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
   307
                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
   308
                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
   309
                return status_icon
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   310
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   311
        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
   312
                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
   313
                        if self.get_show_notify_message():
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   314
                                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
   315
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   316
        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
   317
                self.show_status_icon(False)
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   318
                gobject.spawn_async([GKSU_PATH, UPDATEMANAGER])
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   319
                if self.get_terminate_after_activate():
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   320
                        gtk.main_quit()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   321
                        sys.exit(0)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   322
                else:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   323
                        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
   324
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   325
        def show_notify_message(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   326
                if self.notify == None:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   327
                        if pynotify.init("UpdateManager"):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   328
                                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
   329
                _("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
   330
                _("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
   331
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   332
                if self.notify != None:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   333
                        self.set_notify_position()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   334
                        self.notify.show()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   335
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   336
        def set_notify_position(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   337
                geometry = self.status_icon.get_geometry()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   338
                rectangle = geometry[1]
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   339
                orientation = geometry[2]
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   340
                x = rectangle.x
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   341
                y = rectangle.y
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   342
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   343
                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
   344
                        x += 10
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   345
                        y += 5
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   346
                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
   347
                        x += 10
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   348
                        y += 25
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   349
                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
   350
                        x -= 5
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   351
                        y += 10
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   352
                else:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   353
                        x += 25
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   354
                        y += 10
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   355
                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
   356
                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
   357
730
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   358
        def schedule_next_check_for_checks(self):
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   359
                """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
   360
                necessary to check for updates yet."""
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   361
                if self.time_until_next_check <= 0:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   362
                        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
   363
                else:
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   364
                        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
   365
                if debug == True:
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   366
                        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
   367
                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
   368
                    self.do_next_check)
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   369
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   370
        def do_next_check(self):
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   371
                self.timeout_id = 0
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   372
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   373
                        print "Called do_next_check"
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   374
                        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
   375
                                self.last_check_time)
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   376
                if self.is_check_required():
1159
69d2bf8dd8df 9401 UMN should introduce a dither for update time checks to spread server load
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1137
diff changeset
   377
                        self.schedule_check_for_updates()
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   378
                else:
730
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   379
                        self.schedule_next_check_for_checks()
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   380
                return False
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   381
808
6c89385ac9ff 4463 Change PM and UM to use _() as opposed to self._()
Padraig O'Briain <padraig.obriain@sun.com>
parents: 791
diff changeset
   382
        @staticmethod
6c89385ac9ff 4463 Change PM and UM to use _() as opposed to self._()
Padraig O'Briain <padraig.obriain@sun.com>
parents: 791
diff changeset
   383
        def check_already_running():
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   384
                atom = gtk.gdk.atom_intern("UPDATEMANAGERNOTIFIER",
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   385
                                           only_if_exists = False)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   386
                pid = os.getpid()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   387
                atom_args = [pid, ]
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   388
                fail = True
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   389
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   390
                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
   391
                if is_running != None:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   392
                        old_pid = is_running[2][0]
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   393
                        try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   394
                                os.kill(old_pid, 0)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   395
                        except os.error, eargs:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   396
                                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
   397
                                        raise os.error, args
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   398
                                # Old process no longer exists
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   399
                                fail = False
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   400
                else:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   401
                        # Atom does not exist
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   402
                        fail = False
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   403
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   404
                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
   405
                        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
   406
                        sys.exit(1)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   407
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   408
                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
   409
                        "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
   410
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   411
###############################################################################
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   412
#-----------------------------------------------------------------------------#
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   413
# Main
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   414
#-----------------------------------------------------------------------------#
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   415
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   416
def main():
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   417
        gtk.main()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   418
        return 0
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   419
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   420
if __name__ == '__main__':
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   421
        debug = False
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   422
        try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   423
                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
   424
        except getopt.error, msg:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   425
                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
   426
                sys.exit(2)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   427
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   428
        for option, argument in opts:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   429
                if option in ("-h", "--help"):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   430
                        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
   431
                        sys.exit(0)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   432
                if option in ("-d", "--debug"):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   433
                        debug = True
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
        updatemanager_notifier = UpdateManagerNotifier()
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
        main()