author | Rich Burridge <rich.burridge@sun.com> |
Thu, 23 Apr 2009 19:11:18 -0700 | |
changeset 1080 | 147a665c552c |
parent 1076 | db86977aa656 |
child 1081 | 0cc3e524ea7f |
permissions | -rw-r--r-- |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.4 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
2 |
# |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
3 |
# CDDL HEADER START |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
4 |
# |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
5 |
# The contents of this file are subject to the terms of the |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
6 |
# Common Development and Distribution License (the "License"). |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
7 |
# You may not use this file except in compliance with the License. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
8 |
# |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
9 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
10 |
# or http://www.opensolaris.org/os/licensing. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
11 |
# See the License for the specific language governing permissions |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
12 |
# and limitations under the License. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
13 |
# |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
15 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
16 |
# If applicable, add the following below this CDDL HEADER, with the |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
19 |
# |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
20 |
# CDDL HEADER END |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
21 |
# |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
22 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
23 |
# |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
786
diff
changeset
|
24 |
# Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
25 |
# Use is subject to license terms. |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
26 |
# |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
27 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
28 |
import copy |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
29 |
import errno |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
30 |
import httplib |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
31 |
import os |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
32 |
import socket |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
33 |
import simplejson as json |
1072
66ce6aa346d7
8132 __licenses should use StringIO
Rich Burridge <rich.burridge@sun.com>
parents:
1053
diff
changeset
|
34 |
import StringIO |
1032
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
35 |
import sys |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
36 |
import threading |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
37 |
import urllib |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
38 |
import urllib2 |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
39 |
|
1019
e61c57c724c9
7663 disable_fmri should be synchronous
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
996
diff
changeset
|
40 |
import pkg.client.actuator as actuator |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
41 |
import pkg.client.api_errors as api_errors |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
42 |
import pkg.client.bootenv as bootenv |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
43 |
import pkg.client.history as history |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
44 |
import pkg.client.image as image |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
45 |
import pkg.client.indexer as indexer |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
46 |
import pkg.client.publisher as publisher |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
47 |
import pkg.client.query_parser as query_p |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
48 |
import pkg.client.variant as variant |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
49 |
import pkg.fmri as fmri |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
50 |
import pkg.misc as misc |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
51 |
import pkg.search_errors as search_errors |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
52 |
|
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
53 |
from pkg.client.imageplan import EXECUTED_OK |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
54 |
from pkg.client import global_settings |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
55 |
from pkg.misc import versioned_urlopen |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
56 |
|
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
57 |
CURRENT_API_VERSION = 12 |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
58 |
CURRENT_P5I_VERSION = 1 |
696
6bbfd2dece6f
4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents:
688
diff
changeset
|
59 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
60 |
class ImageInterface(object): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
61 |
"""This class presents an interface to images that clients may use. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
62 |
There is a specific order of methods which must be used to install |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
63 |
or uninstall packages, or update an image. First, plan_install, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
64 |
plan_uninstall, or plan_update_all must be called. After that |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
65 |
method completes successfully, describe may be called, and prepare |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
66 |
must be called. Finally, execute_plan may be called to implement |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
67 |
the previous created plan. The other methods do not hav an ordering |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
68 |
imposed upon them, and may be used as needed. Cancel may only be |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
69 |
invoked while a cancelable method is running.""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
70 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
71 |
# Constants used to reference specific values that info can return. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
72 |
INFO_FOUND = 0 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
73 |
INFO_MISSING = 1 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
74 |
INFO_MULTI_MATCH = 2 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
75 |
INFO_ILLEGALS = 3 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
76 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
77 |
# Private constants used for tracking which type of plan was made. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
78 |
__INSTALL = 1 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
79 |
__UNINSTALL = 2 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
80 |
__IMAGE_UPDATE = 3 |
696
6bbfd2dece6f
4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents:
688
diff
changeset
|
81 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
82 |
def __init__(self, img_path, version_id, progesstracker, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
83 |
cancel_state_callable, pkg_client_name): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
84 |
"""Constructs an ImageInterface. img_path should point to an |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
85 |
existing image. version_id indicates the version of the api |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
86 |
the client is expecting to use. progesstracker is the |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
87 |
progresstracker the client wants the api to use for UI |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
88 |
callbacks. cancel_state_callable is a function which the client |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
89 |
wishes to have called each time whether the operation can be |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
90 |
canceled changes. It can raise VersionException and |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
91 |
ImageNotFoundException.""" |
696
6bbfd2dece6f
4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents:
688
diff
changeset
|
92 |
|
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
93 |
compatible_versions = set([12]) |
696
6bbfd2dece6f
4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents:
688
diff
changeset
|
94 |
|
598
c53f6107fdb6
2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents:
594
diff
changeset
|
95 |
if version_id not in compatible_versions: |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
96 |
raise api_errors.VersionException(CURRENT_API_VERSION, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
97 |
version_id) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
98 |
|
696
6bbfd2dece6f
4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents:
688
diff
changeset
|
99 |
# The image's History object will use client_name from |
6bbfd2dece6f
4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents:
688
diff
changeset
|
100 |
# global_settings, but if the program forgot to set it, |
6bbfd2dece6f
4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents:
688
diff
changeset
|
101 |
# we'll go ahead and do so here. |
6bbfd2dece6f
4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents:
688
diff
changeset
|
102 |
if global_settings.client_name is None: |
6bbfd2dece6f
4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents:
688
diff
changeset
|
103 |
global_settings.client_name = pkg_client_name |
6bbfd2dece6f
4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents:
688
diff
changeset
|
104 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
105 |
# These variables are private and not part of the API. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
106 |
self.img = image.Image() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
107 |
self.img.find_root(img_path) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
108 |
self.img.load_config() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
109 |
self.progresstracker = progesstracker |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
110 |
self.cancel_state_callable = cancel_state_callable |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
111 |
self.plan_type = None |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
112 |
self.plan_desc = None |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
113 |
self.prepared = False |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
114 |
self.executed = False |
884
d780afc023ff
3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents:
838
diff
changeset
|
115 |
self.be_name = None |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
116 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
117 |
self.__can_be_canceled = False |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
118 |
self.__canceling = False |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
119 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
120 |
self.__activity_lock = threading.Lock() |
884
d780afc023ff
3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents:
838
diff
changeset
|
121 |
|
d780afc023ff
3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents:
838
diff
changeset
|
122 |
@staticmethod |
d780afc023ff
3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents:
838
diff
changeset
|
123 |
def check_be_name(be_name): |
1076
db86977aa656
8048 image update doesn't check to see if specified be-name already exists
Rich Burridge <rich.burridge@sun.com>
parents:
1072
diff
changeset
|
124 |
bootenv.BootEnv.check_be_name(be_name) |
1080
147a665c552c
8394 image-update without a --be-name fails.
Rich Burridge <rich.burridge@sun.com>
parents:
1076
diff
changeset
|
125 |
return True |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
126 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
127 |
def plan_install(self, pkg_list, filters, refresh_catalogs=True, |
598
c53f6107fdb6
2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents:
594
diff
changeset
|
128 |
noexecute=False, verbose=False, update_index=True): |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
129 |
"""Contructs a plan to install the packages provided in |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
130 |
pkg_list. pkg_list is a list of packages to install. filters |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
131 |
is a list of filters to apply to the actions of the installed |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
132 |
packages. refresh_catalogs controls whether the catalogs will |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
133 |
automatically be refreshed. noexecute determines whether the |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
134 |
history will be recorded after planning is finished. verbose |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
135 |
controls whether verbose debugging output will be printed to the |
594
b072bc027c54
3770 pkg install when authority unavailable traces back
Brock Pytlik <bpytlik@sun.com>
parents:
565
diff
changeset
|
136 |
terminal. Its existence is temporary. It returns a tuple of |
b072bc027c54
3770 pkg install when authority unavailable traces back
Brock Pytlik <bpytlik@sun.com>
parents:
565
diff
changeset
|
137 |
two things. The first is a boolean which tells the client |
b072bc027c54
3770 pkg install when authority unavailable traces back
Brock Pytlik <bpytlik@sun.com>
parents:
565
diff
changeset
|
138 |
whether there is anything to do. The third is either None, or an |
b072bc027c54
3770 pkg install when authority unavailable traces back
Brock Pytlik <bpytlik@sun.com>
parents:
565
diff
changeset
|
139 |
exception which indicates partial success. It can raise |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
140 |
PlanCreationException, NetworkUnavailableException, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
141 |
PermissionsException and InventoryException. The noexecute |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
142 |
argument is included for compatibility with operational |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
143 |
history. The hope is it can be removed in the future.""" |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
144 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
145 |
self.__activity_lock.acquire() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
146 |
try: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
147 |
self.__set_can_be_canceled(True) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
148 |
if self.plan_type is not None: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
149 |
raise api_errors.PlanExistsException( |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
150 |
self.plan_type) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
151 |
try: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
152 |
self.log_operation_start("install") |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
153 |
# Verify validity of certificates before |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
154 |
# attempting network operations. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
155 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
156 |
self.img.check_cert_validity() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
157 |
except api_errors.ExpiringCertificate, e: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
158 |
misc.emsg(e) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
159 |
except api_errors.CertificateError, e: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
160 |
self.log_operation_end(error=e) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
161 |
raise |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
162 |
|
594
b072bc027c54
3770 pkg install when authority unavailable traces back
Brock Pytlik <bpytlik@sun.com>
parents:
565
diff
changeset
|
163 |
exception_caught = None |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
164 |
if refresh_catalogs: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
165 |
try: |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
166 |
self.img.refresh_publishers( |
625
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
615
diff
changeset
|
167 |
progtrack=self.progresstracker) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
168 |
except api_errors.CatalogRefreshException, e: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
169 |
if not e.succeeded: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
170 |
raise |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
171 |
exception_caught = e |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
172 |
else: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
173 |
# If refresh wasn't called, the catalogs |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
174 |
# have to be manually loaded. |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
175 |
self.img.load_catalogs( |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
176 |
self.progresstracker) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
177 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
178 |
self.img.make_install_plan(pkg_list, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
179 |
self.progresstracker, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
180 |
self.__check_cancelation, noexecute, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
181 |
filters=filters, verbose=verbose) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
182 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
183 |
assert self.img.imageplan |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
184 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
185 |
if self.__canceling: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
186 |
raise api_errors.CanceledException() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
187 |
self.__set_can_be_canceled(False) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
188 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
189 |
if not noexecute: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
190 |
self.plan_type = self.__INSTALL |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
191 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
192 |
self.plan_desc = PlanDescription( |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
193 |
self.img.imageplan) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
194 |
if self.img.imageplan.nothingtodo() or \ |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
195 |
noexecute: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
196 |
self.log_operation_end( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
197 |
result=history.RESULT_NOTHING_TO_DO) |
598
c53f6107fdb6
2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents:
594
diff
changeset
|
198 |
self.img.imageplan.update_index = update_index |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
199 |
res = not self.img.imageplan.nothingtodo() |
716
b836c1b14137
4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents:
707
diff
changeset
|
200 |
except api_errors.PlanCreationException, e: |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
201 |
self.__set_history_PlanCreationException(e) |
716
b836c1b14137
4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents:
707
diff
changeset
|
202 |
self.__reset_unlock() |
b836c1b14137
4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents:
707
diff
changeset
|
203 |
raise |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
204 |
except (api_errors.CanceledException, fmri.IllegalFmri, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
205 |
Exception), e: |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
206 |
self.log_operation_end(error=e) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
207 |
self.__reset_unlock() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
208 |
raise |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
209 |
finally: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
210 |
self.__activity_lock.release() |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
211 |
|
598
c53f6107fdb6
2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents:
594
diff
changeset
|
212 |
return res, exception_caught |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
213 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
214 |
def plan_uninstall(self, pkg_list, recursive_removal, noexecute=False, |
598
c53f6107fdb6
2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents:
594
diff
changeset
|
215 |
verbose=False, update_index=True): |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
216 |
"""Contructs a plan to uninstall the packages provided in |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
217 |
pkg_list. pkg_list is a list of packages to install. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
218 |
recursive_removal controls whether recursive removal is |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
219 |
allowed. noexecute determines whether the history will be |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
220 |
recorded after planning is finished. verbose controls whether |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
221 |
verbose debugging output will be printed to the terminal. Its |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
222 |
existence is temporary. If there are things to do to complete |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
223 |
the uninstall, it returns True, otherwise it returns False. It |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
224 |
can raise NonLeafPackageException and PlanCreationException.""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
225 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
226 |
self.__activity_lock.acquire() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
227 |
try: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
228 |
self.__set_can_be_canceled(True) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
229 |
if self.plan_type is not None: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
230 |
raise api_errors.PlanExistsException( |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
231 |
self.plan_type) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
232 |
try: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
233 |
self.log_operation_start("uninstall") |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
234 |
self.img.load_catalogs(self.progresstracker) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
235 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
236 |
self.img.make_uninstall_plan(pkg_list, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
237 |
recursive_removal, self.progresstracker, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
238 |
self.__check_cancelation, noexecute, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
239 |
verbose=verbose) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
240 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
241 |
assert self.img.imageplan |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
242 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
243 |
if self.__canceling: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
244 |
raise api_errors.CanceledException() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
245 |
self.__set_can_be_canceled(False) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
246 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
247 |
if not noexecute: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
248 |
self.plan_type = self.__UNINSTALL |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
249 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
250 |
self.plan_desc = PlanDescription( |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
251 |
self.img.imageplan) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
252 |
if noexecute: |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
253 |
self.log_operation_end( |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
254 |
result=history.RESULT_NOTHING_TO_DO) |
598
c53f6107fdb6
2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents:
594
diff
changeset
|
255 |
self.img.imageplan.update_index = update_index |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
256 |
res = not self.img.imageplan.nothingtodo() |
716
b836c1b14137
4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents:
707
diff
changeset
|
257 |
except api_errors.PlanCreationException, e: |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
258 |
self.__set_history_PlanCreationException(e) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
259 |
self.__reset_unlock() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
260 |
raise |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
261 |
except Exception, e: |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
262 |
self.log_operation_end(error=e) |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
263 |
self.__reset_unlock() |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
264 |
raise |
1032
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
265 |
except: |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
266 |
# Handle exceptions that are not subclasses of |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
267 |
# Exception. |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
268 |
exc_type, exc_value, exc_traceback = \ |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
269 |
sys.exc_info() |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
270 |
|
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
271 |
self.log_operation_end(error=exc_type) |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
272 |
self.__reset_unlock() |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
273 |
raise |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
274 |
finally: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
275 |
self.__activity_lock.release() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
276 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
277 |
return res |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
278 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
279 |
def plan_update_all(self, actual_cmd, refresh_catalogs=True, |
884
d780afc023ff
3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents:
838
diff
changeset
|
280 |
noexecute=False, force=False, verbose=False, update_index=True, |
d780afc023ff
3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents:
838
diff
changeset
|
281 |
be_name=None): |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
282 |
"""Creates a plan to update all packages on the system to the |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
283 |
latest known versions. actual_cmd is the command used to start |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
284 |
the client. It is used to determine the image to check whether |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
285 |
SUNWipkg is up to date. refresh_catalogs controls whether the |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
286 |
catalogs will automatically be refreshed. noexecute determines |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
287 |
whether the history will be recorded after planning is finished. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
288 |
force controls whether update should proceed even if ipkg is not |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
289 |
up to date. verbose controls whether verbose debugging output |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
290 |
will be printed to the terminal. Its existence is temporary. It |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
291 |
returns a tuple of three things. The first is a boolean which |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
292 |
tells the client whether there is anything to do. The second |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
293 |
tells whether the image is an opensolaris image. The third is |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
294 |
either None, or an exception which indicates partial success. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
295 |
This is currently used to indicate a failure in refreshing |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
296 |
catalogs. It can raise CatalogRefreshException, |
685
6f53483db920
1469 image-update by unprivileged user should give better error message
Brock Pytlik <bpytlik@sun.com>
parents:
655
diff
changeset
|
297 |
IpkgOutOfDateException, NetworkUnavailableException, |
6f53483db920
1469 image-update by unprivileged user should give better error message
Brock Pytlik <bpytlik@sun.com>
parents:
655
diff
changeset
|
298 |
PlanCreationException and PermissionsException.""" |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
299 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
300 |
self.__activity_lock.acquire() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
301 |
try: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
302 |
self.__set_can_be_canceled(True) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
303 |
if self.plan_type is not None: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
304 |
raise api_errors.PlanExistsException( |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
305 |
self.plan_type) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
306 |
try: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
307 |
self.log_operation_start("image-update") |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
308 |
exception_caught = None |
1076
db86977aa656
8048 image update doesn't check to see if specified be-name already exists
Rich Burridge <rich.burridge@sun.com>
parents:
1072
diff
changeset
|
309 |
self.check_be_name(be_name) |
884
d780afc023ff
3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents:
838
diff
changeset
|
310 |
self.be_name = be_name |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
311 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
312 |
# Verify validity of certificates before |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
313 |
# attempting network operations. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
314 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
315 |
self.img.check_cert_validity() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
316 |
except api_errors.ExpiringCertificate, e: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
317 |
misc.emsg(e) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
318 |
except api_errors.CertificateError, e: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
319 |
self.log_operation_end(error=e) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
320 |
raise |
625
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
615
diff
changeset
|
321 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
322 |
if refresh_catalogs: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
323 |
try: |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
324 |
self.img.refresh_publishers( |
625
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
615
diff
changeset
|
325 |
progtrack=self.progresstracker) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
326 |
except api_errors.CatalogRefreshException, e: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
327 |
if not e.succeeded: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
328 |
raise |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
329 |
exception_caught = e |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
330 |
else: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
331 |
# If refresh wasn't called, the catalogs |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
332 |
# have to be manually loaded. |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
333 |
self.img.load_catalogs( |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
334 |
self.progresstracker) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
335 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
336 |
# If we can find SUNWipkg and SUNWcs in the |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
337 |
# target image, then we assume this is a valid |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
338 |
# opensolaris image, and activate some |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
339 |
# special case behaviors. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
340 |
opensolaris_image = True |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
341 |
fmris, notfound, illegals = \ |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
342 |
self.img.installed_fmris_from_args( |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
343 |
["SUNWipkg", "SUNWcs"]) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
344 |
assert(len(illegals) == 0) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
345 |
if notfound: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
346 |
opensolaris_image = False |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
347 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
348 |
if opensolaris_image and not force: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
349 |
try: |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
350 |
if not self.img.ipkg_is_up_to_date( |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
351 |
actual_cmd, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
352 |
self.__check_cancelation, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
353 |
noexecute, |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
354 |
refresh_allowed=refresh_catalogs, |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
355 |
progtrack=self.progresstracker): |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
356 |
error = api_errors.IpkgOutOfDateException() |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
357 |
self.log_operation_end(error=error) |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
358 |
raise error |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
359 |
except api_errors.ImageNotFoundException: |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
360 |
# Can't do anything in this |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
361 |
# case; so proceed. |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
362 |
pass |
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
625
diff
changeset
|
363 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
364 |
pkg_list = [ |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
365 |
ipkg.get_pkg_stem() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
366 |
for ipkg in self.img.gen_installed_pkgs() |
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
625
diff
changeset
|
367 |
] |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
368 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
369 |
self.img.make_install_plan(pkg_list, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
370 |
self.progresstracker, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
371 |
self.__check_cancelation, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
372 |
noexecute, verbose=verbose) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
373 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
374 |
assert self.img.imageplan |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
375 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
376 |
if self.__canceling: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
377 |
self.__reset_unlock() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
378 |
raise api_errors.CanceledException() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
379 |
self.__set_can_be_canceled(False) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
380 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
381 |
if not noexecute: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
382 |
self.plan_type = self.__IMAGE_UPDATE |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
383 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
384 |
self.plan_desc = PlanDescription( |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
385 |
self.img.imageplan) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
386 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
387 |
if self.img.imageplan.nothingtodo() or \ |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
388 |
noexecute: |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
389 |
self.log_operation_end( |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
390 |
result=history.RESULT_NOTHING_TO_DO) |
598
c53f6107fdb6
2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents:
594
diff
changeset
|
391 |
self.img.imageplan.update_index = update_index |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
392 |
res = not self.img.imageplan.nothingtodo() |
716
b836c1b14137
4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents:
707
diff
changeset
|
393 |
except api_errors.PlanCreationException, e: |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
394 |
self.__set_history_PlanCreationException(e) |
716
b836c1b14137
4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents:
707
diff
changeset
|
395 |
self.__reset_unlock() |
b836c1b14137
4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents:
707
diff
changeset
|
396 |
raise |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
397 |
except api_errors.IpkgOutOfDateException: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
398 |
self.__reset_unlock() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
399 |
raise |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
400 |
except Exception, e: |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
401 |
self.log_operation_end(error=e) |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
402 |
self.__reset_unlock() |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
403 |
raise |
1032
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
404 |
except: |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
405 |
# Handle exceptions that are not subclasses of |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
406 |
# Exception. |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
407 |
exc_type, exc_value, exc_traceback = \ |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
408 |
sys.exc_info() |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
409 |
|
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
410 |
self.log_operation_end(error=exc_type) |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
411 |
self.__reset_unlock() |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
412 |
raise |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
413 |
finally: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
414 |
self.__activity_lock.release() |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
415 |
|
598
c53f6107fdb6
2863 pkg install should have a way to disable indexing
Brock Pytlik <bpytlik@sun.com>
parents:
594
diff
changeset
|
416 |
return res, opensolaris_image, exception_caught |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
417 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
418 |
def describe(self): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
419 |
"""Returns None if no plan is ready yet, otherwise returns |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
420 |
a PlanDescription""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
421 |
return self.plan_desc |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
422 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
423 |
def prepare(self): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
424 |
"""Takes care of things which must be done before the plan |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
425 |
can be executed. This includes downloading the packages to |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
426 |
disk and preparing the indexes to be updated during |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
427 |
execution. It can raise ProblematicPermissionsIndexException, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
428 |
and PlanMissingException. Should only be called once a |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
429 |
plan_X method has been called.""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
430 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
431 |
self.__activity_lock.acquire() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
432 |
self.__set_can_be_canceled(True) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
433 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
434 |
try: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
435 |
try: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
436 |
if not self.img.imageplan: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
437 |
raise api_errors.PlanMissingException() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
438 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
439 |
if self.prepared: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
440 |
raise api_errors.AlreadyPreparedException() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
441 |
assert self.plan_type == self.__INSTALL or \ |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
442 |
self.plan_type == self.__UNINSTALL or \ |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
443 |
self.plan_type == self.__IMAGE_UPDATE |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
444 |
try: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
445 |
self.img.imageplan.preexecute() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
446 |
except search_errors.ProblematicPermissionsIndexException, e: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
447 |
self.img.cleanup_downloads() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
448 |
raise api_errors.ProblematicPermissionsIndexException(e) |
1032
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
449 |
except: |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
450 |
self.img.cleanup_downloads() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
451 |
raise |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
452 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
453 |
if self.__canceling: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
454 |
self.img.cleanup_downloads() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
455 |
raise api_errors.CanceledException() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
456 |
self.prepared = True |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
457 |
except Exception, e: |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
458 |
if self.img.history.operation_name: |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
459 |
# If an operation is in progress, log |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
460 |
# the error and mark its end. |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
461 |
self.log_operation_end(error=e) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
462 |
raise |
1032
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
463 |
except: |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
464 |
# Handle exceptions that are not subclasses of |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
465 |
# Exception. |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
466 |
if self.img.history.operation_name: |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
467 |
# If an operation is in progress, log |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
468 |
# the error and mark its end. |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
469 |
exc_type, exc_value, exc_traceback = \ |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
470 |
sys.exc_info() |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
471 |
self.log_operation_end(error=exc_type) |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
472 |
raise |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
473 |
finally: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
474 |
self.__set_can_be_canceled(False) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
475 |
self.__activity_lock.release() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
476 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
477 |
def execute_plan(self): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
478 |
"""Executes the plan. This is uncancelable one it begins. It |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
479 |
can raise CorruptedIndexException, |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
480 |
ProblematicPermissionsIndexException, ImageplanStateException, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
481 |
ImageUpdateOnLiveImageException, and PlanMissingException. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
482 |
Should only be called after the prepare method has been |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
483 |
called.""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
484 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
485 |
self.__activity_lock.acquire() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
486 |
self.__set_can_be_canceled(False) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
487 |
try: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
488 |
if not self.img.imageplan: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
489 |
raise api_errors.PlanMissingException() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
490 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
491 |
if not self.prepared: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
492 |
raise api_errors.PrematureExecutionException() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
493 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
494 |
if self.executed: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
495 |
raise api_errors.AlreadyExecutedException() |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
496 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
497 |
assert self.plan_type == self.__INSTALL or \ |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
498 |
self.plan_type == self.__UNINSTALL or \ |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
499 |
self.plan_type == self.__IMAGE_UPDATE |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
500 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
501 |
try: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
502 |
be = bootenv.BootEnv(self.img.get_root()) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
503 |
except RuntimeError: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
504 |
be = bootenv.BootEnvNull(self.img.get_root()) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
505 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
506 |
if self.plan_type is self.__IMAGE_UPDATE: |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
507 |
try: |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
508 |
be.init_image_recovery(self.img, self.be_name) |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
509 |
except Exception, e: |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
510 |
self.log_operation_end(error=e) |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
511 |
raise |
1032
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
512 |
except: |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
513 |
# Handle exceptions that are not subclasses of |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
514 |
# Exception. |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
515 |
exc_type, exc_value, exc_traceback = \ |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
516 |
sys.exc_info() |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
517 |
self.log_operation_end(error=exc_type) |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
518 |
raise |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
519 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
520 |
if self.img.is_liveroot(): |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
521 |
e = api_errors.ImageUpdateOnLiveImageException() |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
522 |
self.log_operation_end(error=e) |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
523 |
raise e |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
524 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
525 |
try: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
526 |
self.img.imageplan.execute() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
527 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
528 |
if self.plan_type is self.__IMAGE_UPDATE: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
529 |
be.activate_image() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
530 |
else: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
531 |
be.activate_install_uninstall() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
532 |
ret_code = 0 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
533 |
except RuntimeError, e: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
534 |
if self.plan_type is self.__IMAGE_UPDATE: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
535 |
be.restore_image() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
536 |
else: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
537 |
be.restore_install_uninstall() |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
538 |
# Must be done after bootenv restore. |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
539 |
self.log_operation_end(error=e) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
540 |
self.img.cleanup_downloads() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
541 |
raise |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
542 |
except search_errors.ProblematicPermissionsIndexException, e: |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
543 |
error = api_errors.ProblematicPermissionsIndexException(e) |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
544 |
self.log_operation_end(error=error) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
545 |
self.img.cleanup_downloads() |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
546 |
raise error |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
547 |
except (search_errors.InconsistentIndexException, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
548 |
search_errors.PartialIndexingException), e: |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
549 |
error = api_errors.CorruptedIndexException(e) |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
550 |
self.log_operation_end(error=error) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
551 |
self.img.cleanup_downloads() |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
552 |
raise error |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
553 |
except search_errors.MainDictParsingException, e: |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
554 |
error = api_errors.MainDictParsingException(e) |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
555 |
self.log_operation_end(error=error) |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
556 |
self.img.cleanup_downloads() |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
557 |
raise error |
1019
e61c57c724c9
7663 disable_fmri should be synchronous
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
996
diff
changeset
|
558 |
except actuator.NonzeroExitException, e: |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
559 |
# Won't happen during image-update |
1019
e61c57c724c9
7663 disable_fmri should be synchronous
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
996
diff
changeset
|
560 |
be.restore_install_uninstall() |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
561 |
error = api_errors.ActuatorException(e) |
1019
e61c57c724c9
7663 disable_fmri should be synchronous
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
996
diff
changeset
|
562 |
self.img.cleanup_downloads() |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
563 |
self.log_operation_end(error=error) |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
564 |
raise error |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
565 |
except Exception, e: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
566 |
if self.plan_type is self.__IMAGE_UPDATE: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
567 |
be.restore_image() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
568 |
else: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
569 |
be.restore_install_uninstall() |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
570 |
# Must be done after bootenv restore. |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
571 |
self.log_operation_end(error=e) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
572 |
self.img.cleanup_downloads() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
573 |
raise |
1032
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
574 |
except: |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
575 |
# Handle exceptions that are not subclasses of |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
576 |
# Exception. |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
577 |
exc_type, exc_value, exc_traceback = \ |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
578 |
sys.exc_info() |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
579 |
|
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
580 |
if self.plan_type is self.__IMAGE_UPDATE: |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
581 |
be.restore_image() |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
582 |
else: |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
583 |
be.restore_install_uninstall() |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
584 |
# Must be done after bootenv restore. |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
585 |
self.log_operation_end(error=exc_type) |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
586 |
self.img.cleanup_downloads() |
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
587 |
raise |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
588 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
589 |
if self.img.imageplan.state != EXECUTED_OK: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
590 |
if self.plan_type is self.__IMAGE_UPDATE: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
591 |
be.restore_image() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
592 |
else: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
593 |
be.restore_install_uninstall() |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
594 |
|
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
595 |
error = api_errors.ImageplanStateException( |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
596 |
self.img.imageplan.state) |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
597 |
# Must be done after bootenv restore. |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
598 |
self.log_operation_end(error=error) |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
599 |
raise error |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
600 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
601 |
self.img.cleanup_downloads() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
602 |
self.img.cleanup_cached_content() |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
603 |
|
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
604 |
# If the end of the operation wasn't already logged |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
605 |
# by one of the above operations, then log it as |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
606 |
# ending now. |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
607 |
if self.img.history.operation_name: |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
608 |
self.log_operation_end() |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
609 |
self.executed = True |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
610 |
finally: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
611 |
self.__activity_lock.release() |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
612 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
613 |
def refresh(self, full_refresh=False, pubs=None, immediate=False): |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
614 |
"""Refreshes the metadata (e.g. catalog) for one or more |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
615 |
publishers. |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
616 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
617 |
'full_refresh' is an optional boolean value indicating whether |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
618 |
a full retrieval of publisher metadata (e.g. catalogs) or only |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
619 |
an update to the existing metadata should be performed. When |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
620 |
True, 'immediate' is also set to True. |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
621 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
622 |
'pubs' is a list of publisher prefixes or publisher objects |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
623 |
to refresh. Passing an empty list or using the default value |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
624 |
implies all publishers. |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
625 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
626 |
'immediate' is an optional boolean value indicating whether the |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
627 |
a refresh should occur now. If False, a publisher's selected |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
628 |
repository will only be checked for updates if the update |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
629 |
interval period recorded in the image configuration has been |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
630 |
exceeded; ignored when 'full_refresh' is True. |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
631 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
632 |
Currently returns an image object, allowing existing code to |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
633 |
work while the rest of the API is put into place.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
634 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
635 |
self.__activity_lock.acquire() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
636 |
self.__set_can_be_canceled(False) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
637 |
try: |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
638 |
self.img.refresh_publishers(full_refresh=full_refresh, |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
639 |
immediate=immediate, pubs=pubs, |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
640 |
progtrack=self.progresstracker) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
641 |
return self.img |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
642 |
finally: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
643 |
self.__activity_lock.release() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
644 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
645 |
def __licenses(self, mfst, local): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
646 |
"""Private function. Returns the license info from the |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
647 |
manifest mfst. Local controls whether the information is |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
648 |
retrieved locally.""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
649 |
license_lst = [] |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
650 |
for lic in mfst.gen_actions_by_type("license"): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
651 |
if not local: |
1072
66ce6aa346d7
8132 __licenses should use StringIO
Rich Burridge <rich.burridge@sun.com>
parents:
1053
diff
changeset
|
652 |
s = StringIO.StringIO() |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
653 |
hash_val = misc.gunzip_from_stream( |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
654 |
lic.get_remote_opener(self.img, |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
655 |
mfst.fmri)(), s) |
1072
66ce6aa346d7
8132 __licenses should use StringIO
Rich Burridge <rich.burridge@sun.com>
parents:
1053
diff
changeset
|
656 |
text = s.getvalue() |
66ce6aa346d7
8132 __licenses should use StringIO
Rich Burridge <rich.burridge@sun.com>
parents:
1053
diff
changeset
|
657 |
s.close() |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
658 |
else: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
659 |
text = lic.get_local_opener(self.img, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
660 |
mfst.fmri)().read()[:-1] |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
661 |
license_lst.append(LicenseInfo(text)) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
662 |
return license_lst |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
663 |
|
917
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
664 |
def info(self, fmri_strings, local, info_needed): |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
665 |
"""Gathers information about fmris. fmri_strings is a list |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
666 |
of fmri_names for which information is desired. local |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
667 |
determines whether to retrieve the information locally. It |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
668 |
returns a dictionary of lists. The keys for the dictionary are |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
669 |
the constants specified in the class definition. The values are |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
670 |
lists of PackageInfo objects or strings.""" |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
671 |
|
917
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
672 |
bad_opts = info_needed - PackageInfo.ALL_OPTIONS |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
673 |
if bad_opts: |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
674 |
raise api_errors.UnrecognizedOptionsToInfo(bad_opts) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
675 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
676 |
self.log_operation_start("info") |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
677 |
self.img.load_catalogs(self.progresstracker) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
678 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
679 |
fmris = [] |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
680 |
notfound = [] |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
681 |
multiple_matches = [] |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
682 |
illegals = [] |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
683 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
684 |
if local: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
685 |
fmris, notfound, illegals = \ |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
686 |
self.img.installed_fmris_from_args(fmri_strings) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
687 |
if not fmris and not notfound and not illegals: |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
688 |
self.log_operation_end( |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
689 |
result=history.RESULT_NOTHING_TO_DO) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
690 |
raise api_errors.NoPackagesInstalledException() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
691 |
else: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
692 |
# Verify validity of certificates before attempting |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
693 |
# network operations. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
694 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
695 |
self.img.check_cert_validity() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
696 |
except api_errors.ExpiringCertificate, e: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
697 |
misc.emsg(e) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
698 |
except api_errors.CertificateError, e: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
699 |
self.log_operation_end(error=e) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
700 |
raise |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
701 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
702 |
# XXX This loop really needs not to be copied from |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
703 |
# Image.make_install_plan()! |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
704 |
for p in fmri_strings: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
705 |
try: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
706 |
matches = list(self.img.inventory([ p ], |
1045
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1044
diff
changeset
|
707 |
all_known=True, ordered=False)) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
708 |
except api_errors.InventoryException, e: |
707
d37b19989de2
4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents:
696
diff
changeset
|
709 |
assert(len(e.notfound) == 1 or \ |
d37b19989de2
4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents:
696
diff
changeset
|
710 |
len(e.illegal) == 1) |
d37b19989de2
4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents:
696
diff
changeset
|
711 |
if e.notfound: |
d37b19989de2
4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents:
696
diff
changeset
|
712 |
notfound.append(e.notfound[0]) |
d37b19989de2
4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents:
696
diff
changeset
|
713 |
else: |
d37b19989de2
4878 pkg info traceback when given invalid input
Brock Pytlik <bpytlik@sun.com>
parents:
696
diff
changeset
|
714 |
illegals.append(e.illegal[0]) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
715 |
err = 1 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
716 |
continue |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
717 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
718 |
pnames = {} |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
719 |
pmatch = [] |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
720 |
npnames = {} |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
721 |
npmatch = [] |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
722 |
for m, state in matches: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
723 |
if m.preferred_publisher(): |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
724 |
pnames[m.get_pkg_stem()] = 1 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
725 |
pmatch.append(m) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
726 |
else: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
727 |
npnames[m.get_pkg_stem()] = 1 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
728 |
npmatch.append(m) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
729 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
730 |
if len(pnames.keys()) > 1: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
731 |
multiple_matches.append( |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
732 |
(p, pnames.keys())) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
733 |
error = 1 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
734 |
continue |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
735 |
elif len(pnames.keys()) < 1 and \ |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
736 |
len(npnames.keys()) > 1: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
737 |
multiple_matches.append( |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
738 |
(p, pnames.keys())) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
739 |
error = 1 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
740 |
continue |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
741 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
742 |
# matches is a list reverse sorted by version, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
743 |
# so take the first; i.e., the latest. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
744 |
if len(pmatch) > 0: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
745 |
fmris.append(pmatch[0]) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
746 |
else: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
747 |
fmris.append(npmatch[0]) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
748 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
749 |
pis = [] |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
750 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
751 |
for f in fmris: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
752 |
pub = name = version = release = None |
917
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
753 |
build_release = branch = packaging_date = None |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
754 |
if PackageInfo.IDENTITY in info_needed: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
755 |
pub, name, version = f.tuple() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
756 |
pub = fmri.strip_pub_pfx(pub) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
757 |
release = version.release |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
758 |
build_release = version.build_release |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
759 |
branch = version.branch |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
760 |
packaging_date = version.get_timestamp().ctime() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
761 |
pref_pub = None |
938
eeb932b9b44e
7336 putback for 5871 missed a few vestiges of authority
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
926
diff
changeset
|
762 |
if PackageInfo.PREF_PUBLISHER in info_needed: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
763 |
pref_pub = False |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
764 |
if f.preferred_publisher(): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
765 |
pref_pub = True |
917
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
766 |
state = None |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
767 |
if PackageInfo.STATE in info_needed: |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
768 |
if self.img.is_installed(f): |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
769 |
state = PackageInfo.INSTALLED |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
770 |
else: |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
771 |
state = PackageInfo.NOT_INSTALLED |
615
aeeeb9f31173
4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents:
610
diff
changeset
|
772 |
links = hardlinks = files = dirs = dependencies = None |
917
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
773 |
summary = size = licenses = cat_info = None |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
774 |
|
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
775 |
if (frozenset([PackageInfo.SIZE, PackageInfo.LICENSES, |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
776 |
PackageInfo.SUMMARY, PackageInfo.CATEGORIES]) | |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
777 |
PackageInfo.ACTION_OPTIONS) & info_needed: |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
778 |
mfst = self.img.get_manifest(f) |
1044
046981c42149
8102 pkg.client.api info reports size of zero for packages with cached manifests
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
1032
diff
changeset
|
779 |
excludes = self.img.list_excludes() |
917
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
780 |
if PackageInfo.SIZE in info_needed: |
1044
046981c42149
8102 pkg.client.api info reports size of zero for packages with cached manifests
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
1032
diff
changeset
|
781 |
size = mfst.get_size(excludes=excludes) |
917
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
782 |
if PackageInfo.LICENSES in info_needed: |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
783 |
licenses = self.__licenses(mfst, local) |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
784 |
if PackageInfo.SUMMARY in info_needed: |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
785 |
summary = mfst.get("description", "") |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
786 |
|
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
787 |
if PackageInfo.ACTION_OPTIONS & info_needed: |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
788 |
if PackageInfo.LINKS in info_needed: |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
789 |
links = list( |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
790 |
mfst.gen_key_attribute_value_by_type( |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
791 |
"link", excludes)) |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
792 |
if PackageInfo.HARDLINKS in info_needed: |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
793 |
hardlinks = list( |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
794 |
mfst.gen_key_attribute_value_by_type( |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
795 |
"hardlink", excludes)) |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
796 |
if PackageInfo.FILES in info_needed: |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
797 |
files = list( |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
798 |
mfst.gen_key_attribute_value_by_type( |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
799 |
"file", excludes)) |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
800 |
if PackageInfo.DIRS in info_needed: |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
801 |
dirs = list( |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
802 |
mfst.gen_key_attribute_value_by_type( |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
803 |
"dir", excludes)) |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
804 |
if PackageInfo.DEPENDENCIES in \ |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
805 |
info_needed: |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
806 |
dependencies = list( |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
807 |
mfst.gen_key_attribute_value_by_type( |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
808 |
"depend", excludes)) |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
809 |
|
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
810 |
if PackageInfo.CATEGORIES in info_needed: |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
811 |
cat_info = [ |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
812 |
PackageCategory(scheme, cat) |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
813 |
for ca |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
814 |
in mfst.gen_actions_by_type("set") |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
815 |
if ca.has_category_info() |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
816 |
for scheme, cat |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
817 |
in ca.parse_category_info() |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
818 |
] |
615
aeeeb9f31173
4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents:
610
diff
changeset
|
819 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
820 |
pis.append(PackageInfo(pkg_stem=name, summary=summary, |
688
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
821 |
category_info_list=cat_info, state=state, |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
822 |
publisher=pub, preferred_publisher=pref_pub, |
917
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
823 |
version=release, build_release=build_release, |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
824 |
branch=branch, packaging_date=packaging_date, |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
825 |
size=size, pfmri=str(f), licenses=licenses, |
615
aeeeb9f31173
4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents:
610
diff
changeset
|
826 |
links=links, hardlinks=hardlinks, files=files, |
aeeeb9f31173
4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents:
610
diff
changeset
|
827 |
dirs=dirs, dependencies=dependencies)) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
828 |
if pis: |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
829 |
self.log_operation_end() |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
830 |
elif illegals or multiple_matches: |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
831 |
self.log_operation_end( |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
832 |
result=history.RESULT_FAILED_BAD_REQUEST) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
833 |
else: |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
834 |
self.log_operation_end( |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
835 |
result=history.RESULT_NOTHING_TO_DO) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
836 |
return { |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
837 |
self.INFO_FOUND: pis, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
838 |
self.INFO_MISSING: notfound, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
839 |
self.INFO_MULTI_MATCH: multiple_matches, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
840 |
self.INFO_ILLEGALS: illegals |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
841 |
} |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
842 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
843 |
def can_be_canceled(self): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
844 |
"""Returns true if the API is in a cancelable state.""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
845 |
return self.__can_be_canceled |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
846 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
847 |
def __set_can_be_canceled(self, status): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
848 |
"""Private method. Handles the details of changing the |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
849 |
cancelable state.""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
850 |
if self.__can_be_canceled != status: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
851 |
self.__can_be_canceled = status |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
852 |
if self.cancel_state_callable: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
853 |
self.cancel_state_callable( |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
854 |
self.__can_be_canceled) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
855 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
856 |
def reset(self): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
857 |
"""Resets the API back the the initial state. Note: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
858 |
this does not necessarily return the disk to its initial state |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
859 |
since the indexes or download cache may have been changed by |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
860 |
the prepare method.""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
861 |
self.__activity_lock.acquire() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
862 |
self.__reset_unlock() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
863 |
self.__activity_lock.release() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
864 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
865 |
def __reset_unlock(self): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
866 |
"""Private method. Provides a way to reset without taking the |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
867 |
activity lock. Should only be called by a thread which already |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
868 |
holds the activity lock.""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
869 |
self.img.imageplan = None |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
870 |
self.plan_desc = None |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
871 |
self.plan_type = None |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
872 |
self.prepared = False |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
873 |
self.executed = False |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
874 |
self.__set_can_be_canceled(False) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
875 |
self.__canceling = False |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
876 |
self.progresstracker.reset() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
877 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
878 |
def __check_cancelation(self): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
879 |
"""Private method. Provides a callback method for internal |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
880 |
code to use to determine whether the current action has been |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
881 |
canceled.""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
882 |
return self.__canceling |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
883 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
884 |
def cancel(self): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
885 |
"""Used for asynchronous cancelation. It returns the API |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
886 |
to the state it was in prior to the current method being |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
887 |
invoked. Canceling during a plan phase returns the API to |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
888 |
its initial state. Canceling during prepare puts the API |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
889 |
into the state it was in just after planning had completed. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
890 |
Plan execution cannot be canceled. A call to this method blocks |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
891 |
until the canelation has happened. Note: this does not |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
892 |
necessarily return the disk to its initial state since the |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
893 |
indexes or download cache may have been changed by the |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
894 |
prepare method.""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
895 |
if not self.__can_be_canceled: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
896 |
return False |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
897 |
self.__set_can_be_canceled(False) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
898 |
self.__canceling = True |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
899 |
# The lock is taken here to make the call block, until |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
900 |
# the activity has been canceled. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
901 |
self.__activity_lock.acquire() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
902 |
self.__activity_lock.release() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
903 |
self.__canceling = False |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
904 |
return True |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
905 |
|
716
b836c1b14137
4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents:
707
diff
changeset
|
906 |
def __set_history_PlanCreationException(self, e): |
b836c1b14137
4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents:
707
diff
changeset
|
907 |
if e.unfound_fmris or e.multiple_matches or \ |
b836c1b14137
4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents:
707
diff
changeset
|
908 |
e.missing_matches or e.illegal: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
909 |
self.log_operation_end(error=e, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
910 |
result=history.RESULT_FAILED_BAD_REQUEST) |
716
b836c1b14137
4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents:
707
diff
changeset
|
911 |
elif e.constraint_violations: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
912 |
self.log_operation_end(error=e, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
913 |
result=history.RESULT_FAILED_CONSTRAINED) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
914 |
else: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
915 |
self.log_operation_end(error=e) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
916 |
|
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
917 |
def local_search(self, query_lst): |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
918 |
for i, q in enumerate(query_lst): |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
919 |
l = query_p.QueryLexer() |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
920 |
l.build() |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
921 |
qp = query_p.QueryParser(l) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
922 |
try: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
923 |
query = qp.parse(q.encoded_text()) |
1053
00fe9773d072
8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents:
1051
diff
changeset
|
924 |
except query_p.BooleanQueryException, e: |
00fe9773d072
8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents:
1051
diff
changeset
|
925 |
raise api_errors.BooleanQueryException(e) |
00fe9773d072
8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents:
1051
diff
changeset
|
926 |
except query_p.ParseError, e: |
00fe9773d072
8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents:
1051
diff
changeset
|
927 |
raise api_errors.ParseError(e) |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
928 |
self.img.update_index_dir() |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
929 |
assert self.img.index_dir |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
930 |
try: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
931 |
query.set_info(q.num_to_return, q.start_point, |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
932 |
self.img.index_dir, |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
933 |
self.img.get_manifest_path, |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
934 |
self.img.gen_installed_pkg_names, |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
935 |
q.case_sensitive) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
936 |
excludes = [variant.Variants( |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
937 |
{"variant.arch": self.img.get_arch()} |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
938 |
).allow_action] |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
939 |
res = query.search(self.img.gen_installed_pkgs, |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
940 |
self.img.get_manifest_path, excludes) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
941 |
except search_errors.InconsistentIndexException, e: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
942 |
raise api_errors.InconsistentIndexException(e) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
943 |
return ((i, None, r) for r in res) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
944 |
|
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
945 |
@staticmethod |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
946 |
def __parse_v_0(line, pub, v): |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
947 |
line = line.strip() |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
948 |
fields = line.split(None, 3) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
949 |
return (0, pub, (v, Query.RETURN_ACTIONS, (fields[:4]))) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
950 |
|
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
951 |
@staticmethod |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
952 |
def __parse_v_1(line, pub, v): |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
953 |
fields = line.split(None, 2) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
954 |
if len(fields) != 3: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
955 |
raise api_errors.ServerReturnError(line) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
956 |
try: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
957 |
return_type = int(fields[1]) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
958 |
except ValueError: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
959 |
raise api_errors.ServerReturnError(line) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
960 |
if return_type == Query.RETURN_ACTIONS: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
961 |
subfields = fields[2].split(None, 2) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
962 |
return (fields[0], pub, (v, return_type, |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
963 |
(subfields[0], urllib.unquote(subfields[1]), |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
964 |
subfields[2]))) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
965 |
elif return_type == Query.RETURN_PACKAGES: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
966 |
return (fields[0], pub, (v, return_type, fields[2])) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
967 |
else: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
968 |
raise api_errors.ServerReturnError(line) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
969 |
|
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
970 |
def remote_search(self, query_str_and_args_lst, servers=None): |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
971 |
failed = [] |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
972 |
invalid = [] |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
973 |
|
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
974 |
if not servers: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
975 |
servers = self.img.gen_publishers() |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
976 |
|
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
977 |
single = True |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
978 |
|
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
979 |
if not len(query_str_and_args_lst) == 1: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
980 |
single = False |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
981 |
|
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
982 |
allow_version_zero = single |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
983 |
|
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
984 |
version_list = [1] |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
985 |
|
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
986 |
if single: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
987 |
method = "GET" |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
988 |
q = query_str_and_args_lst[0] |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
989 |
qs = [urllib.quote(str(q), safe='')] |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
990 |
version_1_data = None |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
991 |
l = query_p.QueryLexer() |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
992 |
l.build() |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
993 |
qp = query_p.QueryParser(l) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
994 |
try: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
995 |
query = qp.parse(q.encoded_text()) |
1053
00fe9773d072
8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents:
1051
diff
changeset
|
996 |
except query_p.BooleanQueryException, e: |
00fe9773d072
8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents:
1051
diff
changeset
|
997 |
raise api_errors.BooleanQueryException(e) |
00fe9773d072
8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents:
1051
diff
changeset
|
998 |
except query_p.ParseError, e: |
00fe9773d072
8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents:
1051
diff
changeset
|
999 |
raise api_errors.ParseError(e) |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1000 |
if query.allow_version(0): |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1001 |
version_list.append(0) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1002 |
qs.append(urllib.quote(q.ver_0(), safe='')) |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1003 |
|
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1004 |
else: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1005 |
method = "POST" |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1006 |
qs = None |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1007 |
version_1_data = urllib.urlencode( |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1008 |
[(i, str(q)) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1009 |
for i, q in enumerate(query_str_and_args_lst)]) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1010 |
|
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1011 |
for pub in servers: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1012 |
prefix = None |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1013 |
uuid = None |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1014 |
if not isinstance(pub, publisher.Publisher): |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1015 |
origin = pub["origin"] |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1016 |
try: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1017 |
pub = self.img.get_publisher( |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1018 |
origin=origin) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1019 |
except api_errors.UnknownPublisher: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1020 |
pass |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1021 |
else: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1022 |
repo = pub.selected_repository |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1023 |
origin = repo.get_origin(origin) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1024 |
prefix = pub.prefix |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1025 |
uuid = pub.client_uuid |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1026 |
else: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1027 |
origin = pub.selected_repository.origins[0] |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1028 |
|
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1029 |
uuid = None |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1030 |
ssl_key = None |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1031 |
ssl_cert = None |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1032 |
if isinstance(origin, publisher.RepositoryURI): |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1033 |
ssl_key = origin.ssl_key |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1034 |
ssl_cert = origin.ssl_cert |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1035 |
origin = origin.uri |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1036 |
if ssl_cert: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1037 |
try: |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1038 |
misc.validate_ssl_cert(ssl_cert, |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1039 |
prefix=prefix, uri=origin) |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1040 |
except api_errors.CertificateError, e: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1041 |
failed.append((pub, e)) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1042 |
continue |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1043 |
ssl_tuple = (ssl_key, ssl_cert) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1044 |
try: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1045 |
res, v = versioned_urlopen(origin, |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1046 |
"search", version_list, tail=qs, |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1047 |
data=version_1_data, |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1048 |
ssl_creds=ssl_tuple, imgtype=self.img.type, |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1049 |
method=method, uuid=uuid) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1050 |
except urllib2.HTTPError, e: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1051 |
if e.code != httplib.NOT_FOUND and \ |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1052 |
e.code != httplib.NO_CONTENT: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1053 |
failed.append((pub, e)) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1054 |
continue |
1051
6b47b42fddcc
7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents:
1045
diff
changeset
|
1055 |
except (urllib2.URLError, httplib.BadStatusLine, |
6b47b42fddcc
7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents:
1045
diff
changeset
|
1056 |
httplib.IncompleteRead, RuntimeError, |
6b47b42fddcc
7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents:
1045
diff
changeset
|
1057 |
ValueError), e: |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1058 |
failed.append((pub, e)) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1059 |
continue |
1051
6b47b42fddcc
7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents:
1045
diff
changeset
|
1060 |
except KeyboardInterrupt: |
6b47b42fddcc
7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents:
1045
diff
changeset
|
1061 |
raise |
6b47b42fddcc
7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents:
1045
diff
changeset
|
1062 |
except Exception, e: |
6b47b42fddcc
7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents:
1045
diff
changeset
|
1063 |
failed.append((pub, "Could not perform search." |
6b47b42fddcc
7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents:
1045
diff
changeset
|
1064 |
"\nException: str:%s repr:%r" % (e, e))) |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1065 |
continue |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1066 |
|
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1067 |
try: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1068 |
if v == 0: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1069 |
for line in res: |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1070 |
yield self.__parse_v_0(line, |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1071 |
pub, v) |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1072 |
else: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1073 |
if not self.validate_response(res, v): |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1074 |
invalid.append(pub) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1075 |
continue |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1076 |
for line in res: |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1077 |
yield self.__parse_v_1(line, |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1078 |
pub, v) |
1051
6b47b42fddcc
7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents:
1045
diff
changeset
|
1079 |
except (socket.timeout, socket.error, ValueError, |
6b47b42fddcc
7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents:
1045
diff
changeset
|
1080 |
httplib.IncompleteRead, |
6b47b42fddcc
7367 search needs to catch more possible exceptions from transport
Brock Pytlik <bpytlik@sun.com>
parents:
1045
diff
changeset
|
1081 |
api_errors.ServerReturnError), e: |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1082 |
failed.append((pub, e)) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1083 |
continue |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1084 |
if failed or invalid: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1085 |
raise api_errors.ProblematicSearchServers(failed, |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1086 |
invalid) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1087 |
|
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1088 |
def rebuild_search_index(self): |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1089 |
"""Rebuilds the search indexes. Removes all |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1090 |
existing indexes and replaces them from scratch rather than |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1091 |
performing the incremental update which is usually used. |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1092 |
This is useful for times when the index for the client has |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1093 |
been corrupted.""" |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1094 |
self.img.update_index_dir() |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
1095 |
self.log_operation_start("rebuild-index") |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1096 |
if not os.path.isdir(self.img.index_dir): |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1097 |
self.img.mkdirs() |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1098 |
try: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1099 |
excludes = [variant.Variants( |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1100 |
{"variant.arch": self.img.get_arch()}).allow_action] |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1101 |
ind = indexer.Indexer(self.img, self.img.get_manifest, |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1102 |
self.img.get_manifest_path, |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1103 |
self.progresstracker, excludes) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1104 |
ind.rebuild_index_from_scratch( |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1105 |
self.img.gen_installed_pkgs()) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1106 |
except search_errors.ProblematicPermissionsIndexException, e: |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
1107 |
error = api_errors.ProblematicPermissionsIndexException(e) |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
1108 |
self.log_operation_end(error=error) |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
1109 |
raise error |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1110 |
except search_errors.MainDictParsingException, e: |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
1111 |
error = api_errors.MainDictParsingException(e) |
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
1112 |
self.log_operation_end(error=error) |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1113 |
self.img.cleanup_downloads() |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
1114 |
raise error |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1115 |
else: |
1027
e827313523d8
7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents:
1019
diff
changeset
|
1116 |
self.log_operation_end() |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1117 |
|
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1118 |
@staticmethod |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1119 |
def validate_response(res, v): |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1120 |
try: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1121 |
s = res.next() |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1122 |
return s == Query.VALIDATION_STRING[v] |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1123 |
except StopIteration: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1124 |
return False |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1125 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1126 |
def add_publisher(self, pub, refresh_allowed=True): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1127 |
"""Add the provided publisher object to the image |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1128 |
configuration.""" |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1129 |
self.img.add_publisher(pub, refresh_allowed=refresh_allowed, |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1130 |
progtrack=self.progresstracker) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1131 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1132 |
def get_preferred_publisher(self): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1133 |
"""Returns the preferred publisher object for the image.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1134 |
return self.get_publisher( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1135 |
prefix=self.img.get_preferred_publisher()) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1136 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1137 |
def get_publisher(self, prefix=None, alias=None, duplicate=False): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1138 |
"""Retrieves a publisher object matching the provided prefix |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1139 |
(name) or alias. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1140 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1141 |
'duplicate' is an optional boolean value indicating whether |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1142 |
a copy of the publisher object should be returned instead |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1143 |
of the original. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1144 |
""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1145 |
pub = self.img.get_publisher(prefix=prefix, alias=alias) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1146 |
if duplicate: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1147 |
# Never return the original so that changes to the |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1148 |
# retrieved object are not reflected until |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1149 |
# update_publisher is called. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1150 |
return copy.copy(pub) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1151 |
return pub |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1152 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1153 |
def get_publishers(self, duplicate=False): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1154 |
"""Returns a list of the publisher objects for the current |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1155 |
image. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1156 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1157 |
'duplicate' is an optional boolean value indicating whether |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1158 |
copies of the publisher objects should be returned instead |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1159 |
of the originals. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1160 |
""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1161 |
if duplicate: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1162 |
# Return a copy so that changes to the retrieved objects |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1163 |
# are not reflected until update_publisher is called. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1164 |
pubs = [ |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1165 |
copy.copy(p) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1166 |
for p in self.img.get_publishers().values() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1167 |
] |
716
b836c1b14137
4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents:
707
diff
changeset
|
1168 |
else: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1169 |
pubs = self.img.get_publishers().values() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1170 |
return misc.get_sorted_publishers(pubs, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1171 |
preferred=self.img.get_preferred_publisher()) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1172 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1173 |
def get_publisher_last_update_time(self, prefix=None, alias=None): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1174 |
"""Returns a datetime object representing the last time the |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1175 |
catalog for a publisher was modified or None.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1176 |
if alias: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1177 |
prefix = self.get_publisher(alias=alias).prefix |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1178 |
dt = None |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1179 |
self.__activity_lock.acquire() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1180 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1181 |
self.__set_can_be_canceled(True) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1182 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1183 |
dt = self.img.get_publisher_last_update_time( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1184 |
prefix) |
1032
ff3c6b09f430
8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents:
1027
diff
changeset
|
1185 |
except: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1186 |
self.__reset_unlock() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1187 |
raise |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1188 |
finally: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1189 |
self.__activity_lock.release() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1190 |
return dt |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1191 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1192 |
def has_publisher(self, prefix=None, alias=None): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1193 |
"""Retrieves a publisher object matching the provided prefix |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1194 |
(name) or alias.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1195 |
return self.img.has_publisher(prefix=prefix, alias=alias) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1196 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1197 |
def remove_publisher(self, prefix=None, alias=None): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1198 |
"""Removes a publisher object matching the provided prefix |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1199 |
(name) or alias.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1200 |
self.img.remove_publisher(prefix=prefix, alias=alias) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1201 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1202 |
def set_preferred_publisher(self, prefix=None, alias=None): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1203 |
"""Sets the preferred publisher for the image.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1204 |
self.img.set_preferred_publisher(prefix=prefix, alias=alias) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1205 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1206 |
def update_publisher(self, pub, refresh_allowed=True): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1207 |
"""Replaces an existing publisher object with the provided one |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1208 |
using the _source_object_id identifier set during copy. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1209 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1210 |
'refresh_allowed' is an optional boolean value indicating |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1211 |
whether a refresh of publisher metadata (such as its catalog) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1212 |
should be performed if transport information is changed for a |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1213 |
repository, mirror, or origin. If False, no attempt will be |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1214 |
made to retrieve publisher metadata.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1215 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1216 |
self.log_operation_start("update-publisher") |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1217 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1218 |
if pub.disabled and \ |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1219 |
pub.prefix == self.img.get_preferred_publisher(): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1220 |
raise api_errors.SetPreferredPublisherDisabled( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1221 |
pub.prefix) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1222 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1223 |
def need_refresh(oldo, newo): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1224 |
if oldo.disabled and not newo.disabled: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1225 |
# The publisher has been re-enabled, so |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1226 |
# retrieve the catalog. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1227 |
return True |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1228 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1229 |
if len(newo.repositories) != len(oldo.repositories): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1230 |
# If there are an unequal number of repositories |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1231 |
# then some have been added or removed. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1232 |
return True |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1233 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1234 |
matched = 0 |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1235 |
for oldr in oldo.repositories: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1236 |
for newr in newo.repositories: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1237 |
if newr._source_object_id == id(oldr): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1238 |
matched += 1 |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1239 |
if oldr.origins != newr.origins: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1240 |
return True |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1241 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1242 |
if matched != len(newo.repositories): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1243 |
# If not all of the repositories match up, then |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1244 |
# one has been removed or added, or an origin |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1245 |
# URI has changed. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1246 |
return True |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1247 |
return False |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1248 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1249 |
refresh_catalog = False |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1250 |
updated = False |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1251 |
publishers = self.img.get_publishers() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1252 |
for key, old in publishers.iteritems(): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1253 |
if pub._source_object_id == id(old): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1254 |
if need_refresh(old, pub): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1255 |
refresh_catalog = True |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1256 |
del publishers[key] |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1257 |
publishers[pub.prefix] = pub |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1258 |
updated = True |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1259 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1260 |
if not updated: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1261 |
# If a matching publisher couldn't be found and |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1262 |
# replaced, something is wrong (client api usage |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1263 |
# error). |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1264 |
e = api_errors.UnknownPublisher(pub) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1265 |
self.log_operation_end(e) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1266 |
raise e |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1267 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1268 |
if pub.disabled: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1269 |
# The catalog only needs to be purged in the event that |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1270 |
# a publisher is disabled; in any other case (the origin |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1271 |
# changing, etc.), self.refresh() will do the right |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1272 |
# thing. |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1273 |
try: |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1274 |
self.img.destroy_catalog(pub.prefix) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1275 |
self.img.destroy_catalog_cache() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1276 |
except EnvironmentError, e: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1277 |
if e.errno == errno.EACCES: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1278 |
raise api_errors.PermissionsException( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1279 |
e.filename) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1280 |
raise |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1281 |
self.img.cache_catalogs() |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1282 |
elif not refresh_catalog: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1283 |
refresh_catalog = pub.needs_refresh |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1284 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1285 |
if refresh_catalog: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1286 |
if refresh_allowed: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1287 |
self.refresh(pubs=[pub], immediate=True) |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1288 |
else: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1289 |
# Something has changed (such as a repository |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1290 |
# origin) for the publisher, so a refresh should |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1291 |
# occur, but isn't currently allowed. As such, |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1292 |
# clear the last_refreshed time so that the next |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1293 |
# time the client checks to see if a refresh is |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1294 |
# needed, and is allowed, one will be performed. |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1295 |
pub.last_refreshed = None |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1296 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
941
diff
changeset
|
1297 |
# Successful; so save configuration. |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1298 |
self.img.save_config() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1299 |
self.log_operation_end() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1300 |
return |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1301 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1302 |
def log_operation_end(self, error=None, result=None): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1303 |
"""Marks the end of an operation to be recorded in image |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1304 |
history. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1305 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1306 |
'result' should be a pkg.client.history constant value |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1307 |
representing the outcome of an operation. If not provided, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1308 |
and 'error' is provided, the final result of the operation will |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1309 |
be based on the class of 'error' and 'error' will be recorded |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1310 |
for the current operation. If 'result' and 'error' is not |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1311 |
provided, success is assumed.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1312 |
self.img.history.log_operation_end(error=error, result=result) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1313 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1314 |
def log_operation_error(self, error): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1315 |
"""Adds an error to the list of errors to be recorded in image |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1316 |
history for the current opreation.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1317 |
self.img.history.log_operation_error(error) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1318 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1319 |
def log_operation_start(self, name): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1320 |
"""Marks the start of an operation to be recorded in image |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1321 |
history.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1322 |
self.img.history.log_operation_start(name) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1323 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1324 |
def parse_p5i(self, fileobj=None, location=None): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1325 |
"""Reads the pkg(5) publisher json formatted data at 'location' |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1326 |
or from the provided file-like object 'fileobj' and returns a |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1327 |
list of tuples of the format (publisher object, pkg_names). |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1328 |
pkg_names is a list of strings representing package names or |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1329 |
FMRIs. If any pkg_names not specific to a publisher were |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1330 |
provided, the last tuple returned will be of the format (None, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1331 |
pkg_names). |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1332 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1333 |
'fileobj' is an optional file-like object that must support a |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1334 |
'read' method for retrieving data. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1335 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1336 |
'location' is an optional string value that should either start |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1337 |
with a leading slash and be pathname of a file or a URI string. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1338 |
If it is a URI string, supported protocol schemes are 'file', |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1339 |
'ftp', 'http', and 'https'. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1340 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1341 |
'fileobj' or 'location' must be provided.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1342 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1343 |
if location is None and fileobj is None: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1344 |
raise api_errors.InvalidResourceLocation(location) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1345 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1346 |
if location: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1347 |
if location.startswith(os.path.sep): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1348 |
location = os.path.abspath(location) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1349 |
location = "file://" + location |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1350 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1351 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1352 |
fileobj = urllib2.urlopen(location) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1353 |
except (EnvironmentError, ValueError, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1354 |
urllib2.HTTPError), e: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1355 |
raise api_errors.RetrievalError(e, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1356 |
location=location) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1357 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1358 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1359 |
dump_struct = json.load(fileobj) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1360 |
except (EnvironmentError, urllib2.HTTPError), e: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1361 |
raise api_errors.RetrievalError(e) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1362 |
except ValueError, e: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1363 |
# Not a valid json file. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1364 |
raise api_errors.InvalidP5IFile(e) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1365 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1366 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1367 |
ver = int(dump_struct["version"]) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1368 |
except KeyError: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1369 |
raise api_errors.InvalidP5IFile(_("missing version")) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1370 |
except ValueError: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1371 |
raise api_errors.InvalidP5IFile(_("invalid version")) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1372 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1373 |
if ver > CURRENT_P5I_VERSION: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1374 |
raise api_errors.UnsupportedP5IFile() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1375 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1376 |
result = [] |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1377 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1378 |
plist = dump_struct.get("publishers", []) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1379 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1380 |
for p in plist: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1381 |
alias = p.get("alias", None) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1382 |
prefix = p.get("name", None) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1383 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1384 |
if not prefix: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1385 |
prefix = "Unknown" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1386 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1387 |
pub = publisher.Publisher(prefix, alias=alias) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1388 |
pkglist = p.get("packages", []) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1389 |
result.append((pub, pkglist)) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1390 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1391 |
for r in p.get("repositories", []): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1392 |
rargs = {} |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1393 |
for prop in ("collection_type", |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1394 |
"description", "name", |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1395 |
"refresh_seconds", |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1396 |
"registration_uri"): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1397 |
val = r.get(prop, None) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1398 |
if val is None or val == "None": |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1399 |
continue |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1400 |
rargs[prop] = val |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1401 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1402 |
for prop in ("legal_uris", "mirrors", |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1403 |
"origins", "related_uris"): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1404 |
val = r.get(prop, []) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1405 |
if not isinstance(val, list): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1406 |
continue |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1407 |
rargs[prop] = val |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1408 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1409 |
if rargs.get("origins", None): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1410 |
repo = publisher.Repository( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1411 |
**rargs) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1412 |
pub.add_repository(repo) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1413 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1414 |
pkglist = dump_struct.get("packages", []) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1415 |
if pkglist: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1416 |
result.append((None, pkglist)) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1417 |
except (api_errors.PublisherError, TypeError, ValueError), e: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1418 |
raise api_errors.InvalidP5IFile(str(e)) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1419 |
return result |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1420 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1421 |
def write_p5i(self, fileobj, pkg_names=None, pubs=None): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1422 |
"""Writes the publisher, repository, and provided package names |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1423 |
to the provided file-like object 'fileobj' in json p5i format. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1424 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1425 |
'fileobj' is only required to have a 'write' method that accepts |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1426 |
data to be written as a parameter. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1427 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1428 |
'pkg_names' is a dict of lists, tuples, or sets indexed by |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1429 |
publisher prefix that contain package names, FMRI strings, or |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1430 |
package info objects. A prefix of "" can be used for packages |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1431 |
that are not specific to a publisher. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1432 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1433 |
'pubs' is an optional list of publisher prefixes or Publisher |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1434 |
objects. If not provided, the information for all publishers |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1435 |
(excluding those disabled) will be output.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1436 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1437 |
dump_struct = { |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1438 |
"packages": [], |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1439 |
"publishers": [], |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1440 |
"version": CURRENT_P5I_VERSION, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1441 |
} |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1442 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1443 |
if not pubs: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1444 |
plist = [ |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1445 |
p for p in self.get_publishers() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1446 |
if not p.disabled |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1447 |
] |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1448 |
else: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1449 |
plist = [] |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1450 |
for p in pubs: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1451 |
if not isinstance(p, publisher.Publisher): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1452 |
plist.append(self.img.get_publisher( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1453 |
prefix=p, alias=p)) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1454 |
else: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1455 |
plist.append(p) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1456 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1457 |
if pkg_names is None: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1458 |
pkg_names = {} |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1459 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1460 |
def copy_pkg_names(source, dest): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1461 |
for entry in source: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1462 |
# Publisher information is intentionally |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1463 |
# omitted as association with this specific |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1464 |
# publisher is implied by location in the |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1465 |
# output. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1466 |
if isinstance(entry, PackageInfo): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1467 |
dest.append(entry.fmri.get_fmri( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1468 |
anarchy=True)) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1469 |
elif isinstance(entry, fmri.PkgFmri): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1470 |
dest.append(entry.get_fmri( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1471 |
anarchy=True)) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1472 |
else: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1473 |
dest.append(str(entry)) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1474 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1475 |
dpubs = dump_struct["publishers"] |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1476 |
for p in plist: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1477 |
dpub = { |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1478 |
"alias": p.alias, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1479 |
"name": p.prefix, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1480 |
"packages": [], |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1481 |
"repositories": [] |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1482 |
} |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1483 |
dpubs.append(dpub) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1484 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1485 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1486 |
copy_pkg_names(pkg_names[p.prefix], |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1487 |
dpub["packages"]) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1488 |
except KeyError: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1489 |
pass |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1490 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1491 |
drepos = dpub["repositories"] |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1492 |
for r in p.repositories: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1493 |
reg_uri = "" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1494 |
if r.registration_uri: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1495 |
reg_uri = r.registration_uri.uri |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1496 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1497 |
drepos.append({ |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1498 |
"collection_type": r.collection_type, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1499 |
"description": r.description, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1500 |
"legal_uris": [u.uri for u in r.legal_uris], |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1501 |
"mirrors": [u.uri for u in r.mirrors], |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1502 |
"name": r.name, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1503 |
"origins": [u.uri for u in r.origins], |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1504 |
"refresh_seconds": r.refresh_seconds, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1505 |
"registration_uri": reg_uri, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1506 |
"related_uris": [ |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1507 |
u.uri for u in r.related_uris |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1508 |
], |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1509 |
}) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1510 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1511 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1512 |
copy_pkg_names(pkg_names[""], dump_struct["packages"]) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1513 |
except KeyError: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1514 |
pass |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1515 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1516 |
return json.dump(dump_struct, fileobj, ensure_ascii=False, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1517 |
allow_nan=False, indent=2, sort_keys=True) |
716
b836c1b14137
4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents:
707
diff
changeset
|
1518 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1519 |
|
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1520 |
class Query(query_p.Query): |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1521 |
def __init__(self, text, case_sensitive, return_actions=True, |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1522 |
num_to_return=None, start_point=None): |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1523 |
if return_actions: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1524 |
return_type = query_p.Query.RETURN_ACTIONS |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1525 |
else: |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1526 |
return_type = query_p.Query.RETURN_PACKAGES |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1527 |
query_p.Query.__init__(self, text, case_sensitive, return_type, |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1528 |
num_to_return, start_point) |
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1529 |
|
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
938
diff
changeset
|
1530 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1531 |
class PlanDescription(object): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1532 |
"""A class which describes the changes the plan will make. It |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1533 |
provides a list of tuples of PackageInfo's. The first item in the |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1534 |
tuple is the package that is being changed. The second item in the |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1535 |
tuple is the package that will be in the image after the change.""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1536 |
def __init__(self, imageplan): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1537 |
self.__pkgs = \ |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1538 |
[ (PackageInfo.build_from_fmri(pp.origin_fmri), |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1539 |
PackageInfo.build_from_fmri(pp.destination_fmri)) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1540 |
for pp |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1541 |
in imageplan.pkg_plans ] |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1542 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1543 |
def get_changes(self): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1544 |
return self.__pkgs |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1545 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1546 |
class LicenseInfo(object): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1547 |
"""A class representing the license information a package |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1548 |
provides.""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1549 |
def __init__(self, text): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1550 |
self.__text = text |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1551 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1552 |
def get_text(self): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1553 |
return self.__text |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1554 |
|
610
09641d85df90
4132 Info --license no longer displays a license
Brock Pytlik <bpytlik@sun.com>
parents:
598
diff
changeset
|
1555 |
def __str__(self): |
09641d85df90
4132 Info --license no longer displays a license
Brock Pytlik <bpytlik@sun.com>
parents:
598
diff
changeset
|
1556 |
return self.__text |
09641d85df90
4132 Info --license no longer displays a license
Brock Pytlik <bpytlik@sun.com>
parents:
598
diff
changeset
|
1557 |
|
688
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1558 |
class PackageCategory(object): |
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1559 |
def __init__(self, scheme, category): |
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1560 |
self.scheme = scheme |
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1561 |
self.category = category |
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1562 |
|
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1563 |
def __str__(self, verbose=False): |
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1564 |
if verbose: |
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1565 |
return "%s (%s)" % (self.category, self.scheme) |
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1566 |
else: |
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1567 |
return "%s" % self.category |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1568 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1569 |
class PackageInfo(object): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1570 |
"""A class capturing the information about packages that a client |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1571 |
could need. The fmri is guaranteed to be set. All other values may |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1572 |
be None, depending on how the PackageInfo instance was created.""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1573 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1574 |
# Possible package installation states |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1575 |
INSTALLED = 1 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1576 |
NOT_INSTALLED = 2 |
917
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
1577 |
|
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
1578 |
__NUM_PROPS = 12 |
938
eeb932b9b44e
7336 putback for 5871 missed a few vestiges of authority
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
926
diff
changeset
|
1579 |
IDENTITY, SUMMARY, CATEGORIES, STATE, PREF_PUBLISHER, SIZE, LICENSES, \ |
917
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
1580 |
LINKS, HARDLINKS, FILES, DIRS, DEPENDENCIES = range(__NUM_PROPS) |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
1581 |
ALL_OPTIONS = frozenset(range(__NUM_PROPS)) |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
1582 |
ACTION_OPTIONS = frozenset([LINKS, HARDLINKS, FILES, DIRS, |
eed22f430a9f
6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents:
884
diff
changeset
|
1583 |
DEPENDENCIES]) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1584 |
|
688
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1585 |
def __init__(self, pfmri, pkg_stem=None, summary=None, |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1586 |
category_info_list=None, state=None, publisher=None, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1587 |
preferred_publisher=None, version=None, build_release=None, |
688
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1588 |
branch=None, packaging_date=None, size=None, licenses=None, |
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1589 |
links=None, hardlinks=None, files=None, dirs=None, |
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1590 |
dependencies=None): |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1591 |
self.pkg_stem = pkg_stem |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1592 |
self.summary = summary |
688
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1593 |
if category_info_list is None: |
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1594 |
category_info_list = [] |
32a3ca40676e
4260 pkg info should print the classification
Brock Pytlik <bpytlik@sun.com>
parents:
685
diff
changeset
|
1595 |
self.category_info_list = category_info_list |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1596 |
self.state = state |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1597 |
self.publisher = publisher |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1598 |
self.preferred_publisher = preferred_publisher |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1599 |
self.version = version |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1600 |
self.build_release = build_release |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1601 |
self.branch = branch |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1602 |
self.packaging_date = packaging_date |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1603 |
self.size = size |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1604 |
self.fmri = pfmri |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1605 |
self.licenses = licenses |
615
aeeeb9f31173
4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents:
610
diff
changeset
|
1606 |
self.links = links |
aeeeb9f31173
4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents:
610
diff
changeset
|
1607 |
self.hardlinks = hardlinks |
aeeeb9f31173
4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents:
610
diff
changeset
|
1608 |
self.files = files |
aeeeb9f31173
4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents:
610
diff
changeset
|
1609 |
self.dirs = dirs |
aeeeb9f31173
4114 Api.Info needs to provide more info
Brock Pytlik <bpytlik@sun.com>
parents:
610
diff
changeset
|
1610 |
self.dependencies = dependencies |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1611 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1612 |
def __str__(self): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1613 |
return self.fmri |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1614 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1615 |
@staticmethod |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1616 |
def build_from_fmri(f): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1617 |
if not f: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1618 |
return f |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1619 |
pub, name, version = f.tuple() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1620 |
pub = fmri.strip_pub_pfx(pub) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1621 |
return PackageInfo(pkg_stem=name, publisher=pub, |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1622 |
version=version.release, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff
changeset
|
1623 |
build_release=version.build_release, branch=version.branch, |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1624 |
packaging_date=version.get_timestamp().ctime(), |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
917
diff
changeset
|
1625 |
pfmri=str(f)) |