author | Brock Pytlik <brock.pytlik@oracle.com> |
Tue, 08 Feb 2011 23:55:15 -0800 | |
changeset 2215 | b4355e8c5097 |
parent 2183 | 21ae45e8dfcf |
child 2218 | f025ba1faae7 |
permissions | -rw-r--r-- |
1516
8c950a3b4171
10485 move pkg(5) to Python 2.6
Rich Burridge <rich.burridge@sun.com>
parents:
1505
diff
changeset
|
1 |
#!/usr/bin/python |
1336
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
2 |
# |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
3 |
# CDDL HEADER START |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
4 |
# |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
5 |
# The contents of this file are subject to the terms of the |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
6 |
# Common Development and Distribution License (the "License"). |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
7 |
# You may not use this file except in compliance with the License. |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
8 |
# |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
9 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
10 |
# or http://www.opensolaris.org/os/licensing. |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
11 |
# See the License for the specific language governing permissions |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
12 |
# and limitations under the License. |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
13 |
# |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
15 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
16 |
# If applicable, add the following below this CDDL HEADER, with the |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
19 |
# |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
20 |
# CDDL HEADER END |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
21 |
# |
2183
21ae45e8dfcf
17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents:
2158
diff
changeset
|
22 |
# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. |
1336
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
23 |
# |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
24 |
|
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
25 |
import os |
1987
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
26 |
import socket |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
27 |
import urlparse |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
28 |
import urllib2 |
1336
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
29 |
import cPickle |
1573
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
30 |
import logging |
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
31 |
import logging.handlers |
2010
eeba083d1e4a
16134 About Package Manager dialog needs to be updated
John Rice <john.rice@oracle.com>
parents:
1987
diff
changeset
|
32 |
import platform |
1585
fe17b1cf5774
13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents:
1573
diff
changeset
|
33 |
import sys |
1336
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
34 |
|
1649
aab234a49e34
13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents:
1618
diff
changeset
|
35 |
import pkg |
2010
eeba083d1e4a
16134 About Package Manager dialog needs to be updated
John Rice <john.rice@oracle.com>
parents:
1987
diff
changeset
|
36 |
import pkg.portable as portable |
1336
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
37 |
import pkg.client.api as api |
1987
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
38 |
import pkg.client.api_errors as api_errors |
1336
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
39 |
from pkg.client import global_settings |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
40 |
|
1537 | 41 |
# The current version of the Client API the PM, UM and |
42 |
# WebInstall GUIs have been tested against and are known to work with. |
|
2215
b4355e8c5097
16856 need to check keyUsage for leaf certs
Brock Pytlik <brock.pytlik@oracle.com>
parents:
2183
diff
changeset
|
43 |
CLIENT_API_VERSION = 51 |
1650
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
44 |
LOG_DIR = "/var/tmp" |
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
45 |
LOG_ERROR_EXT = "_error.log" |
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
46 |
LOG_INFO_EXT = "_info.log" |
2078
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
47 |
PKG_CLIENT_NAME_UM = "updatemanager" |
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
48 |
IMAGE_DIRECTORY_DEFAULT = "/" # Image default directory |
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
49 |
IMAGE_DIR_COMMAND = "svcprop -p update/image_dir svc:/application/pkg/update" |
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
50 |
|
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
51 |
|
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
52 |
def get_image_path(): |
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
53 |
try: |
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
54 |
image_directory = os.environ["PKG_IMAGE"] |
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
55 |
except KeyError: |
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
56 |
image_directory = \ |
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
57 |
os.popen(IMAGE_DIR_COMMAND).readline().rstrip() |
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
58 |
if len(image_directory) == 0: |
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
59 |
image_directory = IMAGE_DIRECTORY_DEFAULT |
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
60 |
return image_directory |
1650
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
61 |
|
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
62 |
def get_log_dir(): |
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
63 |
return LOG_DIR |
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
64 |
|
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
65 |
def get_log_error_ext(): |
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
66 |
return LOG_ERROR_EXT |
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
67 |
|
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
68 |
def get_log_info_ext(): |
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
69 |
return LOG_INFO_EXT |
1336
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
70 |
|
1573
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
71 |
class _LogFilter(logging.Filter): |
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
72 |
def __init__(self, max_level=logging.CRITICAL): |
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
73 |
logging.Filter.__init__(self) |
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
74 |
self.max_level = max_level |
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
75 |
|
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
76 |
def filter(self, record): |
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
77 |
return record.levelno <= self.max_level |
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
78 |
|
1649
aab234a49e34
13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents:
1618
diff
changeset
|
79 |
def get_version(): |
aab234a49e34
13852 PM needs a global error handler for uncaught exceptions
John Rice <john.rice@sun.com>
parents:
1618
diff
changeset
|
80 |
return pkg.VERSION |
1573
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
81 |
|
2010
eeba083d1e4a
16134 About Package Manager dialog needs to be updated
John Rice <john.rice@oracle.com>
parents:
1987
diff
changeset
|
82 |
def get_os_version_and_build(): |
eeba083d1e4a
16134 About Package Manager dialog needs to be updated
John Rice <john.rice@oracle.com>
parents:
1987
diff
changeset
|
83 |
os_ver = portable.util.get_os_release() |
eeba083d1e4a
16134 About Package Manager dialog needs to be updated
John Rice <john.rice@oracle.com>
parents:
1987
diff
changeset
|
84 |
os_name = portable.util.get_canonical_os_name() |
eeba083d1e4a
16134 About Package Manager dialog needs to be updated
John Rice <john.rice@oracle.com>
parents:
1987
diff
changeset
|
85 |
if os_name == 'sunos': |
eeba083d1e4a
16134 About Package Manager dialog needs to be updated
John Rice <john.rice@oracle.com>
parents:
1987
diff
changeset
|
86 |
os_ver += " (" + platform.uname()[3] + ")" |
eeba083d1e4a
16134 About Package Manager dialog needs to be updated
John Rice <john.rice@oracle.com>
parents:
1987
diff
changeset
|
87 |
return os_ver |
eeba083d1e4a
16134 About Package Manager dialog needs to be updated
John Rice <john.rice@oracle.com>
parents:
1987
diff
changeset
|
88 |
|
1573
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
89 |
def setup_logging(client_name): |
1650
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
90 |
log_path = os.path.join(LOG_DIR, client_name) |
1573
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
91 |
log_fmt = logging.Formatter( |
1650
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
92 |
"<b>%(levelname)s:</b> " + client_name + \ |
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
93 |
"\n%(asctime)s: %(filename)s: %(module)s: %(lineno)s:\n%(message)s") |
1573
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
94 |
|
1650
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
95 |
infolog_path = log_path + LOG_INFO_EXT |
1585
fe17b1cf5774
13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents:
1573
diff
changeset
|
96 |
try: |
1650
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
97 |
info_h = logging.handlers.RotatingFileHandler(infolog_path, |
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
98 |
maxBytes=1000000, backupCount=1) |
1585
fe17b1cf5774
13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents:
1573
diff
changeset
|
99 |
except IOError: |
fe17b1cf5774
13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents:
1573
diff
changeset
|
100 |
info_h = logging.StreamHandler(sys.stdout) |
fe17b1cf5774
13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents:
1573
diff
changeset
|
101 |
|
1573
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
102 |
info_t = _LogFilter(logging.INFO) |
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
103 |
info_h.addFilter(info_t) |
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
104 |
info_h.setFormatter(log_fmt) |
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
105 |
info_h.setLevel(logging.INFO) |
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
106 |
global_settings.info_log_handler = info_h |
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
107 |
|
1650
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
108 |
errlog_path = log_path + LOG_ERROR_EXT |
1585
fe17b1cf5774
13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents:
1573
diff
changeset
|
109 |
try: |
1650
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
110 |
err_h = logging.handlers.RotatingFileHandler(errlog_path, |
4538ffc7c034
13333 PM Provide user notification when errors written to log in GUI.
John Rice <john.rice@sun.com>
parents:
1649
diff
changeset
|
111 |
maxBytes=1000000, backupCount=1) |
1585
fe17b1cf5774
13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents:
1573
diff
changeset
|
112 |
except IOError: |
fe17b1cf5774
13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents:
1573
diff
changeset
|
113 |
err_h = logging.StreamHandler(sys.stderr) |
fe17b1cf5774
13309 Change priority of publishers without sufficient privileges got traceback
Michal Pryc <Michal.Pryc@Sun.Com>
parents:
1573
diff
changeset
|
114 |
|
1573
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
115 |
err_h.setFormatter(log_fmt) |
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
116 |
err_h.setLevel(logging.WARNING) |
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
117 |
global_settings.error_log_handler = err_h |
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
118 |
|
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
119 |
def shutdown_logging(): |
2041
ee746d3c19be
6084 Simplify Update Manager use same code as PM
John Rice <john.rice@oracle.com>
parents:
2034
diff
changeset
|
120 |
try: |
ee746d3c19be
6084 Simplify Update Manager use same code as PM
John Rice <john.rice@oracle.com>
parents:
2034
diff
changeset
|
121 |
global_settings.reset_logging() |
ee746d3c19be
6084 Simplify Update Manager use same code as PM
John Rice <john.rice@oracle.com>
parents:
2034
diff
changeset
|
122 |
logging.shutdown() |
ee746d3c19be
6084 Simplify Update Manager use same code as PM
John Rice <john.rice@oracle.com>
parents:
2034
diff
changeset
|
123 |
except IOError: |
ee746d3c19be
6084 Simplify Update Manager use same code as PM
John Rice <john.rice@oracle.com>
parents:
2034
diff
changeset
|
124 |
pass |
1573
ae7488fbff6a
12240 PM / UM need to intercept and display client messages
John Rice <john.rice@sun.com>
parents:
1538
diff
changeset
|
125 |
|
1336
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
126 |
def get_cache_dir(api_object): |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
127 |
img = api_object.img |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
128 |
cache_dir = os.path.join(img.imgdir, "gui_cache") |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
129 |
try: |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
130 |
__mkdir(cache_dir) |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
131 |
except OSError: |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
132 |
cache_dir = None |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
133 |
return cache_dir |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
134 |
|
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
135 |
def __mkdir(directory_path): |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
136 |
if not os.path.isdir(directory_path): |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
137 |
os.makedirs(directory_path) |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
138 |
|
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
139 |
def get_api_object(img_dir, progtrack): |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
140 |
api_o = None |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
141 |
api_o = api.ImageInterface(img_dir, |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
142 |
CLIENT_API_VERSION, |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
143 |
progtrack, None, global_settings.client_name) |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
144 |
return api_o |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
145 |
|
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
146 |
def read_cache_file(file_path): |
1686
c3ce86de2702
13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents:
1685
diff
changeset
|
147 |
data = [] |
c3ce86de2702
13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents:
1685
diff
changeset
|
148 |
try: |
c3ce86de2702
13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents:
1685
diff
changeset
|
149 |
fh = open(file_path, 'r') |
c3ce86de2702
13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents:
1685
diff
changeset
|
150 |
data = cPickle.load(fh) |
c3ce86de2702
13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents:
1685
diff
changeset
|
151 |
fh.close() |
2041
ee746d3c19be
6084 Simplify Update Manager use same code as PM
John Rice <john.rice@oracle.com>
parents:
2034
diff
changeset
|
152 |
except IOError: |
ee746d3c19be
6084 Simplify Update Manager use same code as PM
John Rice <john.rice@oracle.com>
parents:
2034
diff
changeset
|
153 |
pass |
1788
e43ea4447c6b
14699 packagemanager traceback during cache load
Padraig O'Briain <padraig.obriain@sun.com>
parents:
1736
diff
changeset
|
154 |
except: |
1686
c3ce86de2702
13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents:
1685
diff
changeset
|
155 |
pass |
1336
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
156 |
return data |
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
157 |
|
2ea22dad29e3
10192 /usr/lib/pm-checkforupdates emits warning when DISPLAY is not set.
Padraig O'Briain <padraig.obriain@sun.com>
parents:
diff
changeset
|
158 |
def dump_cache_file(file_path, data): |
1686
c3ce86de2702
13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents:
1685
diff
changeset
|
159 |
try: |
c3ce86de2702
13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents:
1685
diff
changeset
|
160 |
fh = open(file_path,"w") |
c3ce86de2702
13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents:
1685
diff
changeset
|
161 |
cPickle.dump(data, fh, True) |
c3ce86de2702
13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents:
1685
diff
changeset
|
162 |
fh.close() |
2041
ee746d3c19be
6084 Simplify Update Manager use same code as PM
John Rice <john.rice@oracle.com>
parents:
2034
diff
changeset
|
163 |
except IOError: |
ee746d3c19be
6084 Simplify Update Manager use same code as PM
John Rice <john.rice@oracle.com>
parents:
2034
diff
changeset
|
164 |
pass |
1788
e43ea4447c6b
14699 packagemanager traceback during cache load
Padraig O'Briain <padraig.obriain@sun.com>
parents:
1736
diff
changeset
|
165 |
except: |
1686
c3ce86de2702
13036 PM Persist expanded and selected Category state for each Publisher
John Rice <john.rice@sun.com>
parents:
1685
diff
changeset
|
166 |
pass |
1987
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
167 |
|
2078
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
168 |
def get_um_name(): |
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
169 |
return PKG_CLIENT_NAME_UM |
a13afe24c79a
17024 pm-updatemanager can't find display when running from cron
John Rice <john.rice@oracle.com>
parents:
2073
diff
changeset
|
170 |
|
1987
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
171 |
def get_catalogrefresh_exception_msg(cre): |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
172 |
if not isinstance(cre, api_errors.CatalogRefreshException): |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
173 |
return "" |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
174 |
msg = _("Catalog refresh error:\n") |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
175 |
if cre.succeeded < cre.total: |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
176 |
msg += _( |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
177 |
"Only %(suc)s out of %(tot)s catalogs successfully updated.\n") % \ |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
178 |
{"suc": cre.succeeded, "tot": cre.total} |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
179 |
|
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
180 |
for pub, err in cre.failed: |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
181 |
if isinstance(err, urllib2.HTTPError): |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
182 |
msg += "%s: %s - %s" % \ |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
183 |
(err.filename, err.code, err.msg) |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
184 |
elif isinstance(err, urllib2.URLError): |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
185 |
if err.args[0][0] == 8: |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
186 |
msg += "%s: %s" % \ |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
187 |
(urlparse.urlsplit( |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
188 |
pub["origin"])[1].split(":")[0], |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
189 |
err.args[0][1]) |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
190 |
else: |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
191 |
if isinstance(err.args[0], socket.timeout): |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
192 |
msg += "%s: %s" % \ |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
193 |
(pub["origin"], "timeout") |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
194 |
else: |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
195 |
msg += "%s: %s" % \ |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
196 |
(pub["origin"], err.args[0][1]) |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
197 |
else: |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
198 |
msg += str(err) |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
199 |
|
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
200 |
if cre.errmessage: |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
201 |
msg += cre.errmessage |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
202 |
|
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
203 |
return msg |
34494822ad14
10995 Update manager should indicate when there's a problem refreshing one or more repositories
Padraig O'Briain <padraig.obriain@oracle.com>
parents:
1970
diff
changeset
|
204 |