src/updatemanagernotifier.py
author thejaswini.k@oracle.com
Fri, 07 Sep 2012 11:30:52 +0530
changeset 2791 4361a284bbcb
parent 2078 a13afe24c79a
child 2792 94435d89e7c5
permissions -rw-r--r--
7140506 Package Manager and Update Manager should use get_default_image_dir 7140761 Package Manager window title wrong
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
#
2791
4361a284bbcb 7140506 Package Manager and Update Manager should use get_default_image_dir
thejaswini.k@oracle.com
parents: 2078
diff changeset
    22
# Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    23
#
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
import os
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1169
diff changeset
    26
import subprocess
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    27
import errno
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    28
import sys
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    29
import time
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    30
import socket
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    31
import locale
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    32
import gettext
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    33
import getopt
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
    34
import random
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    35
try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    36
        import gobject
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    37
        gobject.threads_init()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    38
        import gconf
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    39
        import gtk
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    40
        import pygtk
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    41
        pygtk.require("2.0")
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    42
except ImportError:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    43
        sys.exit(1)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
    44
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
    45
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
    46
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
    47
import pkg.gui.enumerations as enumerations
1948
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
    48
from gettext import ngettext
1791
b2a37ff09e8c 13994 References to package names may need to change
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1577
diff changeset
    49
try:
b2a37ff09e8c 13994 References to package names may need to change
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1577
diff changeset
    50
        import pynotify
b2a37ff09e8c 13994 References to package names may need to change
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1577
diff changeset
    51
except ImportError:
b2a37ff09e8c 13994 References to package names may need to change
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1577
diff changeset
    52
        print "%s package must be installed" % (
b2a37ff09e8c 13994 References to package names may need to change
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1577
diff changeset
    53
            gui_misc.package_name["SUNWpython26-notify"])
b2a37ff09e8c 13994 References to package names may need to change
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1577
diff changeset
    54
        sys.exit(1)
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')
2078
a13afe24c79a 17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents: 2041
diff changeset
    65
CHECKFOR_UPDATES = "/usr/lib/pm-checkforupdates"
2041
ee746d3c19be 6084 Simplify Update Manager use same code as PM
John Rice <john.rice@oracle.com>
parents: 2013
diff changeset
    66
UPDATEMANAGER = "pm-updatemanager"
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"
1577
010ca8cee4d2 12732 Notification icon updates
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1516
diff changeset
    69
NOTIFY_ICON_NAME = "updatemanager"
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"
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, "")
2013
7e157252546e 16657 libglade to GtkBuilder
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1948
diff changeset
    99
                gettext.bindtextdomain("pkg", os.path.join(
7e157252546e 16657 libglade to GtkBuilder
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1948
diff changeset
   100
                    self.application_dir,
7e157252546e 16657 libglade to GtkBuilder
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1948
diff changeset
   101
                    "usr/share/locale"))
7e157252546e 16657 libglade to GtkBuilder
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1948
diff changeset
   102
                gettext.textdomain("pkg")
603
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   103
                self.pr = None
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   104
                self.last_check_filename = None
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   105
                self.time_until_next_check = 0
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   106
                self.status_icon = None
1948
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   107
                self.n_updates = 0
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   108
                self.n_installs = 0
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   109
                self.n_removes = 0
