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