author | John Rice <john.rice@sun.com> |
Mon, 20 Oct 2008 18:13:28 +0100 | |
changeset 603 | 4000e193b337 |
parent 585 | 3ea97a12eea4 |
child 638 | 53b78e3428fc |
permissions | -rw-r--r-- |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.4 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
2 |
# |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
3 |
# CDDL HEADER START |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
4 |
# |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
5 |
# The contents of this file are subject to the terms of the |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
6 |
# Common Development and Distribution License (the "License"). |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
7 |
# You may not use this file except in compliance with the License. |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
8 |
# |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
9 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
10 |
# or http://www.opensolaris.org/os/licensing. |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
11 |
# See the License for the specific language governing permissions |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
12 |
# and limitations under the License. |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
13 |
# |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
15 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
16 |
# If applicable, add the following below this CDDL HEADER, with the |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
19 |
# |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
20 |
# CDDL HEADER END |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
21 |
# |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
22 |
# Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
23 |
# Use is subject to license terms. |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
24 |
# |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
25 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
26 |
import os |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
27 |
import errno |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
28 |
import sys |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
29 |
import time |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
30 |
import socket |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
31 |
import locale |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
32 |
import gettext |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
33 |
import getopt |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
34 |
try: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
35 |
import gobject |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
36 |
gobject.threads_init() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
37 |
import gconf |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
38 |
import gtk |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
39 |
import pygtk |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
40 |
pygtk.require("2.0") |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
41 |
except ImportError: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
42 |
sys.exit(1) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
43 |
try: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
44 |
import pynotify |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
45 |
except ImportError: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
46 |
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
|
47 |
sys.exit(1) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
48 |
import pkg.client.image as image |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
49 |
import pkg.client.progress as progress |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
50 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
51 |
START_DELAY_DEFAULT = 120 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
52 |
REFRESH_PERIOD_DEFAULT = "Never" |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
53 |
SHOW_NOTIFY_ICON_DEFAULT = True |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
54 |
IMAGE_DIRECTORY_DEFAULT = "/" |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
55 |
LASTCHECK_DIR_NAME = os.path.expanduser("~") + '/.updatemanager/notify/' |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
56 |
IMAGE_DIR_COMMAND = "svcprop -p update/image_dir svc:/application/pkg/update" |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
57 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
58 |
NOTIFY_ICON_PATH = "/usr/share/icons/update-manager/notify_update.png" |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
59 |
GKSU_PATH = "/usr/bin/gksu" |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
60 |
UPDATEMANAGER = "updatemanager" |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
61 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
SHOW_ICON_ON_STARTUP_PREFERENCES = "/apps/updatemanager/preferences/show_icon_on_startup" |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
66 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
67 |
DAILY = "Daily" |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
68 |
WEEKLY = "Weekly" |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
69 |
MONTHLY = "Monthly" |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
70 |
NEVER = "Never" |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
71 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
72 |
DAILY_SECS = 24*60*60 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
73 |
WEEKLY_SECS = 7*24*60*60 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
74 |
# 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
|
75 |
MONTHLY_SECS = 30*24*60*60 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
76 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
77 |
class UpdateManagerNotifier: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
78 |
def __init__(self): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
79 |
# Required for pkg strings used in pkg API |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
80 |
gettext.install("pkg", "/usr/lib/locale") |
603
4000e193b337
4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents:
585
diff
changeset
|
81 |
self.pr = None |
4000e193b337
4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents:
585
diff
changeset
|
82 |
self.last_check_filename = None |
4000e193b337
4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents:
585
diff
changeset
|
83 |
self.time_until_next_check = 0 |
4000e193b337
4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents:
585
diff
changeset
|
84 |
self.status_icon = None |
4000e193b337
4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents:
585
diff
changeset
|
85 |
self.notify = None |
4000e193b337
4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents:
585
diff
changeset
|
86 |
self.host = None |
4000e193b337
4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents:
585
diff
changeset
|
87 |
self.last_check_time = 0 |
4000e193b337
4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents:
585
diff
changeset
|
88 |
self.refresh_period = 0 |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
89 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
90 |
locale.setlocale(locale.LC_ALL, '') |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
91 |
self._ = gettext.gettext |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
92 |
self.client = gconf.client_get_default() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
93 |
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
|
94 |
# 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
|
95 |
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
|
96 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
97 |
def check_and_start(self): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
98 |
self.check_already_running() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
99 |
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
|
100 |
self.host = socket.gethostname() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
101 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
102 |
if self.get_show_icon_on_startup(): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
103 |
self.show_status_icon() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
104 |
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
|
105 |
self.pr = progress.NullProgressTracker() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
106 |
gobject.idle_add(self.do_next_check) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
107 |
return False |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
108 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
109 |
def get_start_delay(self): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
110 |
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
|
111 |
if start_delay == 0: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
112 |
start_delay = START_DELAY_DEFAULT |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
113 |
if debug == True: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
114 |
print "start_delay: %d" % start_delay |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
115 |
return start_delay |
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 |
def get_refresh_period(self): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
118 |
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
|
119 |
if refresh_period == None: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
120 |
refresh_period = REFRESH_PERIOD_DEFAULT |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
121 |
if debug == True: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
122 |
print "refresh_period: %s" % refresh_period |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
123 |
return refresh_period |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
124 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
125 |
def get_show_notify_message(self): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
126 |
show_notify_message = \ |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
127 |
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
|
128 |
if debug == True: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
129 |
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
|
130 |
return show_notify_message |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
131 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
132 |
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
|
133 |
show_icon_on_startup = \ |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
134 |
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
|
135 |
if debug == True: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
136 |
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
|
137 |
return show_icon_on_startup |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
138 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
139 |
def get_last_check_time(self): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
140 |
if (self.last_check_filename == None): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
141 |
self.last_check_filename = \ |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
142 |
LASTCHECK_DIR_NAME + self.host + '-lastcheck' |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
143 |
try: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
144 |
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
|
145 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
146 |
try: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
147 |
return float(f.read(64)) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
148 |
finally: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
149 |
f.close() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
150 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
151 |
except IOError, strerror: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
152 |
if debug == True: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
153 |
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
|
154 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
155 |
return 0 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
156 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
157 |
def set_last_check_time(self): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
158 |
self.last_check_time = time.time() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
159 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
160 |
try: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
161 |
os.makedirs(LASTCHECK_DIR_NAME) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
162 |
except os.error, eargs: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
163 |
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
|
164 |
raise os.error, args |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
165 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
166 |
try: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
167 |
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
|
168 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
169 |
try: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
170 |
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
|
171 |
finally: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
172 |
f.close() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
173 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
174 |
except IOError, strerror: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
175 |
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
|
176 |
% (strerror, self.last_check_filename) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
177 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
178 |
def is_check_required(self): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
179 |
if self.refresh_period == DAILY: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
180 |
delta = DAILY_SECS |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
181 |
elif self.refresh_period == WEEKLY: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
182 |
delta = WEEKLY_SECS |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
183 |
elif self.refresh_period == MONTHLY: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
184 |
delta = MONTHLY_SECS |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
185 |
else: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
186 |
self.time_until_next_check = 0 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
187 |
return False |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
188 |
current_time = time.time() |
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 "current time %s " \ |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
191 |
% time.strftime("%a %d %b %Y %H:%M:%S", time.gmtime(current_time)) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
192 |
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
|
193 |
if debug == True: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
194 |
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
|
195 |
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
|
196 |
return True |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
197 |
else: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
198 |
return False |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
199 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
200 |
def show_status_icon(self): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
201 |
if self.status_icon == None: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
202 |
self.status_icon = self.create_status_icon() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
203 |
self.client.set_bool(SHOW_ICON_ON_STARTUP_PREFERENCES, True) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
204 |
self.status_icon.set_visible(True) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
205 |
|
603
4000e193b337
4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents:
585
diff
changeset
|
206 |
def check_for_updates(self): |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
207 |
self.set_last_check_time() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
208 |
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
|
209 |
if debug == True: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
210 |
print "image_directory: %s" % image_directory |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
211 |
if len(image_directory) == 0: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
212 |
image_directory = IMAGE_DIRECTORY_DEFAULT |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
213 |
image_obj = self.__get_image_obj_from_directory(image_directory) |
585
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
214 |
|
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
215 |
count = 0 |
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
216 |
pkg_upgradeable = None |
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
217 |
for pkg, state in sorted(image_obj.inventory(all_known = True)): |
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
218 |
if state["upgradable"] and state["state"] == "installed": |
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
219 |
pkg_upgradeable = pkg |
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
220 |
|
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
221 |
if pkg_upgradeable != None and not state["upgradable"] \ |
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
222 |
and image_obj.fmri_is_same_pkg(pkg_upgradeable, pkg): |
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
223 |
count += 1 |
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
224 |
|
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
225 |
if debug == True: |
585
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
226 |
print "pkgs_to_be_updated: %d" % count |
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
227 |
if count: |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
228 |
self.show_status_icon() |
585
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
229 |
return False |
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
230 |
|
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
231 |
# This is copied from a similar function in packagemanager.py |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
232 |
def __get_image_obj_from_directory(self, image_directory): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
233 |
image_obj = image.Image() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
234 |
dr = "/" |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
235 |
try: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
236 |
image_obj.find_root(image_directory) |
585
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
237 |
while gtk.events_pending(): |
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
238 |
gtk.main_iteration(False) |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
239 |
image_obj.load_config() |
585
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
240 |
while gtk.events_pending(): |
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
241 |
gtk.main_iteration(False) |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
242 |
image_obj.load_catalogs(self.pr) |
585
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
243 |
while gtk.events_pending(): |
3ea97a12eea4
3834 UpdateManager Notifier incorrect notification
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
244 |
gtk.main_iteration(False) |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
245 |
except ValueError: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
246 |
print self._('%s is not valid image, trying root image') \ |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
247 |
% image_directory |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
248 |
try: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
249 |
dr = os.environ["PKG_IMAGE"] |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
250 |
except KeyError: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
251 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
252 |
try: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
253 |
image_obj.find_root(dr) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
254 |
image_obj.load_config() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
255 |
except ValueError: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
256 |
print self._('%s is not valid root image, return None') \ |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
257 |
% dr |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
258 |
image_obj = None |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
259 |
return image_obj |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
260 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
261 |
def create_status_icon(self): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
262 |
status_icon = gtk.status_icon_new_from_file(NOTIFY_ICON_PATH) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
263 |
status_icon.set_visible(False) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
264 |
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
|
265 |
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
|
266 |
status_icon.set_tooltip(self._("Updates are available")) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
267 |
return status_icon |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
268 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
269 |
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
|
270 |
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
|
271 |
if self.get_show_notify_message(): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
272 |
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
|
273 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
274 |
def activate_status_icon(self, status_icon): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
275 |
self.status_icon.set_visible(False) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
276 |
self.client.set_bool(SHOW_ICON_ON_STARTUP_PREFERENCES, False) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
277 |
gobject.spawn_async([GKSU_PATH, UPDATEMANAGER]) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
278 |
gtk.main_quit() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
279 |
sys.exit(0) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
280 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
281 |
def show_notify_message(self): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
282 |
if self.notify == None: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
283 |
if pynotify.init("UpdateManager"): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
284 |
self.notify = pynotify.Notification(\ |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
285 |
self._("Update Manager"), \ |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
286 |
self._("Updates available\nPlease click on icon to update.")) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
287 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
288 |
if self.notify != None: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
289 |
self.set_notify_position() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
290 |
self.notify.show() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
291 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
292 |
def set_notify_position(self): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
293 |
geometry = self.status_icon.get_geometry() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
294 |
rectangle = geometry[1] |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
295 |
orientation = geometry[2] |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
296 |
x = rectangle.x |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
297 |
y = rectangle.y |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
298 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
299 |
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
|
300 |
x += 10 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
301 |
y += 5 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
302 |
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
|
303 |
x += 10 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
304 |
y += 25 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
305 |
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
|
306 |
x -= 5 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
307 |
y += 10 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
308 |
else: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
309 |
x += 25 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
310 |
y += 10 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
311 |
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
|
312 |
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
|
313 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
314 |
def do_next_check(self): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
315 |
if debug == True: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
316 |
print "Called do_next_check" |
603
4000e193b337
4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents:
585
diff
changeset
|
317 |
print "time for check: %s - %s \n" % (time.gmtime(), \ |
4000e193b337
4101 Pylint cleanup updatemanager and updatemanagernotifier
John Rice <john.rice@sun.com>
parents:
585
diff
changeset
|
318 |
self.last_check_time) |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
319 |
if self.last_check_time == 0 or self.is_check_required(): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
320 |
gobject.idle_add(self.check_for_updates) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
321 |
else: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
322 |
if self.time_until_next_check > DAILY_SECS: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
323 |
next_check_time = DAILY_SECS |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
324 |
else: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
325 |
next_check_time = self.time_until_next_check |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
326 |
gobject.timeout_add(int(next_check_time*1000), self.do_next_check) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
327 |
return False |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
328 |
return True |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
329 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
330 |
def check_already_running(self): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
331 |
atom = gtk.gdk.atom_intern("UPDATEMANAGERNOTIFIER", |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
332 |
only_if_exists = False) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
333 |
pid = os.getpid() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
334 |
atom_args = [pid, ] |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
335 |
fail = True |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
336 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
337 |
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
|
338 |
if is_running != None: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
339 |
old_pid = is_running[2][0] |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
340 |
try: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
341 |
os.kill(old_pid, 0) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
342 |
except os.error, eargs: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
343 |
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
|
344 |
raise os.error, args |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
345 |
# Old process no longer exists |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
346 |
fail = False |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
347 |
else: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
348 |
# Atom does not exist |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
349 |
fail = False |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
350 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
351 |
if fail == True: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
352 |
print self._("Another instance of UpdateManagerNotify is running") |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
353 |
sys.exit(1) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
354 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
355 |
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
|
356 |
"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
|
357 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
358 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
359 |
############################################################################### |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
360 |
#-----------------------------------------------------------------------------# |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
361 |
# Main |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
362 |
#-----------------------------------------------------------------------------# |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
363 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
364 |
def main(): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
365 |
gtk.main() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
366 |
return 0 |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
367 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
368 |
if __name__ == '__main__': |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
369 |
debug = False |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
370 |
try: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
371 |
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
|
372 |
except getopt.error, msg: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
373 |
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
|
374 |
sys.exit(2) |
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 |
for option, argument in opts: |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
377 |
if option in ("-h", "--help"): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
378 |
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
|
379 |
sys.exit(0) |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
380 |
if option in ("-d", "--debug"): |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
381 |
debug = True |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
382 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
383 |
updatemanager_notifier = UpdateManagerNotifier() |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
384 |
|
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
385 |
main() |