603
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   110
                self.notify = None
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   111
                self.host = None
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   112
                self.last_check_time = 0
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   113
                self.refresh_period = 0
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   114
                self.timeout_id = 0
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   115
                self.terminate_after_activate = False
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   116
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   117
                self.client = gconf.client_get_default()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   118
                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
   119
                # 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
   120
                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
   121
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   122
        def check_and_start(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   123
                self.check_already_running()
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   124
                self.client.add_dir(UPDATEMANAGER_PREFERENCES, 
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   125
                    gconf.CLIENT_PRELOAD_NONE)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   126
                self.client.notify_add(REFRESH_PERIOD_PREFERENCES, 
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   127
                    self.refresh_period_changed)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   128
                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
   129
                    self.show_icon_changed)
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   130
                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
   131
                self.host = socket.gethostname()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   132
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   133
                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
   134
                self.pr = progress.NullProgressTracker()
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   135
                if self.get_show_icon_on_startup():
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   136
                        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
   137
                        self.schedule_check_for_updates()
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   138
                else:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   139
                        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
   140
                return False
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   141
                
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   142
        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
   143
                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
   144
                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
   145
                        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
   146
                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
   147
                if debug == True:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   148
                        print "old_delta %d" % old_delta
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   149
                        print "new_delta %d" % new_delta
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   150
                if old_delta > new_delta:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   151
                        if self.timeout_id > 0:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   152
                                gobject.source_remove(self.timeout_id)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   153
                                self.timeout_id = 0
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   154
                        self.do_next_check()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   155
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   156
        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
   157
                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
   158
                        show_icon = entry.get_value().get_bool()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   159
                if self.status_icon != None:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   160
                        self.status_icon.set_visible(show_icon)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   161
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   162
        def get_start_delay(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   163
                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
   164
                if start_delay == 0:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   165
                        start_delay = START_DELAY_DEFAULT
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   166
                if debug == True:
1948
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   167
                        start_delay = 1
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   168
                        print "start_delay: %d" % start_delay
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   169
                return start_delay
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   170
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   171
        def get_refresh_period(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   172
                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
   173
                if refresh_period == None:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   174
                        refresh_period = REFRESH_PERIOD_DEFAULT
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   175
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   176
                        print "refresh_period: %s" % refresh_period
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   177
                return refresh_period
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   178
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   179
        def get_show_notify_message(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   180
                show_notify_message  =  \
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   181
                        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
   182
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   183
                        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
   184
                return show_notify_message
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   185
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   186
        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
   187
                show_icon_on_startup  =  \
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   188
                        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
   189
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   190
                        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
   191
                return show_icon_on_startup
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   192
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   193
        def get_terminate_after_activate(self):
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   194
                terminate_after_activate  =  \
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   195
                        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
   196
                if debug == True:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   197
                        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
   198
                return terminate_after_activate
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   199
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   200
        def get_last_check_time(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   201
                if (self.last_check_filename == None):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   202
                        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
   203
                                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
   204
                                    self.host + '-lastcheck')
578
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
                        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
   207
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   208
                        try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   209
                                return float(f.read(64))
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   210
                        finally:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   211
                                f.close()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   212
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   213
                except IOError, strerror:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   214
                        if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   215
                                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
   216
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   217
                return 0
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   218
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   219
        def set_last_check_time(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   220
                try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   221
                        os.makedirs(LASTCHECK_DIR_NAME)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   222
                except os.error, eargs:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   223
                        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
   224
                                raise os.error, args
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 = open(self.last_check_filename, "w")
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   228
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   229
                        try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   230
                                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
   231
                        finally:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   232
                                f.close()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   233
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   234
                except IOError, strerror:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   235
                        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
   236
                                % (strerror, self.last_check_filename)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   237
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   238
        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
   239
                if self.refresh_period == DAILY:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   240
                        delta = DAILY_SECS
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   241
                elif self.refresh_period == WEEKLY:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   242
                        delta = WEEKLY_SECS
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   243
                elif self.refresh_period == MONTHLY:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   244
                        delta = MONTHLY_SECS
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   245
                else:
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   246
                        delta = NEVER_SECS
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   247
                return delta
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   248
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   249
        def is_check_required(self):
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   250
                delta = self.get_delta_for_refresh_period()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   251
                if delta == NEVER_SECS:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   252
                        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
   253
                        return False
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   254
                if self.last_check_time == 0:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   255
                        return True
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   256
                current_time = time.time()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   257
                if debug == True:
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   258
                        print "current time %f " % current_time
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   259
                        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
   260
                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
   261
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   262
                        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
   263
                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
   264
                        return True
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   265
                else:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   266
                        return False
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   267
810
4f4620272b7a 5263 UMN notification icon inconsistent behavior
Padraig O'Briain <padraig.obriain@sun.com>
parents: 808
diff changeset
   268
        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
   269
                if self.status_icon == None:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   270
                        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
   271
                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
   272
                self.status_icon.set_visible(value)
1948
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   273
                if not value:
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   274
                        return
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   275
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   276
                toolfmt = _("<b>Updates are available: </b>\n"
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   277
                    "%(updates)s %(installs)s %(removes)s")
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   278
                tooltip = self.__set_updates_str(toolfmt)
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   279
                self.status_icon.set_tooltip_markup(tooltip)
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   280
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   281
        def __set_updates_str(self, str_fmt):
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   282
                if self.n_updates == 0:
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   283
                        updates_str = ""
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   284
                else:
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   285
                        updates_fmt = ngettext("%d Update,", "%d Updates,",
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   286
                            self.n_updates)
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   287
                        updates_str = updates_fmt % self.n_updates
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   288
                if self.n_installs == 0:
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   289
                        installs_str = ""
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   290
                else:
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   291
                        installs_fmt = ngettext("%d Install,", "%d Installs,",
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   292
                            self.n_installs)
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   293
                        installs_str = installs_fmt % self.n_installs
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   294
                if self.n_removes == 0:
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   295
                        removes_str = ""
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   296
                else:
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   297
                        removes_fmt = ngettext("%d Remove", "%d Removes",
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   298
                            self.n_removes)
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   299
                        removes_str = removes_fmt % self.n_removes
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   300
                updates_str = str_fmt % \
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   301
                    {"updates": updates_str,
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   302
                    "installs": installs_str,
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   303
                    "removes": removes_str}
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   304
                updates_str = updates_str.rstrip(', ')
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   305
                return updates_str
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   306
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
   307
        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
   308
                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
   309
                # 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
   310
                # 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
   311
                if debug:
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1169
diff changeset
   312
                        random_delay = 0
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1169
diff changeset
   313
                else:
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1169
diff changeset
   314
                        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
   315
                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
   316
603
4000e193b337 4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents: 585
diff changeset
   317
        def check_for_updates(self):
2078
a13afe24c79a 17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents: 2041
diff changeset
   318
                proc = subprocess.Popen([CHECKFOR_UPDATES,
2041
ee746d3c19be 6084 Simplify Update Manager use same code as PM
John Rice <john.rice@oracle.com>
parents: 2013
diff changeset
   319
                            '--nice', '--checkupdates-cache',
2791
4361a284bbcb 7140506 Package Manager and Update Manager should use get_default_image_dir
thejaswini.k@oracle.com
parents: 2078
diff changeset
   320
                            '--image-dir', IMAGE_DIRECTORY_DEFAULT],
2041
ee746d3c19be 6084 Simplify Update Manager use same code as PM
John Rice <john.rice@oracle.com>
parents: 2013
diff changeset
   321
                            stdout=subprocess.PIPE)
ee746d3c19be 6084 Simplify Update Manager use same code as PM
John Rice <john.rice@oracle.com>
parents: 2013
diff changeset
   322
1948
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   323
                output = proc.communicate()[0].strip()
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   324
                lines = output.splitlines()
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   325
                n_updates = 0
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   326
                n_installs = 0
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   327
                n_removes = 0
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   328
                for line in lines:
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   329
                        if line.startswith("n_updates"):
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   330
                                updates = line.split(":", 1)
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   331
                                n_updates = int(updates[1]) 
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   332
                        if line.startswith("n_installs"):
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   333
                                installs = line.split(":", 1)
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   334
                                n_installs = int(installs[1]) 
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   335
                        if line.startswith("n_removes"):
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   336
                                removes = line.split(":", 1)
2041
ee746d3c19be 6084 Simplify Update Manager use same code as PM
John Rice <john.rice@oracle.com>
parents: 2013
diff changeset
   337
                                n_removes = int(removes[1])
1948
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   338
                return_code = proc.wait()
1201
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1169
diff changeset
   339
                if debug:
fca0d56e685c 8631 abnormal heavy memory consumption of updatemanagernotifier
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1169
diff changeset
   340
                        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
   341
                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
   342
                if return_code == enumerations.UPDATES_AVAILABLE:
1948
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   343
                        self.n_updates = n_updates
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   344
                        self.n_installs = n_installs
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   345
                        self.n_removes = n_removes
810
4f4620272b7a 5263 UMN notification icon inconsistent behavior
Padraig O'Briain <padraig.obriain@sun.com>
parents: 808
diff changeset
   346
                        self.show_status_icon(True)
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   347
                else:
810
4f4620272b7a 5263 UMN notification icon inconsistent behavior
Padraig O'Briain <padraig.obriain@sun.com>
parents: 808
diff changeset
   348
                        self.show_status_icon(False)
4f4620272b7a 5263 UMN notification icon inconsistent behavior
Padraig O'Briain <padraig.obriain@sun.com>
parents: 808
diff changeset
   349
                self.schedule_next_check_for_checks()
585
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   350
                return False                                
3ea97a12eea4 3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents: 578
diff changeset
   351
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   352
        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
   353
                icon_theme = gtk.IconTheme()
978947aae45f 9513 Some icons are installed in wrong locations
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1159
diff changeset
   354
                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
   355
                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
   356
                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
   357
                status_icon.set_visible(False)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   358
                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
   359
                status_icon.connect('notify', self.notify_status_icon)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   360
                return status_icon
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   361
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   362
        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
   363
                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
   364
                        if self.get_show_notify_message():
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   365
                                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
   366
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   367
        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
   368
                self.show_status_icon(False)
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   369
                gobject.spawn_async([GKSU_PATH, UPDATEMANAGER])
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   370
                if self.get_terminate_after_activate():
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   371
                        gtk.main_quit()
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   372
                        sys.exit(0)
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   373
                else:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   374
                        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
   375
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   376
        def show_notify_message(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   377
                if self.notify == None:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   378
                        if pynotify.init("UpdateManager"):
1948
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   379
                                notify_fmt = _("Updates available\n"
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   380
                                    "%(updates)s %(installs)s %(removes)s")
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   381
                                notify_str = self.__set_updates_str(notify_fmt)
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   382
                                notify_str += _("\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
   383
                                self.notify = pynotify.Notification(\
1948
2b0682839132 10730 Updatemanager notification area tooltip should include the number of updates
Padraig O'Briain <padraig.obriain@oracle.com>
parents: 1791
diff changeset
   384
                                    _("Update Manager"), notify_str)
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   385
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   386
                if self.notify != None:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   387
                        self.set_notify_position()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   388
                        self.notify.show()
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
        def set_notify_position(self):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   391
                geometry = self.status_icon.get_geometry()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   392
                rectangle = geometry[1]
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   393
                orientation = geometry[2]
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   394
                x = rectangle.x
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   395
                y = rectangle.y
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   396
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   397
                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
   398
                        x += 10
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   399
                        y += 5
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   400
                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
   401
                        x += 10
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   402
                        y += 25
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   403
                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
   404
                        x -= 5
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   405
                        y += 10
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   406
                else:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   407
                        x += 25
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   408
                        y += 10
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   409
                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
   410
                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
   411
730
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   412
        def schedule_next_check_for_checks(self):
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   413
                """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
   414
                necessary to check for updates yet."""
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   415
                if self.time_until_next_check <= 0:
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   416
                        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
   417
                else:
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   418
                        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
   419
                if debug == True:
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   420
                        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
   421
                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
   422
                    self.do_next_check)
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   423
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   424
        def do_next_check(self):
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   425
                self.timeout_id = 0
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   426
                if debug == True:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   427
                        print "Called do_next_check"
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   428
                        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
   429
                                self.last_check_time)
766
300c8f10f13d 5188 Tidy up required in updatemanagernotifier
Michal Pryc <Michal.Pryc@Sun.Com>
parents: 730
diff changeset
   430
                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
   431
                        self.schedule_check_for_updates()
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   432
                else:
730
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   433
                        self.schedule_next_check_for_checks()
5a41c5c740dd 5171 Updatemanager eating 50% of the CPU
Brock Pytlik <bpytlik@sun.com>
parents: 698
diff changeset
   434
                return False
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   435
808
6c89385ac9ff 4463 Change PM and UM to use _() as opposed to self._()
Padraig O'Briain <padraig.obriain@sun.com>
parents: 791
diff changeset
   436
        @staticmethod
6c89385ac9ff 4463 Change PM and UM to use _() as opposed to self._()
Padraig O'Briain <padraig.obriain@sun.com>
parents: 791
diff changeset
   437
        def check_already_running():
578
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   438
                atom = gtk.gdk.atom_intern("UPDATEMANAGERNOTIFIER",
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   439
                                           only_if_exists = False)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   440
                pid = os.getpid()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   441
                atom_args = [pid, ]
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   442
                fail = True
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   443
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   444
                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
   445
                if is_running != None:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   446
                        old_pid = is_running[2][0]
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   447
                        try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   448
                                os.kill(old_pid, 0)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   449
                        except os.error, eargs:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   450
                                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
   451
                                        raise os.error, args
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   452
                                # Old process no longer exists
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   453
                                fail = False
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   454
                else:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   455
                        # Atom does not exist
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   456
                        fail = False
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   457
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   458
                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
   459
                        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
   460
                        sys.exit(1)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   461
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   462
                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
   463
                        "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
   464
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   465
###############################################################################
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   466
#-----------------------------------------------------------------------------#
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   467
# Main
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   468
#-----------------------------------------------------------------------------#
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   469
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   470
def main():
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   471
        gtk.main()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   472
        return 0
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   473
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   474
if __name__ == '__main__':
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   475
        debug = False
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   476
        try:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   477
                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
   478
        except getopt.error, msg:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   479
                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
   480
                sys.exit(2)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   481
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   482
        for option, argument in opts:
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   483
                if option in ("-h", "--help"):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   484
                        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
   485
                        sys.exit(0)
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   486
                if option in ("-d", "--debug"):
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   487
                        debug = True
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   488
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   489
        updatemanager_notifier = UpdateManagerNotifier()
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   490
da257532b3f2 3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff changeset
   491
        main()