author | Rich Burridge <rich.burridge@sun.com> |
Thu, 11 Jun 2009 09:41:21 -0700 | |
changeset 1141 | a74d6815a7fc |
parent 1133 | 2c28e4526a6e |
child 1143 | 71becfca5cfd |
permissions | -rw-r--r-- |
409
713e20963dc2
2314 shebang lines should use minimum python version
Shawn Walker <swalker@opensolaris.org>
parents:
405
diff
changeset
|
1 |
#!/usr/bin/python2.4 |
19 | 2 |
# |
3 |
# CDDL HEADER START |
|
4 |
# |
|
5 |
# The contents of this file are subject to the terms of the |
|
6 |
# Common Development and Distribution License (the "License"). |
|
7 |
# You may not use this file except in compliance with the License. |
|
8 |
# |
|
9 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
10 |
# or http://www.opensolaris.org/os/licensing. |
|
11 |
# See the License for the specific language governing permissions |
|
12 |
# and limitations under the License. |
|
13 |
# |
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each |
|
15 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
16 |
# If applicable, add the following below this CDDL HEADER, with the |
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying |
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
|
19 |
# |
|
20 |
# CDDL HEADER END |
|
21 |
# |
|
22 |
||
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
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:
834
diff
changeset
|
24 |
# Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
19 | 25 |
# Use is subject to license terms. |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
26 |
# |
19 | 27 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
28 |
import datetime as dt |
161
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
29 |
import errno |
26 | 30 |
import os |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
31 |
import platform |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
32 |
import shutil |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
33 |
import tempfile |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
34 |
import time |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
35 |
import urllib |
479
de75c17238ff
2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
36 |
|
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
37 |
import pkg.Uuid25 |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
38 |
import pkg.catalog as catalog |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
39 |
import pkg.client.api_errors as api_errors |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
40 |
import pkg.client.constraint as constraint |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
41 |
import pkg.client.history as history |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
42 |
import pkg.client.imageconfig as imageconfig |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
43 |
import pkg.client.imageplan as imageplan |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
44 |
import pkg.client.imagestate as imagestate |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
45 |
import pkg.client.pkgplan as pkgplan |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
46 |
import pkg.client.progress as progress |
941
e7bff46da54e
6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents:
931
diff
changeset
|
47 |
import pkg.client.publisher as publisher |
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
48 |
import pkg.client.retrieve as retrieve |
877
b23f809e8abd
6653 we should elide alternate architectures from in-memory manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
855
diff
changeset
|
49 |
import pkg.client.variant as variant |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
50 |
import pkg.fmri |
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
51 |
import pkg.manifest as manifest |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
52 |
import pkg.misc as misc |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
53 |
import pkg.portable as portable |
539
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
54 |
import pkg.version |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
55 |
|
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
56 |
from pkg.actions import MalformedActionError |
576
6ee6de304041
3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents:
573
diff
changeset
|
57 |
from pkg.client import global_settings |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
58 |
from pkg.client.api_errors import InvalidDepotResponseException |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
59 |
from pkg.client.imagetypes import IMG_USER, IMG_ENTIRE |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
60 |
from pkg.misc import CfgCacheError |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
61 |
from pkg.misc import EmptyI, EmptyDict |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
62 |
from pkg.misc import msg, emsg |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
63 |
from pkg.misc import TransportException |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
64 |
from pkg.misc import TransportFailures |
19 | 65 |
|
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
66 |
CATALOG_CACHE_FILE = "catalog_cache" |
26 | 67 |
img_user_prefix = ".org.opensolaris,pkg" |
30 | 68 |
img_root_prefix = "var/pkg" |
26 | 69 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
70 |
PKG_STATE_INSTALLED = "installed" |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
71 |
PKG_STATE_KNOWN = "known" |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
72 |
|
19 | 73 |
class Image(object): |
74 |
"""An Image object is a directory tree containing the laid-down contents |
|
75 |
of a self-consistent graph of Packages. |
|
76 |
||
77 |
An Image has a root path. |
|
78 |
||
79 |
An Image of type IMG_ENTIRE does not have a parent Image. Other Image |
|
80 |
types must have a parent Image. The external state of the parent Image |
|
81 |
must be accessible from the Image's context, or duplicated within the |
|
82 |
Image (IMG_PARTIAL for zones, for instance). |
|
83 |
||
84 |
The parent of a user Image can be a partial Image. The parent of a |
|
85 |
partial Image must be an entire Image. |
|
86 |
||
87 |
An Image of type IMG_USER stores its external state at self.root + |
|
26 | 88 |
".org.opensolaris,pkg". |
19 | 89 |
|
90 |
An Image of type IMG_ENTIRE or IMG_PARTIAL stores its external state at |
|
91 |
self.root + "/var/pkg". |
|
92 |
||
26 | 93 |
An Image needs to be able to have a different repository set than the |
94 |
system's root Image. |
|
95 |
||
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
96 |
Directory layout |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
97 |
|
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
98 |
$IROOT/catalog |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
99 |
Directory containing catalogs for URIs of interest. Filename is |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
100 |
the escaped URI of the catalog. |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
101 |
|
30 | 102 |
$IROOT/file |
103 |
Directory containing file hashes of installed packages. |
|
104 |
||
105 |
$IROOT/pkg |
|
106 |
Directory containing manifests and states of installed packages. |
|
107 |
||
60
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
108 |
$IROOT/index |
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
109 |
Directory containing reverse-index databases. |
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
110 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
111 |
$IROOT/cfg_cache |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
112 |
File containing image's cached configuration. |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
113 |
|
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
114 |
$IROOT/opaque |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
115 |
File containing image's opaque state. |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
116 |
|
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
117 |
$IROOT/state/installed |
434
48c05c66cdd2
2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents:
432
diff
changeset
|
118 |
Directory containing files whose names identify the installed |
48c05c66cdd2
2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents:
432
diff
changeset
|
119 |
packages. |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
120 |
|
397
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
121 |
All of these directories and files other than state are considered |
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
122 |
essential for any image to be complete. To add a new essential file or |
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
123 |
subdirectory, the following steps should be done. |
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
124 |
|
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
125 |
If it's a directory, add it to the image_subdirs list below and it will |
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
126 |
be created automatically. The programmer must fill the directory as |
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
127 |
needed. If a file is added, the programmer is responsible for creating |
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
128 |
that file during image creation at an appropriate place and time. |
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
129 |
|
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
130 |
If a directory is required to be present in order for an image to be |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
131 |
identifiable as such, it should go into required_subdirs instead. |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
132 |
However, upgrade issues abound; this list should probably not change. |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
133 |
|
397
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
134 |
Once those steps have been carried out, the change should be added |
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
135 |
to the test suite for image corruption (t_pkg_install_corrupt_image.py). |
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
136 |
This will likely also involve a change to |
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
137 |
SingleDepotTestCaseCorruptImage in testutils.py. Each of these files |
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
138 |
outline what must be updated. |
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
139 |
|
19 | 140 |
XXX Root path probably can't be absolute, so that we can combine or |
30 | 141 |
reuse Image contents. |
26 | 142 |
|
143 |
XXX Image file format? Image file manipulation API?""" |
|
144 |
||
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
145 |
required_subdirs = [ "catalog", "file", "pkg" ] |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
146 |
image_subdirs = required_subdirs + [ "index", "state/installed" ] |
397
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
147 |
|
26 | 148 |
def __init__(self): |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
149 |
self.cfg_cache = None |
26 | 150 |
self.type = None |
151 |
self.root = None |
|
539
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
152 |
self.history = history.History() |
30 | 153 |
self.imgdir = None |
1037
56ff5f4fab83
8050 image-update fails from b110 to b111 at SUNWgnome-system-monitor manifest
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
999
diff
changeset
|
154 |
self.pkgdir = None |
271
ec8a7669bff2
659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
268
diff
changeset
|
155 |
self.img_prefix = None |
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
156 |
self.index_dir = None |
26 | 157 |
self.repo_uris = [] |
158 |
self.filter_tags = {} |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
159 |
self.__catalogs = {} |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
160 |
self._catalog = {} |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
161 |
self.__pkg_states = None |
554
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
162 |
self.dl_cache_dir = None |
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
163 |
self.dl_cache_incoming = None |
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
164 |
self.is_user_cache_dir = False |
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
165 |
self.state = imagestate.ImageState() |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
166 |
self.attrs = { |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
167 |
"Policy-Require-Optional": False, |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
168 |
"Policy-Pursue-Latest": True |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
169 |
} |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
170 |
self.__catalog_cache_mod_time = None |
32
c26788b7217c
begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents:
30
diff
changeset
|
171 |
|
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
172 |
self.imageplan = None # valid after evaluation succeeds |
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
173 |
|
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
174 |
self.constraints = constraint.ConstraintSet() |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
175 |
|
462
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
176 |
# a place to keep info about saved_files; needed by file action |
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
177 |
self.saved_files = {} |
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
178 |
|
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
179 |
# A place to keep track of which manifests (based on fmri and |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
180 |
# operation) have already provided intent information. |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
181 |
self.__touched_manifests = {} |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
182 |
|
567
ea1d96e269a4
3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents:
565
diff
changeset
|
183 |
self.__manifest_cache = {} |
ea1d96e269a4
3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents:
565
diff
changeset
|
184 |
|
674
e740c8c3bed1
166 os.makedirs() does not set directory mode
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
664
diff
changeset
|
185 |
# right now we don't explicitly set dir/file modes everywhere; |
e740c8c3bed1
166 os.makedirs() does not set directory mode
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
664
diff
changeset
|
186 |
# set umask to proper value to prevent problems w/ overly |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
187 |
# locked down umask. |
674
e740c8c3bed1
166 os.makedirs() does not set directory mode
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
664
diff
changeset
|
188 |
os.umask(0022) |
e740c8c3bed1
166 os.makedirs() does not set directory mode
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
664
diff
changeset
|
189 |
|
582
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
190 |
def _check_subdirs(self, sub_d, prefix): |
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
191 |
for n in self.required_subdirs: |
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
192 |
if not os.path.isdir(os.path.join(sub_d, prefix, n)): |
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
193 |
return False |
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
194 |
return True |
397
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
195 |
|
582
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
196 |
def image_type(self, d): |
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
197 |
"""Returns the type of image at directory: d; or None""" |
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
198 |
rv = None |
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
199 |
if os.path.isdir(os.path.join(d, img_user_prefix)) and \ |
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
200 |
os.path.isfile(os.path.join(d, img_user_prefix, |
786
a400f8c4d1c0
2340 support authority enable and disable
Tom Mueller <Tom.Mueller@sun.com>
parents:
756
diff
changeset
|
201 |
imageconfig.CFG_FILE)) and \ |
582
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
202 |
self._check_subdirs(d, img_user_prefix): |
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
203 |
rv = IMG_USER |
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
204 |
elif os.path.isdir(os.path.join(d, img_root_prefix)) \ |
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
205 |
and os.path.isfile(os.path.join(d, |
786
a400f8c4d1c0
2340 support authority enable and disable
Tom Mueller <Tom.Mueller@sun.com>
parents:
756
diff
changeset
|
206 |
img_root_prefix, imageconfig.CFG_FILE)) and \ |
582
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
207 |
self._check_subdirs(d, img_root_prefix): |
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
208 |
rv = IMG_ENTIRE |
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
209 |
return rv |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
210 |
|
582
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
211 |
def find_root(self, d, exact_match=False): |
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
212 |
# Ascend from the given directory d to find first |
561
be1ad23e7704
1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents:
560
diff
changeset
|
213 |
# encountered image. If exact_match is true, if the |
be1ad23e7704
1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents:
560
diff
changeset
|
214 |
# image found doesn't match startd, raise an |
be1ad23e7704
1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents:
560
diff
changeset
|
215 |
# ImageNotFoundException. |
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
216 |
startd = d |
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
217 |
# eliminate problem if relative path such as "." is passed in |
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
218 |
d = os.path.realpath(d) |
26 | 219 |
while True: |
582
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
220 |
imgtype = self.image_type(d) |
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
221 |
if imgtype == IMG_USER: |
26 | 222 |
# XXX Look at image file to determine filter |
223 |
# tags and repo URIs. |
|
561
be1ad23e7704
1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents:
560
diff
changeset
|
224 |
if exact_match and \ |
be1ad23e7704
1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents:
560
diff
changeset
|
225 |
os.path.realpath(startd) != \ |
be1ad23e7704
1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents:
560
diff
changeset
|
226 |
os.path.realpath(d): |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
227 |
raise api_errors.ImageNotFoundException( |
561
be1ad23e7704
1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents:
560
diff
changeset
|
228 |
exact_match, startd, d) |
582
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
229 |
self.__set_dirs(imgtype=imgtype, root=d) |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
230 |
self.attrs["Build-Release"] = "5.11" |
26 | 231 |
return |
582
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
232 |
elif imgtype == IMG_ENTIRE: |
26 | 233 |
# XXX Look at image file to determine filter |
234 |
# tags and repo URIs. |
|
235 |
# XXX Look at image file to determine if this |
|
236 |
# image is a partial image. |
|
561
be1ad23e7704
1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents:
560
diff
changeset
|
237 |
if exact_match and \ |
be1ad23e7704
1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents:
560
diff
changeset
|
238 |
os.path.realpath(startd) != \ |
be1ad23e7704
1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents:
560
diff
changeset
|
239 |
os.path.realpath(d): |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
240 |
raise api_errors.ImageNotFoundException( |
561
be1ad23e7704
1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents:
560
diff
changeset
|
241 |
exact_match, startd, d) |
582
303fa3b78f93
3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents:
577
diff
changeset
|
242 |
self.__set_dirs(imgtype=imgtype, root=d) |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
243 |
self.attrs["Build-Release"] = "5.11" |
26 | 244 |
return |
245 |
||
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
246 |
# XXX follow symlinks or not? |
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
247 |
oldpath = d |
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
248 |
d = os.path.normpath(os.path.join(d, os.path.pardir)) |
26 | 249 |
|
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
250 |
# Make sure we are making progress and aren't in an |
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
251 |
# infinite loop. |
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
252 |
# |
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
253 |
# (XXX - Need to deal with symlinks here too) |
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
254 |
if d == oldpath: |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
255 |
raise api_errors.ImageNotFoundException( |
596
f4519e2a99bc
3704 InventoryException raised if optional dependencies not in catalog
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
583
diff
changeset
|
256 |
exact_match, startd, d) |
26 | 257 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
258 |
def load_config(self): |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
259 |
"""Load this image's cached configuration from the default |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
260 |
location.""" |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
261 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
262 |
# XXX Incomplete with respect to doc/image.txt description of |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
263 |
# configuration. |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
264 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
265 |
if self.root == None: |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
266 |
raise RuntimeError, "self.root must be set" |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
267 |
|
1111
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
268 |
ic = imageconfig.ImageConfig(self.root) |
786
a400f8c4d1c0
2340 support authority enable and disable
Tom Mueller <Tom.Mueller@sun.com>
parents:
756
diff
changeset
|
269 |
ic.read(self.imgdir) |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
270 |
|
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
271 |
# make sure we define architecture variant; upgrade config |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
272 |
# file if possible. |
1111
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
273 |
changed = False |
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
274 |
if "variant.arch" not in ic.variants: |
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
275 |
ic.variants["variant.arch"] = platform.processor() |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
276 |
try: |
1111
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
277 |
ic.write(self.imgdir) |
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
278 |
changed = True |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
279 |
except api_errors.PermissionsException: |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
280 |
pass |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
281 |
# make sure we define zone variant; upgrade config if possible |
1111
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
282 |
if "variant.opensolaris.zone" not in ic.variants: |
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
283 |
zone = ic.filters.get("opensolaris.zone", "") |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
284 |
if zone == "nonglobal": |
1111
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
285 |
ic.variants[ |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
286 |
"variant.opensolaris.zone"] = "nonglobal" |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
287 |
else: |
1111
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
288 |
ic.variants[ |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
289 |
"variant.opensolaris.zone"] = "global" |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
290 |
try: |
1111
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
291 |
ic.write(self.imgdir) |
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
292 |
changed = True |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
293 |
except api_errors.PermissionsException: |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
294 |
pass |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
295 |
|
1111
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
296 |
# |
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
297 |
# If we made changes to the configuration, reload it; |
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
298 |
# this lets any processing which is a side-effect of |
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
299 |
# these changes take place. |
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
300 |
# |
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
301 |
if changed: |
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
302 |
ic = imageconfig.ImageConfig(self.root) |
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
303 |
ic.read(self.imgdir) |
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
304 |
|
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
305 |
self.cfg_cache = ic |
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
306 |
|
551 | 307 |
def save_config(self): |
786
a400f8c4d1c0
2340 support authority enable and disable
Tom Mueller <Tom.Mueller@sun.com>
parents:
756
diff
changeset
|
308 |
self.cfg_cache.write(self.imgdir) |
551 | 309 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
310 |
# XXX mkdirs and set_attrs() need to be combined into a create |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
311 |
# operation. |
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
312 |
def mkdirs(self): |
397
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
313 |
for sd in self.image_subdirs: |
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
314 |
if not os.path.isdir(os.path.join(self.imgdir, sd)): |
617be57c5f2b
777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents:
394
diff
changeset
|
315 |
os.makedirs(os.path.join(self.imgdir, sd)) |
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
316 |
|
554
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
317 |
def __set_dirs(self, imgtype, root): |
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
318 |
self.type = imgtype |
22
379f0f6809ff
pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents:
19
diff
changeset
|
319 |
self.root = root |
379f0f6809ff
pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents:
19
diff
changeset
|
320 |
if self.type == IMG_USER: |
271
ec8a7669bff2
659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
268
diff
changeset
|
321 |
self.img_prefix = img_user_prefix |
22
379f0f6809ff
pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents:
19
diff
changeset
|
322 |
else: |
271
ec8a7669bff2
659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
268
diff
changeset
|
323 |
self.img_prefix = img_root_prefix |
993
7cfbab7739c3
588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents:
988
diff
changeset
|
324 |
|
7cfbab7739c3
588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents:
988
diff
changeset
|
325 |
# Change directory to the root of the image so that we can |
7cfbab7739c3
588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents:
988
diff
changeset
|
326 |
# remove any directories beneath us. If we're changing the |
7cfbab7739c3
588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents:
988
diff
changeset
|
327 |
# image, don't chdir, as we're likely changing to a new BE |
7cfbab7739c3
588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents:
988
diff
changeset
|
328 |
# and want to be able to unmount it later. |
999
04c29b9c97a0
7811 pkg image-create no longer creates image path if it doesn't exist
Danek Duvall <danek.duvall@sun.com>
parents:
996
diff
changeset
|
329 |
if not self.imgdir and os.path.isdir(root): |
993
7cfbab7739c3
588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents:
988
diff
changeset
|
330 |
os.chdir(root) |
7cfbab7739c3
588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents:
988
diff
changeset
|
331 |
|
1133
2c28e4526a6e
8720 image-create with a non-absolute path can cause strange results
Shawn Walker <srw@sun.com>
parents:
1125
diff
changeset
|
332 |
# The specified root may have been a relative path. |
2c28e4526a6e
8720 image-create with a non-absolute path can cause strange results
Shawn Walker <srw@sun.com>
parents:
1125
diff
changeset
|
333 |
self.root = os.getcwd() |
2c28e4526a6e
8720 image-create with a non-absolute path can cause strange results
Shawn Walker <srw@sun.com>
parents:
1125
diff
changeset
|
334 |
|
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
335 |
self.imgdir = os.path.join(self.root, self.img_prefix) |
1037
56ff5f4fab83
8050 image-update fails from b110 to b111 at SUNWgnome-system-monitor manifest
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
999
diff
changeset
|
336 |
self.pkgdir = os.path.join(self.imgdir, "pkg") |
539
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
337 |
self.history.root_dir = self.imgdir |
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
338 |
|
554
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
339 |
if "PKG_CACHEDIR" in os.environ: |
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
340 |
self.dl_cache_dir = os.path.normpath( \ |
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
341 |
os.environ["PKG_CACHEDIR"]) |
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
342 |
self.is_user_cache_dir = True |
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
343 |
else: |
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
344 |
self.dl_cache_dir = os.path.normpath( \ |
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
345 |
os.path.join(self.imgdir, "download")) |
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
346 |
self.dl_cache_incoming = os.path.normpath(os.path.join( |
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
347 |
self.dl_cache_dir, "incoming-%d" % os.getpid())) |
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
348 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
349 |
def set_attrs(self, imgtype, root, is_zone, prefix, pub_url, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
350 |
ssl_key=None, ssl_cert=None, variants=EmptyDict, |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
351 |
refresh_allowed=True, progtrack=None): |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
352 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
353 |
self.__set_dirs(imgtype=imgtype, root=root) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
354 |
|
1086
16500d7bf1ca
8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents:
1085
diff
changeset
|
355 |
# Create the publisher object before creating the image... |
16500d7bf1ca
8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents:
1085
diff
changeset
|
356 |
repo = publisher.Repository() |
16500d7bf1ca
8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents:
1085
diff
changeset
|
357 |
repo.add_origin(pub_url, ssl_cert=ssl_cert, ssl_key=ssl_key) |
16500d7bf1ca
8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents:
1085
diff
changeset
|
358 |
newpub = publisher.Publisher(prefix, |
16500d7bf1ca
8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents:
1085
diff
changeset
|
359 |
meta_root=self._get_publisher_meta_root(prefix), |
16500d7bf1ca
8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents:
1085
diff
changeset
|
360 |
repositories=[repo]) |
16500d7bf1ca
8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents:
1085
diff
changeset
|
361 |
|
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
362 |
# Initialize and store the configuration object. |
1111
26c3e2407c53
8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents:
1107
diff
changeset
|
363 |
self.cfg_cache = imageconfig.ImageConfig(self.root) |
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
364 |
|
1086
16500d7bf1ca
8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents:
1085
diff
changeset
|
365 |
# ...so that if creation of the Publisher object fails, an |
16500d7bf1ca
8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents:
1085
diff
changeset
|
366 |
# empty, useless image won't be left behind. |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
367 |
if not os.path.exists(os.path.join(self.imgdir, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
368 |
imageconfig.CFG_FILE)): |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
369 |
self.history.log_operation_start("image-create") |
539
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
370 |
else: |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
371 |
self.history.log_operation_start("image-set-attributes") |
539
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
372 |
|
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
373 |
# Determine and add the default variants for the image. |
111 | 374 |
if is_zone: |
375 |
self.cfg_cache.filters["opensolaris.zone"] = "nonglobal" |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
376 |
self.cfg_cache.variants[ |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
377 |
"variant.opensolaris.zone"] = "nonglobal" |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
378 |
else: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
379 |
self.cfg_cache.variants[ |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
380 |
"variant.opensolaris.zone"] = "global" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
381 |
|
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
382 |
self.cfg_cache.variants["variant.arch"] = \ |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
383 |
variants.get("variant.arch", platform.processor()) |
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
384 |
|
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
385 |
# After setting up the default variants, add any overrides or |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
386 |
# additional variants specified. |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
387 |
self.cfg_cache.variants.update(variants) |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
388 |
|
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
389 |
# Now everything is ready for publisher configuration. |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
390 |
self.cfg_cache.preferred_publisher = newpub.prefix |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
391 |
self.add_publisher(newpub, refresh_allowed=refresh_allowed, |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
392 |
progtrack=progtrack) |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
393 |
|
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
394 |
# Next, create the image directories if they haven't been |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
395 |
# (add_publisher will normally do this if it needs to write |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
396 |
# something to disk). Waiting until after add_publisher is |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
397 |
# called avoids leaving an empty, useless set of directories |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
398 |
# for the image if the add fails. |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
399 |
self.mkdirs() |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
400 |
|
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
401 |
# Finally, since all operations were successful, save the image |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
402 |
# configuration. |
551 | 403 |
self.save_config() |
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
404 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
405 |
self.history.log_operation_end() |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
406 |
|
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
407 |
def is_liveroot(self): |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
408 |
return self.root == "/" |
281
81a0bb7f7d63
217 packages need to be able to [un]install users (groups, roles, etc)
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
271
diff
changeset
|
409 |
|
344
4c887185d780
528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents:
342
diff
changeset
|
410 |
def is_zone(self): |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
411 |
return self.cfg_cache.variants[ |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
412 |
"variant.opensolaris.zone"] == "nonglobal" |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
413 |
|
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
414 |
def get_arch(self): |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
415 |
return self.cfg_cache.variants["variant.arch"] |
344
4c887185d780
528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents:
342
diff
changeset
|
416 |
|
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
417 |
def get_root(self): |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
418 |
return self.root |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
419 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
420 |
def gen_publishers(self, inc_disabled=False): |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
421 |
if not self.cfg_cache: |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
422 |
raise CfgCacheError, "empty ImageConfig" |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
423 |
for p in self.cfg_cache.publishers: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
424 |
pub = self.cfg_cache.publishers[p] |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
425 |
if inc_disabled or not pub.disabled: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
426 |
yield self.cfg_cache.publishers[p] |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
427 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
428 |
def get_url_by_publisher(self, prefix=None): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
429 |
"""Return the URL prefix associated with the given prefix. |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
430 |
For the undefined case, represented by None, return the |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
431 |
preferred publisher.""" |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
432 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
433 |
# XXX This function is a possible location to insert one or more |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
434 |
# policies regarding use of mirror responses, etc. |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
435 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
436 |
if prefix is None: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
437 |
prefix = self.cfg_cache.preferred_publisher |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
438 |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
439 |
try: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
440 |
o = self.cfg_cache.publishers[prefix]["origin"] |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
441 |
except KeyError: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
442 |
# If the publisher that we're trying to get no longer |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
443 |
# exists, fall back to preferred publisher. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
444 |
prefix = self.cfg_cache.preferred_publisher |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
445 |
o = self.cfg_cache.publishers[prefix]["origin"] |
106
ed11fcd45545
pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents:
104
diff
changeset
|
446 |
|
146
9b9fcd56b8b2
Reduce use of the re module, for performance.
Danek Duvall <danek.duvall@sun.com>
parents:
145
diff
changeset
|
447 |
return o.rstrip("/") |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
448 |
|
648
9f1f457e78b2
3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents:
644
diff
changeset
|
449 |
def gen_depot_status(self): |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
450 |
"""Walk all publishers and return all depot status |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
451 |
objects for both mirrors and primary publishers.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
452 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
453 |
pubs = self.cfg_cache.publishers |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
454 |
# return depot status objects in publisher order |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
455 |
for pub in pubs.keys(): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
456 |
# first yield publisher origin |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
457 |
yield self.cfg_cache.publisher_status[pub] |
648
9f1f457e78b2
3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents:
644
diff
changeset
|
458 |
# then return mirrors |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
459 |
for ds in self.cfg_cache.mirror_status[pub]: |
648
9f1f457e78b2
3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents:
644
diff
changeset
|
460 |
yield ds |
9f1f457e78b2
3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents:
644
diff
changeset
|
461 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
462 |
def num_mirrors(self, pub): |
648
9f1f457e78b2
3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents:
644
diff
changeset
|
463 |
"""Return the number of mirrors configured for the |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
464 |
given publisher.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
465 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
466 |
if pub == None: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
467 |
pub = self.cfg_cache.preferred_publisher |
648
9f1f457e78b2
3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents:
644
diff
changeset
|
468 |
|
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
469 |
try: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
470 |
num = len(self.cfg_cache.mirror_status[pub]) |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
471 |
except KeyError: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
472 |
# pub isn't in the list of mirrors, return 0 |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
473 |
num = 0 |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
474 |
|
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
475 |
return num |
648
9f1f457e78b2
3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents:
644
diff
changeset
|
476 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
477 |
def select_mirror(self, pub = None, chosen_set = None): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
478 |
"""For the given publisher, look through the status of |
461
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
479 |
the mirrors. Pick the best one. This method returns |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
480 |
a DepotStatus object or None. The chosen_set argument |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
481 |
contains a set object that lists the mirrors that were |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
482 |
previously chosen. This allows us to choose both |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
483 |
by depot status statistics and ensures we don't |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
484 |
always pick the same depot.""" |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
485 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
486 |
if pub == None: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
487 |
pub = self.cfg_cache.preferred_publisher |
461
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
488 |
try: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
489 |
slst = self.cfg_cache.mirror_status[pub] |
461
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
490 |
except KeyError: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
491 |
# If the publisher that we're trying to get no longer |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
492 |
# exists, fall back to preferred publisher. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
493 |
pub = self.cfg_cache.preferred_publisher |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
494 |
slst = self.cfg_cache.mirror_status[pub] |
461
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
495 |
|
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
496 |
if len(slst) == 0: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
497 |
if pub in self.cfg_cache.publisher_status: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
498 |
return self.cfg_cache.publisher_status[pub] |
461
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
499 |
else: |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
500 |
return None |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
501 |
|
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
502 |
# Choose mirror with fewest errors. |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
503 |
# If mirrors have same number of errors, choose mirror |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
504 |
# with smaller number of good transactions. Assume it's |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
505 |
# being underused, not high-latency. |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
506 |
# |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
507 |
# XXX Will need to revisit the above assumption. |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
508 |
def cmp_depotstatus(a, b): |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
509 |
res = cmp(a.errors, b.errors) |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
510 |
if res == 0: |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
511 |
return cmp(a.good_tx, b.good_tx) |
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
512 |
return res |
461
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
513 |
|
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
514 |
slst.sort(cmp = cmp_depotstatus) |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
515 |
|
648
9f1f457e78b2
3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents:
644
diff
changeset
|
516 |
# All mirrors in the chosen_set have already been |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
517 |
# selected. Try the publisher origin instead. |
648
9f1f457e78b2
3803 Mirror selection should avoid authority origin
johansen <johansen@sun.com>
parents:
644
diff
changeset
|
518 |
# Empty chosen_set, next time we start over. |
461
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
519 |
if chosen_set and len(chosen_set) == len(slst): |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
520 |
chosen_set.clear() |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
521 |
return self.cfg_cache.publisher_status[pub] |
461
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
522 |
|
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
523 |
if chosen_set and slst[0] in chosen_set: |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
524 |
for ds in slst: |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
525 |
if ds not in chosen_set: |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
526 |
return ds |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
527 |
|
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
528 |
return slst[0] |
37cf3ac75e37
1018 actions with payloads should include all sizes and hashes
johansen <johansen@sun.com>
parents:
453
diff
changeset
|
529 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
530 |
def get_ssl_credentials(self, prefix=None, origin=None, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
531 |
pubent=None): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
532 |
"""Deprecated; this function will be removed in a future |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
533 |
release. This information should be retrieved directly from a |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
534 |
repository origin or mirror object. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
535 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
536 |
Return a tuple containing (ssl_key, ssl_cert) for the |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
537 |
specified publisher prefix. If the publisher isn't specified, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
538 |
attempt to determine the publisher by the given origin. If |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
539 |
neither is specified, use the preferred publisher. pubent |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
540 |
is a dictionary argument that contains the publisher |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
541 |
information.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
542 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
543 |
if not pubent and prefix is None: |
322
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
544 |
if origin is None: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
545 |
prefix = self.cfg_cache.preferred_publisher |
322
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
546 |
else: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
547 |
pubs = self.cfg_cache.publishers |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
548 |
for pfx, pub in pubs.iteritems(): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
549 |
repo = pub.selected_repository |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
550 |
if repo.has_origin(origin): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
551 |
prefix = pfx |
322
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
552 |
break |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
553 |
else: |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
554 |
return None |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
555 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
556 |
# One of these should be defined at this point unless the |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
557 |
# caller didn't provide anything. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
558 |
assert prefix or origin or pubent |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
559 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
560 |
if not pubent: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
561 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
562 |
pubent = self.cfg_cache.publishers[prefix] |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
563 |
except KeyError: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
564 |
prefix = self.cfg_cache.preferred_publisher |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
565 |
pubent = self.cfg_cache.publishers[prefix] |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
566 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
567 |
repo = pubent.selected_repository |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
568 |
origin = repo.origins[0] |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
569 |
return (origin.ssl_key, origin.ssl_cert) |
479
de75c17238ff
2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
570 |
|
de75c17238ff
2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
571 |
def check_cert_validity(self): |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
572 |
"""Look through the publishers defined for the image. Print |
479
de75c17238ff
2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
573 |
a message and exit with an error if one of the certificates |
de75c17238ff
2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
574 |
has expired. If certificates are getting close to expiration, |
de75c17238ff
2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
575 |
print a warning instead.""" |
de75c17238ff
2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
576 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
577 |
for p in self.gen_publishers(): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
578 |
for r in p.repositories: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
579 |
for uri in r.origins: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
580 |
if uri.ssl_cert: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
581 |
misc.validate_ssl_cert( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
582 |
uri.ssl_cert, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
583 |
prefix=p.prefix, uri=uri) |
479
de75c17238ff
2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
584 |
return True |
de75c17238ff
2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
585 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
586 |
def get_uuid(self, prefix): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
587 |
"""Deprecated; this function will be removed in a future |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
588 |
release. This information should be retrieved directly from a |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
589 |
publisher object. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
590 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
591 |
Return the UUID for the specified publisher prefix. If the |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
592 |
policy for sending the UUID is set to false, return None.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
593 |
|
551 | 594 |
if not self.cfg_cache.get_policy(imageconfig.SEND_UUID): |
595 |
return None |
|
596 |
||
597 |
try: |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
598 |
return self.cfg_cache.publishers[prefix].client_uuid |
551 | 599 |
except KeyError: |
600 |
return None |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
601 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
602 |
def has_publisher(self, prefix=None, alias=None): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
603 |
for pub in self.gen_publishers(): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
604 |
if prefix == pub.prefix or (alias and |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
605 |
alias == pub.alias): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
606 |
return True |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
607 |
return False |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
608 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
609 |
def remove_publisher(self, prefix=None, alias=None, progtrack=None): |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
610 |
if not progtrack: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
611 |
progtrack = progress.QuietProgressTracker() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
612 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
613 |
self.history.log_operation_start("remove-publisher") |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
614 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
615 |
pub = self.get_publisher(prefix=prefix, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
616 |
alias=alias) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
617 |
except api_errors.ApiException, e: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
618 |
self.history.log_operation_end(e) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
619 |
raise e |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
620 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
621 |
if pub.prefix == self.cfg_cache.preferred_publisher: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
622 |
e = api_errors.RemovePreferredPublisher() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
623 |
self.history.log_operation_end(error=e) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
624 |
raise e |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
625 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
626 |
self.cfg_cache.remove_publisher(prefix) |
551 | 627 |
self.save_config() |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
628 |
self.remove_publisher_metadata(pub) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
629 |
self.load_catalogs(progtrack, force=True) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
630 |
self.history.log_operation_end() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
631 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
632 |
def get_publishers(self): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
633 |
return self.cfg_cache.publishers |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
634 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
635 |
def get_publisher(self, prefix=None, alias=None, origin=None): |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
636 |
publishers = [p for p in self.get_publishers().values()] |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
637 |
for pub in publishers: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
638 |
if prefix and prefix == pub.prefix: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
639 |
return pub |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
640 |
elif alias and alias == pub.alias: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
641 |
return pub |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
642 |
elif origin and \ |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
643 |
pub.selected_repository.has_origin(origin): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
644 |
return pub |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
645 |
raise api_errors.UnknownPublisher(max(prefix, alias, origin)) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
646 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
647 |
def get_publisher_last_update_time(self, prefix, cached=True): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
648 |
"""Returns a datetime object (or 'None') representing the last |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
649 |
time the catalog for a publisher was updated. |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
650 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
651 |
If the catalog has already been loaded, this reflects the |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
652 |
in-memory state of the catalog. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
653 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
654 |
If the catalog has not already been loaded or 'cached' is False, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
655 |
then the catalog will be temporarily loaded and the most recent |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
656 |
information returned.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
657 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
658 |
if not cached: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
659 |
try: |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
660 |
cat = self.__catalogs[prefix] |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
661 |
except KeyError: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
662 |
pass |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
663 |
else: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
664 |
update_dt = cat.last_modified() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
665 |
if update_dt: |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
666 |
update_dt = catalog.ts_to_datetime( |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
667 |
update_dt) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
668 |
return update_dt |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
669 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
670 |
# Temporarily retrieve the catalog object, but don't |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
671 |
# cache it as that would interfere with load_catalogs. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
672 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
673 |
croot = "%s/catalog/%s" % (self.imgdir, prefix) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
674 |
cat = catalog.Catalog(croot, publisher=prefix) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
675 |
except (EnvironmentError, catalog.CatalogException): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
676 |
cat = None |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
677 |
|
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
678 |
update_dt = None |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
679 |
if cat: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
680 |
update_dt = cat.last_modified() |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
681 |
if update_dt: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
682 |
update_dt = catalog.ts_to_datetime(update_dt) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
683 |
return update_dt |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
684 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
685 |
def get_preferred_publisher(self): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
686 |
"""Returns the prefix of the preferred publisher.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
687 |
return self.cfg_cache.preferred_publisher |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
688 |
|
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
689 |
def set_preferred_publisher(self, prefix=None, alias=None, pub=None): |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
690 |
"""Sets the preferred publisher for packaging operations. |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
691 |
|
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
692 |
'prefix' is an optional string value specifying the name of |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
693 |
a publisher; ignored if 'pub' is provided. |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
694 |
|
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
695 |
'alias' is an optional string value specifying the alias of |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
696 |
a publisher; ignored if 'pub' is provided. |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
697 |
|
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
698 |
'pub' is an optional Publisher object identifying the |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
699 |
publisher to set as the preferred publisher. |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
700 |
|
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
701 |
One of the above parameters must be provided.""" |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
702 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
703 |
self.history.log_operation_start("set-preferred-publisher") |
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
704 |
|
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
705 |
if not pub: |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
706 |
try: |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
707 |
pub = self.get_publisher(prefix=prefix, |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
708 |
alias=alias) |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
709 |
except api_errors.UnknownPublisher, e: |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
710 |
self.history.log_operation_end(error=e) |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
711 |
raise e |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
712 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
713 |
if pub.disabled: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
714 |
e = api_errors.SetPreferredPublisherDisabled(pub) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
715 |
self.history.log_operation_end(error=e) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
716 |
raise e |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
717 |
self.cfg_cache.preferred_publisher = pub.prefix |
551 | 718 |
self.save_config() |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
719 |
self.history.log_operation_end() |
539
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
720 |
|
551 | 721 |
def set_property(self, prop_name, prop_value): |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
722 |
assert prop_name != "preferred-publisher" |
551 | 723 |
self.cfg_cache.properties[prop_name] = prop_value |
724 |
self.save_config() |
|
725 |
||
726 |
def get_property(self, prop_name): |
|
727 |
return self.cfg_cache.properties[prop_name] |
|
728 |
||
729 |
def has_property(self, prop_name): |
|
730 |
return prop_name in self.cfg_cache.properties |
|
731 |
||
732 |
def delete_property(self, prop_name): |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
733 |
assert prop_name != "preferred-publisher" |
551 | 734 |
del self.cfg_cache.properties[prop_name] |
735 |
self.save_config() |
|
736 |
||
737 |
def properties(self): |
|
738 |
for p in self.cfg_cache.properties: |
|
739 |
yield p |
|
740 |
||
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
741 |
def add_publisher(self, pub, refresh_allowed=True, progtrack=None): |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
742 |
"""Adds the provided publisher object to the image |
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
743 |
configuration. |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
744 |
|
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
745 |
'refresh_allowed' is an optional, boolean value indicating |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
746 |
whether the publisher's metadata should be retrieved when adding |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
747 |
it to the image's configuration. |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
748 |
|
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
749 |
'progtrack' is an optional ProgressTracker object.""" |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
750 |
self.history.log_operation_start("add-publisher") |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
751 |
for p in self.cfg_cache.publishers.values(): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
752 |
if pub == p or (pub.alias and pub.alias == p.alias): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
753 |
error = api_errors.DuplicatePublisher(pub) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
754 |
self.history.log_operation_end(error=error) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
755 |
raise error |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
756 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
757 |
# Must assign this first before performing any more operations. |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
758 |
pub.meta_root = self._get_publisher_meta_root(pub.prefix) |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
759 |
self.cfg_cache.publishers[pub.prefix] = pub |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
760 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
761 |
# This ensures that if data is leftover from a publisher |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
762 |
# with the same prefix as this one that it gets purged |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
763 |
# first to prevent usage of stale data. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
764 |
self.remove_publisher_metadata(pub) |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
765 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
766 |
if refresh_allowed: |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
767 |
try: |
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
768 |
# First, verify that the publisher has a valid |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
769 |
# pkg(5) repository. |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
770 |
self.valid_publisher_test(pub) |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
771 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
772 |
self.__retrieve_catalogs(full_refresh=True, |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
773 |
pubs=[pub], progtrack=progtrack) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
774 |
except Exception, e: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
775 |
# Remove the newly added publisher since the |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
776 |
# retrieval failed. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
777 |
del self.cfg_cache.publishers[pub.prefix] |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
778 |
self.history.log_operation_end(error=e) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
779 |
raise |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
780 |
except: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
781 |
# Remove the newly added publisher since the |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
782 |
# retrieval failed. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
783 |
del self.cfg_cache.publishers[pub.prefix] |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
784 |
self.history.log_operation_end( |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
785 |
result=history.RESULT_FAILED_UNKNOWN) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
786 |
raise |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
787 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
788 |
# Only after success should the configuration be saved. |
551 | 789 |
self.save_config() |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
790 |
self.history.log_operation_end() |
539
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
791 |
|
235
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
792 |
def verify(self, fmri, progresstracker, **args): |
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
793 |
"""generator that returns any errors in installed pkgs |
235
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
794 |
as tuple of action, list of errors""" |
222
12006bf2a260
4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
221
diff
changeset
|
795 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
796 |
for act in self.get_manifest(fmri).gen_actions( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
797 |
self.list_excludes()): |
235
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
798 |
errors = act.verify(self, pkg_fmri=fmri, **args) |
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
799 |
progresstracker.verify_add_progress(fmri) |
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
800 |
actname = act.distinguished_name() |
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
801 |
if errors: |
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
802 |
progresstracker.verify_yield_error(actname, |
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
803 |
errors) |
583
fc856572d86e
388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents:
582
diff
changeset
|
804 |
yield (act, errors) |
fc856572d86e
388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents:
582
diff
changeset
|
805 |
|
fc856572d86e
388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents:
582
diff
changeset
|
806 |
def repair(self, repairs, progtrack): |
fc856572d86e
388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents:
582
diff
changeset
|
807 |
"""Repair any actions in the fmri that failed a verify.""" |
687
3d7060f40501
4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents:
685
diff
changeset
|
808 |
# XXX: This (lambda x: False) is temporary until we move pkg fix |
3d7060f40501
4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents:
685
diff
changeset
|
809 |
# into the api and can actually use the |
3d7060f40501
4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents:
685
diff
changeset
|
810 |
# api::__check_cancelation() function. |
583
fc856572d86e
388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents:
582
diff
changeset
|
811 |
pps = [] |
fc856572d86e
388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents:
582
diff
changeset
|
812 |
for fmri, actions in repairs: |
fc856572d86e
388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents:
582
diff
changeset
|
813 |
msg("Repairing: %-50s" % fmri.get_pkg_stem()) |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
814 |
m = self.get_manifest(fmri) |
692 | 815 |
pp = pkgplan.PkgPlan(self, progtrack, lambda: False) |
583
fc856572d86e
388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents:
582
diff
changeset
|
816 |
pp.propose_repair(fmri, m, actions) |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
817 |
pp.evaluate(self.list_excludes(), self.list_excludes()) |
583
fc856572d86e
388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents:
582
diff
changeset
|
818 |
pps.append(pp) |
fc856572d86e
388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents:
582
diff
changeset
|
819 |
|
692 | 820 |
ip = imageplan.ImagePlan(self, progtrack, lambda: False) |
625
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
621
diff
changeset
|
821 |
progtrack.evaluate_start() |
583
fc856572d86e
388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents:
582
diff
changeset
|
822 |
ip.pkg_plans = pps |
687
3d7060f40501
4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents:
685
diff
changeset
|
823 |
|
3d7060f40501
4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents:
685
diff
changeset
|
824 |
ip.evaluate() |
3d7060f40501
4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents:
685
diff
changeset
|
825 |
ip.preexecute() |
3d7060f40501
4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents:
685
diff
changeset
|
826 |
ip.execute() |
583
fc856572d86e
388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents:
582
diff
changeset
|
827 |
|
fc856572d86e
388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents:
582
diff
changeset
|
828 |
return True |
222
12006bf2a260
4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
221
diff
changeset
|
829 |
|
50 | 830 |
def has_manifest(self, fmri): |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
831 |
mpath = fmri.get_dir_path() |
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
832 |
|
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
833 |
local_mpath = "%s/pkg/%s/manifest" % (self.imgdir, mpath) |
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
834 |
|
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
835 |
if (os.path.exists(local_mpath)): |
50 | 836 |
return True |
837 |
||
838 |
return False |
|
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
839 |
|
877
b23f809e8abd
6653 we should elide alternate architectures from in-memory manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
855
diff
changeset
|
840 |
def __fetch_manifest_with_retries(self, fmri, excludes=EmptyI): |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
841 |
"""go get the manifest we want - retry if needed""" |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
842 |
|
576
6ee6de304041
3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents:
573
diff
changeset
|
843 |
retry_count = global_settings.PKG_TIMEOUT_MAX |
6ee6de304041
3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents:
573
diff
changeset
|
844 |
failures = TransportFailures() |
388
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
845 |
|
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
846 |
while retry_count > 0: |
388
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
847 |
try: |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
848 |
mcontent = retrieve.get_manifest(self, fmri) |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
849 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
850 |
m = manifest.CachedManifest(fmri, self.pkgdir, |
1037
56ff5f4fab83
8050 image-update fails from b110 to b111 at SUNWgnome-system-monitor manifest
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
999
diff
changeset
|
851 |
self.cfg_cache.preferred_publisher, |
56ff5f4fab83
8050 image-update fails from b110 to b111 at SUNWgnome-system-monitor manifest
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
999
diff
changeset
|
852 |
excludes, mcontent) |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
853 |
|
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
854 |
# What is the client currently processing? |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
855 |
targets = self.state.get_targets() |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
856 |
|
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
857 |
intent = None |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
858 |
for entry in targets: |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
859 |
target, reason = entry |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
860 |
|
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
861 |
# Ignore the publisher for comparison. |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
862 |
np_target = target.get_fmri( |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
863 |
anarchy=True) |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
864 |
np_fmri = fmri.get_fmri(anarchy=True) |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
865 |
if np_target == np_fmri: |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
866 |
intent = reason |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
867 |
|
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
868 |
# If no intent could be found, assume |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
869 |
# INTENT_INFO. |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
870 |
self.__set_touched_manifest(fmri, |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
871 |
max(intent, imagestate.INTENT_INFO)) |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
872 |
|
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
873 |
return m |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
874 |
|
576
6ee6de304041
3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents:
573
diff
changeset
|
875 |
except TransportException, e: |
399
e594d9c5bd60
2295 pkg forgets to raise TransferTimedOutException
johansen <johansen@sun.com>
parents:
397
diff
changeset
|
876 |
retry_count -= 1 |
576
6ee6de304041
3777 PKG_TIMEOUT_MAX is a placebo setting
Dan Price <dp@eng.sun.com>
parents:
573
diff
changeset
|
877 |
failures.append(e) |
399
e594d9c5bd60
2295 pkg forgets to raise TransferTimedOutException
johansen <johansen@sun.com>
parents:
397
diff
changeset
|
878 |
|
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
879 |
except MalformedActionError, e: |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
880 |
retry_count -= 1 |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
881 |
pub = fmri.get_publisher() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
882 |
url = self.cfg_cache.publishers[pub]["origin"] |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
883 |
te = misc.TransferContentException(url=url, |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
884 |
reason=str(e)) |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
885 |
failures.append(te) |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
886 |
|
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
887 |
raise failures |
388
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
888 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
889 |
def __get_touched_manifest(self, fmri, intent): |
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
890 |
"""Returns whether intent information has been provided for the |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
891 |
given fmri.""" |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
892 |
|
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
893 |
op = self.history.operation_name |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
894 |
if not op: |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
895 |
# The client may not have provided the name of the |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
896 |
# operation it is performing. |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
897 |
op = "unknown" |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
898 |
|
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
899 |
if op not in self.__touched_manifests: |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
900 |
# No intent information has been provided for fmris |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
901 |
# for the current operation. |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
902 |
return False |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
903 |
|
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
904 |
f = str(fmri) |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
905 |
if f not in self.__touched_manifests[op]: |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
906 |
# No intent information has been provided for this |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
907 |
# fmri for the current operation. |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
908 |
return False |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
909 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
910 |
if intent not in self.__touched_manifests[op][f]: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
911 |
# No intent information has been provided for this |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
912 |
# fmri for the current operation and reason. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
913 |
return False |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
914 |
|
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
915 |
return True |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
916 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
917 |
def __set_touched_manifest(self, fmri, intent): |
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
918 |
"""Records that intent information has been provided for the |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
919 |
given fmri's manifest.""" |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
920 |
|
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
921 |
op = self.history.operation_name |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
922 |
if not op: |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
923 |
# The client may not have provided the name of the |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
924 |
# operation it is performing. |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
925 |
op = "unknown" |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
926 |
|
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
927 |
if op not in self.__touched_manifests: |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
928 |
# No intent information has yet been provided for fmris |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
929 |
# for the current operation. |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
930 |
self.__touched_manifests[op] = {} |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
931 |
|
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
932 |
f = str(fmri) |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
933 |
if f not in self.__touched_manifests[op]: |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
934 |
# No intent information has yet been provided for this |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
935 |
# fmri for the current operation. |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
936 |
self.__touched_manifests[op][f] = { intent: None } |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
937 |
else: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
938 |
# No intent information has yet been provided for this |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
939 |
# fmri for the current operation and reason. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
940 |
self.__touched_manifests[op][f][intent] = None |
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
941 |
|
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
942 |
def __touch_manifest(self, fmri): |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
943 |
"""Perform steps necessary to 'touch' a manifest to provide |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
944 |
intent information. Ignores most exceptions as this operation |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
945 |
is only for informational purposes.""" |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
946 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
947 |
# What is the client currently processing? |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
948 |
target, intent = self.state.get_target() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
949 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
950 |
# Ignore dry-runs of operations or operations which do not have |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
951 |
# a set target. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
952 |
if not target or intent == imagestate.INTENT_EVALUATE: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
953 |
return |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
954 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
955 |
if not self.__get_touched_manifest(fmri, intent): |
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
956 |
# If the manifest for this fmri hasn't been "seen" |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
957 |
# before, determine if intent information needs to be |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
958 |
# provided. |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
959 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
960 |
# Ignore the publisher for comparison. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
961 |
np_target = target.get_fmri(anarchy=True) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
962 |
np_fmri = fmri.get_fmri(anarchy=True) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
963 |
if np_target == np_fmri: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
964 |
# If the client is currently processing |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
965 |
# the given fmri (for an install, etc.) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
966 |
# then intent information is needed. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
967 |
retrieve.touch_manifest(self, fmri) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
968 |
self.__set_touched_manifest(fmri, intent) |
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
969 |
|
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
970 |
def get_manifest_path(self, fmri): |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
971 |
"""Return path to on-disk manifest""" |
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
972 |
mpath = os.path.join(self.imgdir, "pkg", |
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
973 |
fmri.get_dir_path(), "manifest") |
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
974 |
return mpath |
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
975 |
|
877
b23f809e8abd
6653 we should elide alternate architectures from in-memory manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
855
diff
changeset
|
976 |
def __get_manifest(self, fmri, excludes=EmptyI): |
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
977 |
"""Find on-disk manifest and create in-memory Manifest |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
978 |
object.... grab from server if needed""" |
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
979 |
|
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
980 |
try: |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
981 |
return manifest.CachedManifest(fmri, self.pkgdir, |
1037
56ff5f4fab83
8050 image-update fails from b110 to b111 at SUNWgnome-system-monitor manifest
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
999
diff
changeset
|
982 |
self.cfg_cache.preferred_publisher, |
56ff5f4fab83
8050 image-update fails from b110 to b111 at SUNWgnome-system-monitor manifest
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
999
diff
changeset
|
983 |
excludes) |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
984 |
except KeyError: |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
985 |
return self.__fetch_manifest_with_retries(fmri, |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
986 |
excludes) |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
987 |
|
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
988 |
def get_manifest(self, fmri, add_to_cache=True, all_arch=False): |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
989 |
"""return manifest; uses cached version if available. |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
990 |
all_arch controls whether manifest contains actions |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
991 |
for all architectures""" |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
992 |
|
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
993 |
# Normally elide other arch variants |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
994 |
if all_arch: |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
995 |
add_to_cache = False |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
996 |
v = EmptyI |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
997 |
else: |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
998 |
arch = {"variant.arch": self.get_arch()} |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
999 |
v = [variant.Variants(arch).allow_action] |
877
b23f809e8abd
6653 we should elide alternate architectures from in-memory manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
855
diff
changeset
|
1000 |
|
634
44055bedbebd
4263 manifest caching should only be done for pkg(1) for now
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
625
diff
changeset
|
1001 |
# XXX This is a temporary workaround so that GUI api consumsers |
44055bedbebd
4263 manifest caching should only be done for pkg(1) for now
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
625
diff
changeset
|
1002 |
# are not negatively impacted by manifest caching. This should |
44055bedbebd
4263 manifest caching should only be done for pkg(1) for now
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
625
diff
changeset
|
1003 |
# be removed by bug 4231 whenever a better way to handle caching |
44055bedbebd
4263 manifest caching should only be done for pkg(1) for now
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
625
diff
changeset
|
1004 |
# is found. |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
1005 |
if global_settings.client_name == "pkg" and not all_arch: |
634
44055bedbebd
4263 manifest caching should only be done for pkg(1) for now
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
625
diff
changeset
|
1006 |
if fmri in self.__manifest_cache: |
44055bedbebd
4263 manifest caching should only be done for pkg(1) for now
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
625
diff
changeset
|
1007 |
m = self.__manifest_cache[fmri] |
44055bedbebd
4263 manifest caching should only be done for pkg(1) for now
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
625
diff
changeset
|
1008 |
else: |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
1009 |
m = self.__get_manifest(fmri, v) |
886
8f40fc0ee8f9
6712 search shouldn't index actions for other variants of an image
Brock Pytlik <bpytlik@sun.com>
parents:
877
diff
changeset
|
1010 |
if add_to_cache: |
8f40fc0ee8f9
6712 search shouldn't index actions for other variants of an image
Brock Pytlik <bpytlik@sun.com>
parents:
877
diff
changeset
|
1011 |
self.__manifest_cache[fmri] = m |
567
ea1d96e269a4
3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents:
565
diff
changeset
|
1012 |
else: |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
1013 |
m = self.__get_manifest(fmri, v) |
567
ea1d96e269a4
3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents:
565
diff
changeset
|
1014 |
|
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
1015 |
self.__touch_manifest(fmri) |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1016 |
return m |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1017 |
|
964
a6b1ee94f115
7547 Some working set reductions possible for image-update
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
956
diff
changeset
|
1018 |
def uncache_manifest(self, fmri): |
a6b1ee94f115
7547 Some working set reductions possible for image-update
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
956
diff
changeset
|
1019 |
"""Remove specified FMRI from manifest cache.""" |
a6b1ee94f115
7547 Some working set reductions possible for image-update
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
956
diff
changeset
|
1020 |
|
a6b1ee94f115
7547 Some working set reductions possible for image-update
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
956
diff
changeset
|
1021 |
if fmri in self.__manifest_cache: |
a6b1ee94f115
7547 Some working set reductions possible for image-update
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
956
diff
changeset
|
1022 |
del self.__manifest_cache[fmri] |
a6b1ee94f115
7547 Some working set reductions possible for image-update
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
956
diff
changeset
|
1023 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1024 |
def installed_file_publisher(self, filepath): |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1025 |
"""Find the pkg's installed file named by filepath. |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1026 |
Return the publisher that installed this package.""" |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1027 |
|
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
1028 |
f = file(filepath) |
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
1029 |
try: |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
1030 |
flines = f.readlines() |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1031 |
version, pub = flines |
918
6a14979b842a
1164 "installed" metadata files don't end in newlines
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
891
diff
changeset
|
1032 |
version = version.strip() |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1033 |
pub = pub.strip() |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
1034 |
f.close() |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1035 |
except ValueError: |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
1036 |
# If we get a ValueError, we've encountered an |
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
1037 |
# installed file of a previous format. If we want |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
1038 |
# upgrade to work in this situation, it's necessary |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
1039 |
# to assume that the package was installed from |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1040 |
# the preferred publisher. Here, we set up |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1041 |
# the publisher to record that. |
356
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
1042 |
if flines: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1043 |
pub = flines[0] |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1044 |
pub = pub.strip() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1045 |
newpub = "%s_%s" % (pkg.fmri.PREF_PUB_PFX, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1046 |
pub) |
356
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
1047 |
else: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1048 |
newpub = "%s_%s" % (pkg.fmri.PREF_PUB_PFX, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1049 |
self.get_preferred_publisher()) |
356
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
1050 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1051 |
pub = newpub |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1052 |
|
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
1053 |
try: |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
1054 |
f = file(filepath, "w") |
1107
d2cc5edc2593
8600 incompatibility due to newline following publisher in installed file
Tom Mueller <Tom.Mueller@sun.com>
parents:
1102
diff
changeset
|
1055 |
f.writelines(["VERSION_1\n", newpub]) |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
1056 |
f.close() |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
1057 |
except IOError, e: |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
1058 |
if e.errno not in (errno.EACCES, errno.EROFS): |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
1059 |
raise |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1060 |
assert pub |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1061 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1062 |
return pub |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1063 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1064 |
def _install_file(self, fmri): |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1065 |
"""Returns the path to the "installed" file for a given fmri.""" |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
1066 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1067 |
return "%s/pkg/%s/installed" % (self.imgdir, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1068 |
fmri.get_dir_path()) |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1069 |
|
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1070 |
def install_file_present(self, fmri): |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1071 |
"""Returns true if the package named by the fmri is installed |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1072 |
on the system. Otherwise, returns false.""" |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1073 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1074 |
return os.path.exists(self._install_file(fmri)) |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1075 |
|
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1076 |
def add_install_file(self, fmri): |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1077 |
"""Take an image and fmri. Write a file to disk that |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1078 |
indicates that the package named by the fmri has been |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1079 |
installed.""" |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1080 |
|
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1081 |
# XXX This can be removed at some point in the future once we |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1082 |
# think this link is available on all systems |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1083 |
if not os.path.isdir("%s/state/installed" % self.imgdir): |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1084 |
self.__update_installed_pkgs() |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1085 |
|
717
c40259b4ce98
4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents:
715
diff
changeset
|
1086 |
try: |
c40259b4ce98
4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents:
715
diff
changeset
|
1087 |
f = file(self._install_file(fmri), "w") |
c40259b4ce98
4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents:
715
diff
changeset
|
1088 |
except EnvironmentError: |
c40259b4ce98
4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents:
715
diff
changeset
|
1089 |
try: |
c40259b4ce98
4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents:
715
diff
changeset
|
1090 |
os.makedirs(os.path.dirname( |
c40259b4ce98
4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents:
715
diff
changeset
|
1091 |
self._install_file(fmri))) |
c40259b4ce98
4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents:
715
diff
changeset
|
1092 |
except EnvironmentError, e: |
c40259b4ce98
4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents:
715
diff
changeset
|
1093 |
if e.errno == errno.EACCES: |
c40259b4ce98
4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents:
715
diff
changeset
|
1094 |
raise api_errors.PermissionsException( |
c40259b4ce98
4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents:
715
diff
changeset
|
1095 |
e.filename) |
1075
2c935307c8ab
7593 stack trace on reinstallation of package with insufficient permissions
Rich Burridge <rich.burridge@sun.com>
parents:
1068
diff
changeset
|
1096 |
if e.errno != errno.EEXIST and \ |
2c935307c8ab
7593 stack trace on reinstallation of package with insufficient permissions
Rich Burridge <rich.burridge@sun.com>
parents:
1068
diff
changeset
|
1097 |
not os.path.isdir(e.filename): |
2c935307c8ab
7593 stack trace on reinstallation of package with insufficient permissions
Rich Burridge <rich.burridge@sun.com>
parents:
1068
diff
changeset
|
1098 |
raise |
2c935307c8ab
7593 stack trace on reinstallation of package with insufficient permissions
Rich Burridge <rich.burridge@sun.com>
parents:
1068
diff
changeset
|
1099 |
|
717
c40259b4ce98
4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents:
715
diff
changeset
|
1100 |
f = file(self._install_file(fmri), "w") |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1101 |
|
1107
d2cc5edc2593
8600 incompatibility due to newline following publisher in installed file
Tom Mueller <Tom.Mueller@sun.com>
parents:
1102
diff
changeset
|
1102 |
f.writelines(["VERSION_1\n", fmri.get_publisher_str()]) |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1103 |
f.close() |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1104 |
|
434
48c05c66cdd2
2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents:
432
diff
changeset
|
1105 |
fi = file("%s/state/installed/%s" % (self.imgdir, |
48c05c66cdd2
2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents:
432
diff
changeset
|
1106 |
fmri.get_link_path()), "w") |
48c05c66cdd2
2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents:
432
diff
changeset
|
1107 |
fi.close() |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1108 |
self.__pkg_states[urllib.unquote(fmri.get_link_path())] = \ |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1109 |
(PKG_STATE_INSTALLED, fmri) |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1110 |
|
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1111 |
def remove_install_file(self, fmri): |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1112 |
"""Take an image and a fmri. Remove the file from disk |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1113 |
that indicates that the package named by the fmri has been |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1114 |
installed.""" |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1115 |
|
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1116 |
# XXX This can be removed at some point in the future once we |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1117 |
# think this link is available on all systems |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1118 |
if not os.path.isdir("%s/state/installed" % self.imgdir): |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1119 |
self.__update_installed_pkgs() |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1120 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1121 |
os.unlink(self._install_file(fmri)) |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1122 |
try: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1123 |
os.unlink("%s/state/installed/%s" % (self.imgdir, |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1124 |
fmri.get_link_path())) |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1125 |
except EnvironmentError, e: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1126 |
if e.errno != errno.ENOENT: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1127 |
raise |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1128 |
self.__pkg_states[urllib.unquote(fmri.get_link_path())] = \ |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1129 |
(PKG_STATE_KNOWN, fmri) |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1130 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1131 |
def __update_installed_pkgs(self): |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1132 |
"""Take the image's record of installed packages from the |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1133 |
prototype layout, with an installed file in each |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1134 |
$META/pkg/stem/version directory, to the $META/state/installed |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1135 |
summary directory form.""" |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1136 |
|
658
e470d4688084
4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents:
655
diff
changeset
|
1137 |
# If the directory is empty or it doesn't exist, we should |
e470d4688084
4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents:
655
diff
changeset
|
1138 |
# populate it. The easy test is to try to remove the directory, |
e470d4688084
4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents:
655
diff
changeset
|
1139 |
# which will fail if it's already got entries in it, or doesn't |
e470d4688084
4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents:
655
diff
changeset
|
1140 |
# exist. Other errors are beyond our capability to handle. |
834
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1141 |
statedir = os.path.join(self.imgdir, "state", "installed") |
658
e470d4688084
4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents:
655
diff
changeset
|
1142 |
try: |
834
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1143 |
os.rmdir(statedir) |
658
e470d4688084
4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents:
655
diff
changeset
|
1144 |
except EnvironmentError, e: |
834
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1145 |
if e.errno in (errno.EEXIST, errno.ENOTEMPTY): |
658
e470d4688084
4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents:
655
diff
changeset
|
1146 |
return |
685
6f53483db920
1469 image-update by unprivileged user should give better error message
Brock Pytlik <bpytlik@sun.com>
parents:
674
diff
changeset
|
1147 |
elif e.errno == errno.EACCES: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1148 |
# The directory may exist and be non-empty |
834
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1149 |
# even though we got EACCES. Try |
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1150 |
# to determine its emptiness another way. |
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1151 |
try: |
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1152 |
if os.path.isdir(statedir) and \ |
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1153 |
len(os.listdir(statedir)) > 0: |
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1154 |
return |
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1155 |
except EnvironmentError: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1156 |
# ignore this error, pass on the |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1157 |
# original access error |
834
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1158 |
pass |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1159 |
raise api_errors.PermissionsException( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1160 |
e.filename) |
658
e470d4688084
4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents:
655
diff
changeset
|
1161 |
elif e.errno != errno.ENOENT: |
e470d4688084
4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents:
655
diff
changeset
|
1162 |
raise |
e470d4688084
4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents:
655
diff
changeset
|
1163 |
|
834
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1164 |
tmpdir = os.path.join(self.imgdir, "state", "installed.build") |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1165 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1166 |
# Create the link forest in a temporary directory. We should |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1167 |
# only execute this method once (if ever) in the lifetime of an |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1168 |
# image, but if the path already exists and makedirs() blows up, |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1169 |
# just be quiet if it's already a directory. If it's not a |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1170 |
# directory or something else weird happens, re-raise. |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1171 |
try: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1172 |
os.makedirs(tmpdir) |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1173 |
except OSError, e: |
834
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1174 |
if e.errno == errno.EACCES: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1175 |
raise api_errors.PermissionsException( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1176 |
e.filename) |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1177 |
if e.errno != errno.EEXIST or \ |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1178 |
not os.path.isdir(tmpdir): |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1179 |
raise |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1180 |
return |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1181 |
|
834
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1182 |
proot = os.path.join(self.imgdir, "pkg") |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1183 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1184 |
for pd, vd in ( |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1185 |
(p, v) |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1186 |
for p in sorted(os.listdir(proot)) |
834
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1187 |
for v in sorted(os.listdir(os.path.join(proot, p))) |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1188 |
): |
834
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1189 |
path = os.path.join(proot, pd, vd, "installed") |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1190 |
if not os.path.exists(path): |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1191 |
continue |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1192 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1193 |
fmristr = urllib.unquote("%s@%s" % (pd, vd)) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1194 |
pub = self.installed_file_publisher(path) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1195 |
f = pkg.fmri.PkgFmri(fmristr, publisher = pub) |
834
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1196 |
fi = file(os.path.join(tmpdir, f.get_link_path()), "w") |
434
48c05c66cdd2
2595 List speedup changes don't work on Windows
Tom Mueller <Tom.Mueller@sun.com>
parents:
432
diff
changeset
|
1197 |
fi.close() |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1198 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1199 |
# Someone may have already created this directory. Junk the |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1200 |
# directory we just populated if that's the case. |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1201 |
try: |
834
f8b3396500b3
4883 import failure for non-sunos platforms due to missing pspawn
Tom Mueller <Tom.Mueller@sun.com>
parents:
792
diff
changeset
|
1202 |
portable.rename(tmpdir, statedir) |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1203 |
except EnvironmentError, e: |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1204 |
if e.errno != errno.EEXIST: |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1205 |
raise |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1206 |
shutil.rmtree(tmpdir) |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
1207 |
|
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
1208 |
def get_version_installed(self, pfmri): |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
1209 |
"""Returns an fmri of the installed package matching the |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
1210 |
package stem of the given fmri or None if no match is found.""" |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1211 |
|
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
1212 |
for f in self.gen_installed_pkgs(): |
568
52eea0be5030
3714 cannot uninstall package after authority removal
Danek Duvall <danek.duvall@sun.com>
parents:
567
diff
changeset
|
1213 |
if self.fmri_is_same_pkg(f, pfmri): |
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
1214 |
return f |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
1215 |
return None |
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
1216 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
1217 |
def get_pkg_state_by_fmri(self, pfmri): |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
1218 |
"""Given pfmri, determine the local state of the package.""" |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
1219 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1220 |
return self.__pkg_states.get(pfmri.get_fmri(anarchy = True)[5:], |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1221 |
(PKG_STATE_KNOWN, None))[0] |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
1222 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1223 |
def get_pkg_pub_by_fmri(self, pfmri): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1224 |
"""Return the publisher from which 'pfmri' was installed.""" |
423
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
1225 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1226 |
f = self.__pkg_states.get(pfmri.get_fmri(anarchy = True)[5:], |
423
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
1227 |
(PKG_STATE_KNOWN, None))[1] |
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
1228 |
if f: |
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
1229 |
# Return the non-preferred-prefixed name |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1230 |
return f.get_publisher() |
423
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
1231 |
return None |
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
1232 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1233 |
def fmri_set_default_publisher(self, fmri): |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1234 |
"""If the FMRI supplied as an argument does not have |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1235 |
a publisher, set it to the image's preferred publisher.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1236 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1237 |
if fmri.has_publisher(): |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1238 |
return |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1239 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1240 |
fmri.set_publisher(self.get_preferred_publisher(), True) |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1241 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1242 |
def get_catalog(self, fmri, exception = False): |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1243 |
"""Given a FMRI, look at the publisher and return the |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1244 |
correct catalog for this image.""" |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1245 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1246 |
# If FMRI has no publisher, or is default publisher, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1247 |
# then return the catalog for the preferred publisher |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1248 |
if not fmri.has_publisher() or fmri.preferred_publisher(): |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1249 |
cat = self.__catalogs[self.get_preferred_publisher()] |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1250 |
else: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1251 |
try: |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1252 |
cat = self.__catalogs[fmri.get_publisher()] |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1253 |
except KeyError: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1254 |
# If the publisher that installed this package |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1255 |
# has vanished, pick the default publisher |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1256 |
# instead. |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1257 |
if exception: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1258 |
raise |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1259 |
else: |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1260 |
cat = self.__catalogs[\ |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1261 |
self.get_preferred_publisher()] |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1262 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1263 |
return cat |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1264 |
|
135
a1e20e9a9845
add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents:
116
diff
changeset
|
1265 |
def has_version_installed(self, fmri): |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
1266 |
"""Check that the version given in the FMRI or a successor is |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1267 |
installed in the current image.""" |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1268 |
|
560
4c8d82d58131
3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents:
556
diff
changeset
|
1269 |
v = self.get_version_installed(fmri) |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
1270 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1271 |
if v and not fmri.has_publisher(): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1272 |
fmri.set_publisher(v.get_publisher_str()) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1273 |
elif not fmri.has_publisher(): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1274 |
fmri.set_publisher(self.get_preferred_publisher(), True) |
266
5e5bff6fedce
582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents:
260
diff
changeset
|
1275 |
|
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1276 |
if v and self.fmri_is_successor(v, fmri): |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1277 |
return True |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1278 |
else: |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1279 |
try: |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1280 |
cat = self.get_catalog(fmri, exception = True) |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1281 |
except KeyError: |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1282 |
return False |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
1283 |
|
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1284 |
# If fmri has been renamed, get the list of newer |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1285 |
# packages that are equivalent to fmri. |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1286 |
rpkgs = cat.rename_newer_pkgs(fmri) |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1287 |
for f in rpkgs: |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1288 |
|
560
4c8d82d58131
3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents:
556
diff
changeset
|
1289 |
v = self.get_version_installed(f) |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1290 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1291 |
if v and self.fmri_is_successor(v, fmri): |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1292 |
return True |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
1293 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
1294 |
return False |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
1295 |
|
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1296 |
def older_version_installed(self, fmri): |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1297 |
"""This method is used by the package plan to determine if an |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1298 |
older version of the package is installed. This takes |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1299 |
the destination fmri and checks if an older package exists. |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1300 |
This looks first under the existing name, and then sees |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1301 |
if an older version is installed under another name. This |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1302 |
allows upgrade correctly locate the src fmri, if one exists.""" |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1303 |
|
560
4c8d82d58131
3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents:
556
diff
changeset
|
1304 |
v = self.get_version_installed(fmri) |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1305 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1306 |
assert fmri.has_publisher() |
268
3d53da66d4a4
582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents:
266
diff
changeset
|
1307 |
|
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1308 |
if v: |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1309 |
return v |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1310 |
else: |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1311 |
cat = self.get_catalog(fmri) |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1312 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1313 |
rpkgs = cat.rename_older_pkgs(fmri) |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1314 |
for f in rpkgs: |
560
4c8d82d58131
3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents:
556
diff
changeset
|
1315 |
v = self.get_version_installed(f) |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1316 |
if v and self.fmri_is_successor(fmri, v): |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1317 |
return v |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1318 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1319 |
return None |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1320 |
|
135
a1e20e9a9845
add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents:
116
diff
changeset
|
1321 |
def is_installed(self, fmri): |
a1e20e9a9845
add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents:
116
diff
changeset
|
1322 |
"""Check that the exact version given in the FMRI is installed |
a1e20e9a9845
add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents:
116
diff
changeset
|
1323 |
in the current image.""" |
a1e20e9a9845
add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents:
116
diff
changeset
|
1324 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1325 |
# All FMRIs passed to is_installed shall have a publisher |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1326 |
assert fmri.has_publisher() |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
1327 |
|
560
4c8d82d58131
3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents:
556
diff
changeset
|
1328 |
v = self.get_version_installed(fmri) |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1329 |
if not v: |
135
a1e20e9a9845
add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents:
116
diff
changeset
|
1330 |
return False |
a1e20e9a9845
add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents:
116
diff
changeset
|
1331 |
|
a1e20e9a9845
add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents:
116
diff
changeset
|
1332 |
return v == fmri |
a1e20e9a9845
add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents:
116
diff
changeset
|
1333 |
|
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
1334 |
def list_excludes(self, new_variants=None): |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1335 |
"""Generate a list of callables that each return True if an |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1336 |
action is to be included in the image using the currently |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1337 |
defined variants for the image, or an updated set if |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1338 |
new_variants are specified. The callables take a single action |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1339 |
argument. Variants, facets and filters will be handled in |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1340 |
this fashion.""" |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
1341 |
|
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
1342 |
# XXX simple for now; facets and filters need impl. |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
1343 |
if new_variants: |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
1344 |
new_vars = self.cfg_cache.variants.copy() |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
1345 |
new_vars.update(new_variants) |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
1346 |
return [new_vars.allow_action] |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
1347 |
else: |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
1348 |
return [self.cfg_cache.variants.allow_action] |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
1349 |
|
432
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1350 |
def __build_dependents(self, progtrack): |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1351 |
"""Build a dictionary mapping packages to the list of packages |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1352 |
that have required dependencies on them.""" |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
1353 |
|
432
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1354 |
self.__req_dependents = {} |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1355 |
|
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1356 |
for fmri in self.gen_installed_pkgs(): |
577
cd4e8df4322b
873 Text is wrong in the General Info tab
Michal Pryc <Michal.Pryc@Sun.Com>
parents:
576
diff
changeset
|
1357 |
progtrack.evaluate_progress(fmri) |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
1358 |
mfst = self.get_manifest(fmri) |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
1359 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1360 |
for dep in mfst.gen_actions_by_type("depend", |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
1361 |
self.list_excludes()): |
432
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1362 |
if dep.attrs["type"] != "require": |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1363 |
continue |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1364 |
dfmri = self.strtofmri(dep.attrs["fmri"]) |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1365 |
if dfmri not in self.__req_dependents: |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1366 |
self.__req_dependents[dfmri] = [] |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1367 |
self.__req_dependents[dfmri].append(fmri) |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1368 |
|
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1369 |
def get_dependents(self, pfmri, progtrack): |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
1370 |
"""Return a list of the packages directly dependent on the given |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
1371 |
FMRI.""" |
67
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
1372 |
|
432
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1373 |
if not hasattr(self, "_Image__req_dependents"): |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1374 |
self.__build_dependents(progtrack) |
67
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
1375 |
|
432
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1376 |
dependents = [] |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1377 |
# We run through all the keys, in case a package is depended |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1378 |
# upon under multiple versions. That is, if pkgA depends on |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1379 |
# libc@1 and pkgB depends on libc@2, we need to return both pkgA |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1380 |
# and pkgB. If we used package names as keys, this would be |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1381 |
# simpler, but it wouldn't handle package rename. |
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1382 |
for f in self.__req_dependents.iterkeys(): |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
1383 |
if self.fmri_is_successor(pfmri, f): |
432
578875da6e04
48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents:
429
diff
changeset
|
1384 |
dependents.extend(self.__req_dependents[f]) |
67
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
1385 |
return dependents |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
1386 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1387 |
def __do_get_versions(self, pub): |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1388 |
"""An internal method that is a wrapper around get_catalog. |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1389 |
This handles retryable exceptions and timeouts.""" |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1390 |
|
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1391 |
retry_count = global_settings.PKG_TIMEOUT_MAX |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1392 |
failures = TransportFailures() |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1393 |
versdict = None |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1394 |
|
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1395 |
while not versdict: |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1396 |
try: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1397 |
versdict = retrieve.get_versions(self, pub) |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1398 |
except TransportException, e: |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1399 |
retry_count -= 1 |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1400 |
failures.append(e) |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1401 |
|
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1402 |
if retry_count <= 0: |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1403 |
raise failures |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1404 |
|
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1405 |
return versdict |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1406 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1407 |
def valid_publisher_test(self, pub): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1408 |
"""Test that the publisher supplied in pub actually |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1409 |
points to a valid packaging server.""" |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1410 |
|
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1411 |
try: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1412 |
vd = self.__do_get_versions(pub) |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1413 |
except (retrieve.VersionRetrievalError, |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1414 |
TransportFailures), e: |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1415 |
# Failure when contacting server. Report |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1416 |
# this as an error. |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1417 |
raise InvalidDepotResponseException(pub["origin"], |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1418 |
"Transport errors encountered when trying to " |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1419 |
"contact depot server. Reported the following " |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1420 |
"errors:\n%s" % e) |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1421 |
|
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1422 |
if not self._valid_versions_test(vd): |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1423 |
raise InvalidDepotResponseException(pub["origin"], |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1424 |
"Invalid or unparseable version information.") |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1425 |
|
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1426 |
def captive_portal_test(self, pubs=None): |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1427 |
"""A captive portal forces a HTTP client on a network to see a |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1428 |
special web page, usually for pubentication purposes |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1429 |
(http://en.wikipedia.org/wiki/Captive_portal). |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1430 |
|
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1431 |
'pubs' is an optional list of publisher objects to be used for |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1432 |
the check. If not provided, any publishers available for |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1433 |
packaging operations will be used for the test instead.""" |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1434 |
|
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1435 |
if not pubs: |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1436 |
pubs = list(self.gen_publishers()) |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1437 |
|
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1438 |
vd = None |
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1439 |
for pub in pubs: |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1440 |
try: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1441 |
vd = self.__do_get_versions(pub) |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1442 |
except (retrieve.VersionRetrievalError, |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1443 |
TransportFailures): |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1444 |
# Encountered a transport error while |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1445 |
# trying to contact this publisher. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1446 |
# Pick another publisher instead. |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1447 |
continue |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1448 |
|
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1449 |
if self._valid_versions_test(vd): |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1450 |
return |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1451 |
else: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1452 |
raise InvalidDepotResponseException( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1453 |
pub["origin"], _("This server is not a " |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1454 |
"valid package depot.")) |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1455 |
if not vd: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1456 |
# We got all the way through the list of puborites but |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1457 |
# encountered transport errors in every case. This is |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1458 |
# likely a network configuration problem. Report our |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1459 |
# inability to contact a server. |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1460 |
raise InvalidDepotResponseException(None, |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1461 |
"Unable to contact any configured publishers. " |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1462 |
"This is likely a network configuration problem.") |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1463 |
|
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1464 |
@staticmethod |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1465 |
def _valid_versions_test(versdict): |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1466 |
"""Check that the versions information contained in |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1467 |
versdict contains valid version specifications. |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1468 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1469 |
In order to test for this condition, pick a publisher |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1470 |
from the list of active publishers. Check to see if |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1471 |
we can connect to it. If so, test to see if it supports |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1472 |
the versions/0 operations. If versions/0 is not found, |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1473 |
we get an unparseable response, or the response does |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1474 |
not contain pkg-server, or versions 0 then we're not |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1475 |
talking to a depot. Return an error in these cases.""" |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1476 |
|
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1477 |
if "pkg-server" in versdict: |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1478 |
# success! |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1479 |
return True |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1480 |
elif "versions" in versdict: |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1481 |
try: |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1482 |
versids = [ |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1483 |
int(v) |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1484 |
for v in versdict["versions"].split() |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1485 |
] |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1486 |
except ValueError: |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1487 |
# Unable to determine version number. Fail. |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1488 |
return False |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1489 |
|
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1490 |
if 0 not in versids: |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1491 |
# Paranoia. versions 0 should be in the |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1492 |
# output for versions/0. If we're here, |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1493 |
# something has gone very wrong. EPIC FAIL! |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1494 |
return False |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1495 |
|
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1496 |
# found versions/0, success! |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1497 |
return True |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1498 |
|
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1499 |
# Some other error encountered. Fail |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1500 |
return False |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1501 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1502 |
def _do_get_catalog(self, pub, hdr, ts): |
621
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1503 |
"""An internal method that is a wrapper around get_catalog. |
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1504 |
This handles retryable exceptions and timeouts.""" |
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1505 |
|
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1506 |
retry_count = global_settings.PKG_TIMEOUT_MAX |
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1507 |
failures = TransportFailures() |
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1508 |
success = False |
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1509 |
|
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1510 |
while not success: |
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1511 |
try: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1512 |
success = retrieve.get_catalog(self, pub, |
621
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1513 |
hdr, ts) |
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1514 |
except TransportException, e: |
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1515 |
retry_count -= 1 |
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1516 |
failures.append(e) |
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1517 |
|
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1518 |
if retry_count <= 0: |
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1519 |
raise failures |
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1520 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1521 |
def refresh_publishers(self, full_refresh=False, immediate=False, |
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1522 |
pubs=None, progtrack=None, validate=True): |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1523 |
"""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:
993
diff
changeset
|
1524 |
publishers. |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1525 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1526 |
'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:
993
diff
changeset
|
1527 |
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:
993
diff
changeset
|
1528 |
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:
993
diff
changeset
|
1529 |
True, 'immediate' is also set to True. |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1530 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1531 |
'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:
993
diff
changeset
|
1532 |
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:
993
diff
changeset
|
1533 |
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:
993
diff
changeset
|
1534 |
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:
993
diff
changeset
|
1535 |
exceeded; ignored when 'full_refresh' is True. |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1536 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1537 |
'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:
993
diff
changeset
|
1538 |
to refresh. Passing an empty list or using the default value |
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1539 |
implies all publishers. |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1540 |
|
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1541 |
'validate' is an optional, boolean value indicating whether a |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1542 |
connectivity test should be performed before attempting to |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1543 |
retrieve publisher metadata.""" |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1544 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1545 |
if full_refresh: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1546 |
immediate = True |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1547 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1548 |
if not progtrack: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1549 |
progtrack = progress.QuietProgressTracker() |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1550 |
|
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1551 |
self.history.log_operation_start("refresh-publishers") |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1552 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1553 |
# Verify validity of certificates before attempting network |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1554 |
# operations. |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1555 |
try: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1556 |
self.check_cert_validity() |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1557 |
except api_errors.ExpiringCertificate, e: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1558 |
# XXX need client messaging framework |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1559 |
misc.emsg(e) |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1560 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1561 |
pubs_to_refresh = [] |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1562 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1563 |
if not pubs: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1564 |
# Omit disabled publishers. |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1565 |
pubs = [p for p in self.gen_publishers()] |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1566 |
for pub in pubs: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1567 |
p = pub |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1568 |
if not isinstance(p, publisher.Publisher): |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1569 |
p = self.get_publisher(prefix=p) |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1570 |
if p.disabled: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1571 |
e = api_errors.DisabledPublisher(p) |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1572 |
self.history.log_operation_end(error=e) |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1573 |
raise e |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1574 |
if immediate or p.needs_refresh: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1575 |
pubs_to_refresh.append(p) |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1576 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1577 |
if not pubs_to_refresh: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1578 |
# Trigger a load of the catalogs if they haven't been |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1579 |
# loaded yet for the sake of our caller. |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1580 |
self.load_catalogs(progtrack) |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1581 |
self.history.log_operation_end() |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1582 |
return |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1583 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1584 |
try: |
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1585 |
if validate: |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1586 |
# Before an attempt is made to retrieve catalogs |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1587 |
# from the publisher repositories, a check needs |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1588 |
# to be done to ensure that the client isn't |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1589 |
# stuck behind a captive portal. |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1590 |
self.captive_portal_test() |
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1591 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1592 |
self.__retrieve_catalogs(full_refresh=full_refresh, |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1593 |
pubs=pubs_to_refresh, progtrack=progtrack) |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1594 |
except (api_errors.ApiException, catalog.CatalogException), e: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1595 |
# Reload catalogs; this picks up any updates and |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1596 |
# ensures the catalog is loaded for callers. |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1597 |
self.load_catalogs(progtrack, force=True) |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1598 |
self.history.log_operation_end(error=e) |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1599 |
raise |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1600 |
self.history.log_operation_end() |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1601 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1602 |
def __retrieve_catalogs(self, full_refresh=False, pubs=None, |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1603 |
progtrack=None): |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1604 |
"""Retrieves the catalogs for the specified publishers |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1605 |
performing full or incremental updates as needed or indicated. |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1606 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1607 |
'full_refresh' is a boolean value indicating whether a full |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1608 |
update should be forced for the specified publishers. |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1609 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1610 |
'pubs' is an optional list of publisher objects to refresh the |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1611 |
metadata for. If not provided or 'None', all publishers will be |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1612 |
refreshed. Disabled publishers are always ignored regardless of |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1613 |
whether this list is provided. |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1614 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1615 |
'progtrack' is an optional ProgressTracker object.""" |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1616 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1617 |
if not progtrack: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1618 |
progtrack = progress.QuietProgressTracker() |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1619 |
|
201
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
1620 |
failed = [] |
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
1621 |
total = 0 |
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
1622 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1623 |
if not pubs: |
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1624 |
pubs = list(self.gen_publishers()) |
625
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
621
diff
changeset
|
1625 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1626 |
try: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1627 |
# Ensure Image directory structure is valid. |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1628 |
self.mkdirs() |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1629 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1630 |
# Load the catalogs, if they haven't been already, so |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1631 |
# incremental updates can be performed. |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1632 |
self.load_catalogs(progtrack) |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1633 |
except EnvironmentError, e: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1634 |
self.history.log_operation_end(error=e) |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1635 |
raise |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1636 |
|
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1637 |
progtrack.refresh_start(len(pubs)) |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1638 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1639 |
def catalog_changed(prefix, old_ts, old_size): |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1640 |
if not old_ts or not old_size: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1641 |
# It didn't exist before. |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1642 |
return True |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1643 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1644 |
croot = "%s/catalog/%s" % (self.imgdir, prefix) |
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1645 |
c = catalog.Catalog(croot, publisher=prefix) |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1646 |
if c.last_modified() != old_ts: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1647 |
return True |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1648 |
if c.size() != old_size: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1649 |
return True |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1650 |
return False |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1651 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1652 |
updated = 0 |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1653 |
succeeded = 0 |
1102
5ea5cdb4360d
5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents:
1087
diff
changeset
|
1654 |
for pub in pubs: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1655 |
if pub.disabled: |
786
a400f8c4d1c0
2340 support authority enable and disable
Tom Mueller <Tom.Mueller@sun.com>
parents:
756
diff
changeset
|
1656 |
continue |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1657 |
|
201
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
1658 |
total += 1 |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1659 |
progtrack.refresh_progress(pub.prefix) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1660 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1661 |
full_refresh_this_pub = False |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1662 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1663 |
cat = None |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1664 |
ts = 0 |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1665 |
size = 0 |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1666 |
if pub.prefix in self.__catalogs: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1667 |
cat = self.__catalogs[pub.prefix] |
215
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
1668 |
ts = cat.last_modified() |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1669 |
size = cat.size() |
215
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
1670 |
|
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
1671 |
# Although we may have a catalog with a |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
1672 |
# timestamp, the user may have changed the |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1673 |
# origin URL for the publisher. If this has |
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
1674 |
# occurred, we need to perform a full refresh. |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1675 |
repo = pub.selected_repository |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1676 |
if cat.origin() not in repo.origins: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1677 |
full_refresh_this_pub = True |
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
1678 |
|
496
d36d6700c011
2917 pkg refresh should allow refreshing specific repository(ies)
Brock Pytlik <bpytlik@sun.com>
parents:
479
diff
changeset
|
1679 |
if ts and not full_refresh and \ |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1680 |
not full_refresh_this_pub: |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1681 |
hdr = {"If-Modified-Since": ts} |
215
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
1682 |
else: |
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
1683 |
hdr = {} |
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
1684 |
|
235
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
1685 |
try: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1686 |
self._do_get_catalog(pub, hdr, ts) |
621
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1687 |
except retrieve.CatalogRetrievalError, e: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1688 |
failed.append((pub, e)) |
621
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
616
diff
changeset
|
1689 |
except TransportFailures, e: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1690 |
failed.append((pub, e)) |
201
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
1691 |
else: |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1692 |
if catalog_changed(pub.prefix, ts, size): |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1693 |
updated += 1 |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1694 |
pub.last_refreshed = dt.datetime.utcnow() |
201
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
1695 |
succeeded += 1 |
243
ca57127811b8
399 pkg list on explicit packages fails with no output, exit status of 1
Stephen Hahn <sch@Sun.COM>
parents:
239
diff
changeset
|
1696 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1697 |
if updated > 0: |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1698 |
# If any publisher metadata was changed, then destroy |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1699 |
# the catalog cache, update the installed package list, |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1700 |
# and force a reload of all catalog data. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1701 |
self.__destroy_catalog_cache() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1702 |
self.__update_installed_pkgs() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1703 |
self.load_catalogs(progtrack, force=True) |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1704 |
|
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1705 |
progtrack.refresh_done() |
625
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
621
diff
changeset
|
1706 |
|
201
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
1707 |
if failed: |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
1708 |
raise api_errors.CatalogRefreshException(failed, total, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
1709 |
succeeded) |
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
1710 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1711 |
return updated > 0 |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
1712 |
|
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1713 |
CATALOG_CACHE_VERSION = 4 |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1714 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1715 |
def __cache_catalogs(self, progtrack, pubs=None): |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1716 |
"""Read in all the catalogs and cache the data. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1717 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1718 |
'pubs' is a list of publisher objects to include when caching |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1719 |
the image's configured publisher metadata. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1720 |
""" |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1721 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1722 |
progtrack.cache_catalogs_start() |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1723 |
cache = {} |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1724 |
publist = [] |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1725 |
|
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1726 |
try: |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1727 |
publist = dict( |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1728 |
(p.prefix, p) for p in self.gen_publishers() |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1729 |
) |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1730 |
except CfgCacheError: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1731 |
# No publishers defined. If the caller hasn't |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1732 |
# supplied publishers to cache, raise the error |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1733 |
if not pubs: |
835
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1734 |
raise |
34ec4401dc48
686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents:
834
diff
changeset
|
1735 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1736 |
if pubs: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
1737 |
# If caller passed publishers, include this in |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1738 |
# the list of publishers to cache. These might |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1739 |
# be publisher objects that haven't been added |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1740 |
# to the image configuration yet. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1741 |
for p in pubs: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1742 |
publist[p.prefix] = p |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1743 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1744 |
for pub in publist.itervalues(): |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1745 |
try: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1746 |
catalog.Catalog.read_catalog(cache, |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1747 |
pub.meta_root, pub=pub.prefix) |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1748 |
except EnvironmentError, e: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1749 |
# If a catalog file is just missing, ignore it. |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1750 |
# If there's a worse error, make sure the user |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1751 |
# knows about it. |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1752 |
if e.errno == errno.ENOENT: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1753 |
pass |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1754 |
else: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1755 |
raise |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1756 |
|
723
35192419888d
4447 A corrupt(?) catalog.pkl renders pkg(5) unusable.
Danek Duvall <danek.duvall@sun.com>
parents:
717
diff
changeset
|
1757 |
self._catalog = cache |
35192419888d
4447 A corrupt(?) catalog.pkl renders pkg(5) unusable.
Danek Duvall <danek.duvall@sun.com>
parents:
717
diff
changeset
|
1758 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1759 |
# Use the current time until the actual file timestamp can be |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1760 |
# retrieved at the end. That way, if an exception is raised |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1761 |
# or an early return occurs, it will still be set. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1762 |
self.__catalog_cache_mod_time = int(time.time()) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1763 |
|
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1764 |
# Remove old catalog cache files. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1765 |
croot = os.path.join(self.imgdir, "catalog") |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1766 |
for fname in ("pkg_names.pkl", "catalog.pkl"): |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1767 |
fpath = os.path.join(croot, fname) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1768 |
try: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1769 |
portable.remove(fpath) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1770 |
except KeyboardInterrupt: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1771 |
raise |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1772 |
except: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1773 |
# If for any reason, the file can't be removed, |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1774 |
# it doesn't matter. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1775 |
pass |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1776 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1777 |
try: |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1778 |
cfd, ctmp = tempfile.mkstemp(dir=croot) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1779 |
cf = os.fdopen(cfd, "wb") |
723
35192419888d
4447 A corrupt(?) catalog.pkl renders pkg(5) unusable.
Danek Duvall <danek.duvall@sun.com>
parents:
717
diff
changeset
|
1780 |
except EnvironmentError: |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1781 |
# If the cache can't be written, it doesn't matter. |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1782 |
progtrack.cache_catalogs_done() |
723
35192419888d
4447 A corrupt(?) catalog.pkl renders pkg(5) unusable.
Danek Duvall <danek.duvall@sun.com>
parents:
717
diff
changeset
|
1783 |
return |
35192419888d
4447 A corrupt(?) catalog.pkl renders pkg(5) unusable.
Danek Duvall <danek.duvall@sun.com>
parents:
717
diff
changeset
|
1784 |
|
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1785 |
def cleanup(): |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1786 |
try: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1787 |
if cf: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1788 |
cf.close() |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1789 |
except EnvironmentError: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1790 |
pass |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1791 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1792 |
try: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1793 |
portable.remove(ctmp) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1794 |
except EnvironmentError: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1795 |
pass |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1796 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1797 |
# First, the list of all publishers is built assigning each |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1798 |
# one a sequentially incremented integer as they are discovered. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1799 |
# This number is used as a mapping code for publishers to reduce |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1800 |
# the size of the catalog cache. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1801 |
pubs = {} |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1802 |
for pkg_name in cache: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1803 |
vers = cache[pkg_name] |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1804 |
for k, v in vers.iteritems(): |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1805 |
if k == "versions": |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1806 |
continue |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1807 |
for p in v[1]: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1808 |
if p not in pubs: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1809 |
pubs[p] = str(len(pubs)) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1810 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1811 |
# '|' is used to separate fields of information (such |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1812 |
# as fmri name and each version). |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1813 |
# '!' is used to separate items within a field (such as |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1814 |
# information about a version). |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1815 |
# '^' is used to separate item values (such as a publisher and |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1816 |
# its index number). |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1817 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1818 |
# First line of file is the version of the catalog cache. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1819 |
try: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1820 |
cf.write("%s\n" % self.CATALOG_CACHE_VERSION) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1821 |
except EnvironmentError: |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1822 |
# If the cache can't be written, it doesn't matter. |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1823 |
cleanup() |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1824 |
progtrack.cache_catalogs_done() |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1825 |
return |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1826 |
except: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1827 |
cleanup() |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1828 |
raise |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1829 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1830 |
# Second line of the file is the list of publisher prefixes |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1831 |
# and their index number used to decode the fmri entries. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1832 |
publine = "!".join([ |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1833 |
"^".join((p, pubs[p])) for p in pubs |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1834 |
]) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1835 |
|
723
35192419888d
4447 A corrupt(?) catalog.pkl renders pkg(5) unusable.
Danek Duvall <danek.duvall@sun.com>
parents:
717
diff
changeset
|
1836 |
try: |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1837 |
cf.write("%s\n" % publine) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1838 |
except EnvironmentError: |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1839 |
# If the cache can't be written, it doesn't matter. |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1840 |
cleanup() |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1841 |
progtrack.cache_catalogs_done() |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1842 |
return |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1843 |
except: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1844 |
cleanup() |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1845 |
raise |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1846 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1847 |
# All lines after the first two are made up of a package's |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1848 |
# version-specific fmri and the list of publishers that have |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1849 |
# it in their catalog, or where it was installed from. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1850 |
for pkg_name in sorted(cache.keys()): |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1851 |
vers = cache[pkg_name] |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1852 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1853 |
# Iteration has to be performed over versions to retain |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1854 |
# sort order. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1855 |
first = True |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1856 |
release = None |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1857 |
build_release = None |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1858 |
branch = None |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1859 |
for v in vers["versions"]: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1860 |
f, fpubs = vers[str(v)] |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1861 |
known = "^".join( |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1862 |
pubs[p] for p in fpubs |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1863 |
if fpubs[p] |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1864 |
) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1865 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1866 |
unknown = "^".join( |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1867 |
pubs[p] for p in fpubs |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1868 |
if not fpubs[p] |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1869 |
) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1870 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1871 |
if first: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1872 |
# When writing the first entry for a |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1873 |
# package, write its full fmri. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1874 |
first = False |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1875 |
release = f.version.release |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1876 |
build_release = f.version.build_release |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1877 |
branch = f.version.branch |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1878 |
sfmri = f.get_fmri(anarchy=True, |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1879 |
include_scheme=False) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1880 |
else: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1881 |
# For successive entries, write only |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1882 |
# what is not shared by the previous |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1883 |
# entry. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1884 |
rmatch = f.version.release == release |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1885 |
brmatch = f.version.build_release == \ |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1886 |
build_release |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1887 |
bmatch = f.version.branch == branch |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1888 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1889 |
sver = str(f.version) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1890 |
if rmatch and brmatch and bmatch: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1891 |
# If release, build_release, and |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1892 |
# branch match the last entry, |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1893 |
# they can be omitted. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1894 |
sfmri = ":" + sver.split(":")[1] |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1895 |
elif rmatch and brmatch: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1896 |
# If release and build_release |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1897 |
# match the last entry, they can |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1898 |
# be omitted. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1899 |
sfmri = "-" + sver.split("-")[1] |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1900 |
elif rmatch: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1901 |
# If release matches the last |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1902 |
# entry, it can be omitted. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1903 |
sfmri = "," + sver.split(",")[1] |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1904 |
else: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1905 |
# Nothing matched the previous |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1906 |
# entry except the name, so the |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1907 |
# full version must be written. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1908 |
sfmri = "@" + sver |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1909 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1910 |
release = f.version.release |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1911 |
build_release = f.version.build_release |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1912 |
branch = f.version.branch |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1913 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1914 |
line = sfmri + "|" + known + "!" + unknown |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1915 |
try: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1916 |
cf.write(line + "\n") |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1917 |
except EnvironmentError: |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1918 |
# If the cache can't be written, it |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1919 |
# doesn't matter. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1920 |
progtrack.cache_catalogs_done() |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1921 |
cleanup() |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1922 |
return |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1923 |
except: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1924 |
cleanup() |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1925 |
raise |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1926 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1927 |
cfpath = os.path.join(croot, CATALOG_CACHE_FILE) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1928 |
try: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1929 |
cf.close() |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1930 |
cf = None |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1931 |
os.chmod(ctmp, 0644) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1932 |
portable.rename(ctmp, cfpath) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1933 |
except EnvironmentError: |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1934 |
# If the cache can't be written, it doesn't matter. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1935 |
progtrack.cache_catalogs_done() |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1936 |
cleanup() |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1937 |
return |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1938 |
except: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1939 |
cleanup() |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1940 |
raise |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1941 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1942 |
# Update the mod time with the actual timestamp from the file. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1943 |
self.__catalog_cache_mod_time = \ |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1944 |
self.__get_catalog_cache_mod_time() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1945 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1946 |
progtrack.cache_catalogs_done() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1947 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1948 |
def __get_catalog_cache_mod_time(self): |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1949 |
"""Internal helper function used to obtain last modification |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1950 |
time of the on-disk catalog cache.""" |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1951 |
|
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1952 |
croot = os.path.join(self.imgdir, "catalog") |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
1953 |
cache_file = os.path.join(croot, CATALOG_CACHE_FILE) |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
1954 |
try: |
715
5620652f5927
4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents:
703
diff
changeset
|
1955 |
mod_time = os.stat(cache_file).st_mtime |
5620652f5927
4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents:
703
diff
changeset
|
1956 |
except EnvironmentError, e: |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1957 |
if e.errno == errno.EACCES: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1958 |
raise api_errors.PermissionsException( |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1959 |
e.filename) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1960 |
if e.errno != errno.ENOENT: |
715
5620652f5927
4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents:
703
diff
changeset
|
1961 |
raise |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1962 |
mod_time = None |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1963 |
return mod_time |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1964 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1965 |
def __load_catalog_cache(self, progtrack): |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1966 |
"""Read in the cached catalog data.""" |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1967 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1968 |
progtrack.load_catalog_cache_start() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1969 |
croot = os.path.join(self.imgdir, "catalog") |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1970 |
cache_file = os.path.join(croot, CATALOG_CACHE_FILE) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1971 |
mod_time = self.__get_catalog_cache_mod_time() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1972 |
if self._catalog: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1973 |
if mod_time == self.__catalog_cache_mod_time: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1974 |
# Cache already loaded and up to date. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1975 |
progtrack.load_catalog_cache_done() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1976 |
return |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1977 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1978 |
try: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1979 |
cf = file(cache_file, "rb") |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1980 |
except EnvironmentError, e: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1981 |
self._catalog = {} |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1982 |
self.__catalog_cache_mod_time = None |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1983 |
if e.errno == errno.EACCES: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1984 |
raise api_errors.PermissionsException( |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1985 |
e.filename) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1986 |
if e.errno == errno.ENOENT: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1987 |
raise api_errors.CatalogCacheMissing() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1988 |
raise |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1989 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1990 |
# First line should be version. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1991 |
try: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1992 |
ver = cf.readline().strip() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1993 |
ver = int(ver) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1994 |
except ValueError: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1995 |
ver = None |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1996 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1997 |
# If we don't recognize the version, complain. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1998 |
if ver != self.CATALOG_CACHE_VERSION: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
1999 |
raise api_errors.CatalogCacheBadVersion( |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2000 |
ver, expected=self.CATALOG_CACHE_VERSION) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2001 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2002 |
# Second line should be the list of publishers. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2003 |
publine = cf.readline().strip() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2004 |
if not publine: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2005 |
publine = "" |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2006 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2007 |
pubidx = {} |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2008 |
for e in publine.split("!"): |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2009 |
try: |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2010 |
p, idx = e.split("^") |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2011 |
except ValueError: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2012 |
raise api_errors.CatalogCacheInvalid( |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2013 |
publine, line_number=2) |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2014 |
pubidx[idx] = p |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2015 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2016 |
if not pubidx: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2017 |
raise api_errors.CatalogCacheInvalid( |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2018 |
publine, line_number=2) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2019 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2020 |
self._catalog = {} |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2021 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2022 |
# Read until EOF. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2023 |
pkg_name = None |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2024 |
sver = None |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2025 |
for lnum, line in ((i + 3, l.strip()) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2026 |
for i, l in enumerate(cf)): |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2027 |
# The first of these line for each package is of |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2028 |
# the format: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2029 |
# fmri|pub1_known^pub2...!pub1_unknown^pub2... |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2030 |
# |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2031 |
# Successive versions of the same package are of |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2032 |
# the format: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2033 |
# @ver|pub1_known^pub2...!pub1_unknown^pub2... |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2034 |
try: |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2035 |
sfmri, spubs = line.split("|", 1) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2036 |
sfmri = sfmri.strip() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2037 |
except (AttributeError, ValueError): |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2038 |
raise api_errors.CatalogCacheInvalid( |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2039 |
line, line_number=lnum) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2040 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2041 |
if sfmri[0] in (":", "-", ",", "@") and \ |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2042 |
not pkg_name: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2043 |
# The previous line should have been a |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2044 |
# full fmri or provided enough info |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2045 |
# to construct one for this entry. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2046 |
raise api_errors.CatalogCacheInvalid( |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2047 |
line, line_number=lnum) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2048 |
elif sfmri[0] == ":": |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2049 |
# Everything but the timestamp is the |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2050 |
# same as the previous entry. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2051 |
sfmri = "%s@%s%s" % (pkg_name, |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2052 |
sver.split(":")[0], sfmri) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2053 |
elif sfmri[0] == "-": |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2054 |
# Everything but the branch is the same |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2055 |
# as the previous entry. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2056 |
sfmri = "%s@%s%s" % (pkg_name, |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2057 |
sver.split("-")[0], sfmri) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2058 |
elif sfmri[0] == ",": |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2059 |
# Everything but the release is the same |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2060 |
# as the previous entry. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2061 |
sfmri = "%s@%s%s" % (pkg_name, |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2062 |
sver.split(",")[0], sfmri) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2063 |
elif sfmri[0] == "@": |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2064 |
# If the entry starts with this, then |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2065 |
# only the package name is shared. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2066 |
sfmri = pkg_name + sfmri |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2067 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2068 |
known, unknown = spubs.split("!") |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2069 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2070 |
# Transform the publisher index numbers into |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2071 |
# their equivalent prefixes. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2072 |
pubs = {} |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2073 |
for k in known.split("^"): |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2074 |
if k in pubidx: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2075 |
pubs[pubidx[k]] = True |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2076 |
for u in unknown.split("^"): |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2077 |
if u in pubidx: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2078 |
pubs[pubidx[u]] = False |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2079 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2080 |
if not pubs: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2081 |
raise api_errors.CatalogCacheInvalid( |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2082 |
line, line_number=lnum) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2083 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2084 |
# Build the FMRI from the provided string and |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2085 |
# cache the result using the publisher info. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2086 |
try: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2087 |
pfmri = pkg.fmri.PkgFmri(sfmri) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2088 |
pkg_name = pfmri.pkg_name |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2089 |
sver = sfmri.split("@", 1)[1] |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2090 |
except (pkg.fmri.FmriError, IndexError), e: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2091 |
raise api_errors.CatalogCacheInvalid( |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2092 |
line, line_number=lnum) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2093 |
catalog.Catalog.fast_cache_fmri(self._catalog, |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2094 |
pfmri, sver, pubs) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2095 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2096 |
try: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2097 |
cf.close() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2098 |
except EnvironmentError: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2099 |
# All of the data was retrieved, so this error |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2100 |
# doesn't matter. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2101 |
pass |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2102 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2103 |
# Now that all of the data has been loaded, set the |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2104 |
# modification time. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2105 |
self.__catalog_cache_mod_time = mod_time |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2106 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2107 |
progtrack.load_catalog_cache_done() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2108 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2109 |
def load_catalogs(self, progtrack, force=False): |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2110 |
"""Load publisher catalog data. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2111 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2112 |
'progtrack' should be a ProgressTracker object that will be used |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2113 |
to provide progress information to clients. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2114 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2115 |
'force' is an optional, boolean value that, when 'True', will |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2116 |
cause the publisher catalog data to be loaded again even if it |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2117 |
has been already. It defaults to 'False', which will cause the |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2118 |
catalog data to only be loaded when not already loaded or when |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2119 |
the catalog cache has been modified (which should only happen in |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2120 |
the case of another process modifying it).""" |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2121 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2122 |
if not force and self.__catalogs and \ |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2123 |
self.__pkg_states is not None: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2124 |
last_mod_time = self.__catalog_cache_mod_time |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2125 |
if last_mod_time: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2126 |
mod_time = self.__get_catalog_cache_mod_time() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2127 |
if mod_time == last_mod_time: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2128 |
# Don't load the catalogs as they are |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2129 |
# already loaded and state information |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2130 |
# is up to date. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2131 |
return |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2132 |
elif not mod_time: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2133 |
# Don't load the catalogs since no cache |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2134 |
# exists on-disk but an in-memory one |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2135 |
# does. This can happen for |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2136 |
# unprivileged users, or in a readonly |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2137 |
# environment such as a Live CD where |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2138 |
# the cache does not exist for space |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2139 |
# or other reasons. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2140 |
return |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2141 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2142 |
assert progtrack |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2143 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2144 |
# Flush existing catalog data. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2145 |
self.__catalogs = {} |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
2146 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2147 |
for pub in self.gen_publishers(): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2148 |
croot = "%s/catalog/%s" % (self.imgdir, pub.prefix) |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2149 |
progtrack.catalog_start(pub.prefix) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2150 |
if pub.prefix == self.cfg_cache.preferred_publisher: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2151 |
pubpfx = "%s_%s" % (pkg.fmri.PREF_PUB_PFX, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2152 |
pub.prefix) |
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2153 |
c = catalog.Catalog(croot, |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2154 |
publisher=pubpfx) |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2155 |
else: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2156 |
c = catalog.Catalog(croot, |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2157 |
publisher=pub.prefix) |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2158 |
self.__catalogs[pub.prefix] = c |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2159 |
progtrack.catalog_done() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2160 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2161 |
# Load package state information as this will be used during |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2162 |
# catalog cache generation. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2163 |
self.__load_pkg_states() |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
2164 |
|
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2165 |
# Try to load the catalog cache file. If that fails, call |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2166 |
# cache_catalogs so that the data from the canonical text copies |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2167 |
# of the catalogs from each publisher will be loaded and the |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2168 |
# data cached. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2169 |
# |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2170 |
# XXX Given that this is a read operation, should we be writing? |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2171 |
try: |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2172 |
self.__load_catalog_cache(progtrack) |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2173 |
except api_errors.CatalogCacheError: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2174 |
# If the load failed because of a bad version, |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2175 |
# corruption, or because it was missing, just try to |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2176 |
# rebuild it automatically. |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2177 |
self.__cache_catalogs(progtrack) |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2178 |
|
715
5620652f5927
4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents:
703
diff
changeset
|
2179 |
# Add the packages which are installed, but not in the catalog. |
5620652f5927
4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents:
703
diff
changeset
|
2180 |
# XXX Should we have a different state for these, so we can flag |
5620652f5927
4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents:
703
diff
changeset
|
2181 |
# them to the user? |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2182 |
for state, f in self.__pkg_states.values(): |
715
5620652f5927
4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents:
703
diff
changeset
|
2183 |
if state != PKG_STATE_INSTALLED: |
5620652f5927
4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents:
703
diff
changeset
|
2184 |
continue |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2185 |
|
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2186 |
# cache_fmri will automatically determine whether the |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2187 |
# fmri is in the catalog and then cache if needed. The |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2188 |
# fmri (or its version or publisher information) could |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2189 |
# be missing for a number of reasons: |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2190 |
# * the package's publisher was removed, and no other |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2191 |
# publisher has a matching catalog entry |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2192 |
# * the fmri does not exist in the catalogs of any |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2193 |
# existing publisher, even though the publisher |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2194 |
# of the installed package has a catalog |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2195 |
# * the package's publisher was removed or does not |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2196 |
# exist in the installed package publisher's |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2197 |
# catalog, but another publisher has a matching |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2198 |
# catalog entry, so the fmri has been cached with |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2199 |
# the other publisher's information, and the |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2200 |
# installed publisher's information is missing |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2201 |
# |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2202 |
# The state of the package itself may be installed, but |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2203 |
# the package is unknown to the publisher (not in its |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2204 |
# catalog). |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2205 |
catalog.Catalog.cache_fmri(self._catalog, f, |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2206 |
f.get_publisher(), known=False) |
715
5620652f5927
4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents:
703
diff
changeset
|
2207 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2208 |
def __destroy_catalog_cache(self): |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2209 |
croot = os.path.join(self.imgdir, "catalog") |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2210 |
|
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2211 |
# Remove catalog cache files (including old ones). |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2212 |
croot = os.path.join(self.imgdir, "catalog") |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2213 |
for fname in ("pkg_names.pkl", "catalog.pkl", "catalog_cache"): |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2214 |
fpath = os.path.join(croot, fname) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2215 |
try: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2216 |
portable.remove(fpath) |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2217 |
except KeyboardInterrupt: |
537
3dc9fc9b5fee
1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents:
526
diff
changeset
|
2218 |
raise |
1068
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2219 |
except: |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2220 |
# If for any reason, the file can't be removed, |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2221 |
# it doesn't matter as it will be overwritten. |
9400aa8afd32
2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents:
1045
diff
changeset
|
2222 |
pass |
556
1c3526ca7b9e
2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents:
554
diff
changeset
|
2223 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2224 |
# Reset the in-memory cache. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2225 |
self._catalog = {} |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2226 |
self.__catalog_cache_mod_time = None |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2227 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
2228 |
def _get_publisher_meta_root(self, prefix): |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
2229 |
return os.path.join(self.imgdir, "catalog", prefix) |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
2230 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2231 |
def has_catalog(self, prefix): |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
2232 |
return os.path.exists(os.path.join( |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
2233 |
self._get_publisher_meta_root(prefix), "catalog")) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2234 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2235 |
def remove_publisher_metadata(self, pub): |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2236 |
"""Removes the metadata for the specified publisher object.""" |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2237 |
|
537
3dc9fc9b5fee
1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents:
526
diff
changeset
|
2238 |
try: |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2239 |
del self.__catalogs[pub.prefix] |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2240 |
except KeyError: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2241 |
# May not have been loaded yet. |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2242 |
pass |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2243 |
|
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2244 |
pub.remove_meta_root() |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2245 |
self.__destroy_catalog_cache() |
537
3dc9fc9b5fee
1540 changes to authorities should include refresh
Brock Pytlik <bpytlik@sun.com>
parents:
526
diff
changeset
|
2246 |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2247 |
def fmri_is_same_pkg(self, cfmri, pfmri): |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2248 |
"""Determine whether fmri and pfmri share the same package |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2249 |
name, even if they're not equivalent versions. This |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2250 |
also checks if two packages with different names are actually |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2251 |
the same because of a rename operation.""" |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2252 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2253 |
# If the catalog has a rename record that names fmri as a |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2254 |
# destination, it's possible that pfmri could be the same pkg by |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2255 |
# rename. |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2256 |
if cfmri.is_same_pkg(pfmri): |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2257 |
return True |
329 | 2258 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2259 |
# Get the catalog for the correct publisher |
329 | 2260 |
cat = self.get_catalog(cfmri) |
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2261 |
return cat.rename_is_same_pkg(cfmri, pfmri) |
329 | 2262 |
|
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2263 |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2264 |
def fmri_is_successor(self, cfmri, pfmri): |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2265 |
"""Since the catalog keeps track of renames, it's no longer |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2266 |
sufficient to rely on the FMRI class to determine whether a |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2267 |
package is a successor. This routine takes two FMRIs, and |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2268 |
if they have the same publisher, checks if they've been |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2269 |
renamed. If a rename has occurred, this runs the is_successor |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2270 |
routine from the catalog. Otherwise, this runs the standard |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2271 |
fmri.is_successor() code.""" |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2272 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2273 |
# Get the catalog for the correct publisher |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2274 |
cat = self.get_catalog(cfmri) |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2275 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2276 |
# If the catalog has a rename record that names fmri as a |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2277 |
# destination, it's possible that pfmri could be a successor by |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2278 |
# rename. |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2279 |
if cfmri.is_successor(pfmri): |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2280 |
return True |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2281 |
else: |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2282 |
return cat.rename_is_successor(cfmri, pfmri) |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
2283 |
|
516
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2284 |
def gen_installed_pkg_names(self): |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2285 |
"""Generate the string representation of all installed |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2286 |
packages. This is faster than going through gen_installed_pkgs |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2287 |
when all that will be done is to extract the strings from |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2288 |
the result. |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2289 |
""" |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2290 |
if self.__pkg_states is not None: |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2291 |
for i in self.__pkg_states.values(): |
516
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2292 |
yield i[1].get_fmri(anarchy=True) |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2293 |
else: |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2294 |
installed_state_dir = "%s/state/installed" % \ |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2295 |
self.imgdir |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2296 |
if os.path.isdir(installed_state_dir): |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2297 |
for pl in os.listdir(installed_state_dir): |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2298 |
yield "pkg:/" + urllib.unquote(pl) |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2299 |
else: |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2300 |
proot = "%s/pkg" % self.imgdir |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2301 |
for pd in sorted(os.listdir(proot)): |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2302 |
for vd in \ |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2303 |
sorted(os.listdir("%s/%s" % |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2304 |
(proot, pd))): |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2305 |
path = "%s/%s/%s/installed" % \ |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2306 |
(proot, pd, vd) |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2307 |
if not os.path.exists(path): |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2308 |
continue |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2309 |
|
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2310 |
yield urllib.unquote( |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2311 |
"pkg:/%s@%s" % (pd, vd)) |
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2312 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2313 |
# This could simply call self.inventory() (or be replaced by inventory), |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2314 |
# but it turns out to be about 20% slower. |
221
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
2315 |
def gen_installed_pkgs(self): |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
2316 |
"""Return an iteration through the installed packages.""" |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2317 |
self.__load_pkg_states() |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2318 |
return (i[1] for i in self.__pkg_states.values()) |
315
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
2319 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2320 |
def __load_pkg_states(self): |
423
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
2321 |
"""Build up the package state dictionary. |
526
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2322 |
|
423
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
2323 |
This dictionary maps the full fmri string to a tuple of the |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2324 |
state, the prefix of the publisher from which it's installed, |
423
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
2325 |
and the fmri object. |
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
2326 |
|
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
2327 |
Note that this dictionary only maps installed packages. Use |
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
2328 |
get_pkg_state_by_fmri() to retrieve the state for arbitrary |
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
2329 |
packages. |
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
2330 |
""" |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2331 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2332 |
if self.__pkg_states is not None: |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2333 |
return |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
2334 |
|
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
2335 |
installed_state_dir = "%s/state/installed" % self.imgdir |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
2336 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2337 |
self.__pkg_states = {} |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
2338 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2339 |
# If the state directory structure has already been created, |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2340 |
# loading information from it is fast. The directory is |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2341 |
# populated with symlinks, named by their (url-encoded) FMRI, |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2342 |
# which point to the "installed" file in the corresponding |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2343 |
# directory under /var/pkg. |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
2344 |
if os.path.isdir(installed_state_dir): |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
2345 |
for pl in sorted(os.listdir(installed_state_dir)): |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
2346 |
fmristr = urllib.unquote(pl) |
1125
b5c8d228bd76
2721 image.__load_pkg_states creates extra PkgFmri objects
Rich Burridge <rich.burridge@sun.com>
parents:
1111
diff
changeset
|
2347 |
f = pkg.fmri.PkgFmri(fmristr) |
b5c8d228bd76
2721 image.__load_pkg_states creates extra PkgFmri objects
Rich Burridge <rich.burridge@sun.com>
parents:
1111
diff
changeset
|
2348 |
path = self._install_file(f) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2349 |
pub = self.installed_file_publisher(path) |
1125
b5c8d228bd76
2721 image.__load_pkg_states creates extra PkgFmri objects
Rich Burridge <rich.burridge@sun.com>
parents:
1111
diff
changeset
|
2350 |
f.set_publisher(pub) |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
2351 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2352 |
self.__pkg_states[fmristr] = \ |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2353 |
(PKG_STATE_INSTALLED, f) |
418
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
2354 |
|
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
2355 |
return |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
2356 |
|
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
2357 |
# Otherwise, we must iterate through the earlier installed |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
2358 |
# state. One day, this can be removed. |
21621fd99956
2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents:
409
diff
changeset
|
2359 |
proot = "%s/pkg" % self.imgdir |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
2360 |
for pd in sorted(os.listdir(proot)): |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
2361 |
for vd in sorted(os.listdir("%s/%s" % (proot, pd))): |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
2362 |
path = "%s/%s/%s/installed" % (proot, pd, vd) |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
2363 |
if not os.path.exists(path): |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
2364 |
continue |
226
8939051a496c
376 image must use default authority when none specified
johansen <johansen@sun.com>
parents:
222
diff
changeset
|
2365 |
|
331
4f332d6b4036
1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents:
329
diff
changeset
|
2366 |
fmristr = urllib.unquote("%s@%s" % (pd, vd)) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2367 |
pub = self.installed_file_publisher(path) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2368 |
f = pkg.fmri.PkgFmri(fmristr, publisher = pub) |
226
8939051a496c
376 image must use default authority when none specified
johansen <johansen@sun.com>
parents:
222
diff
changeset
|
2369 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2370 |
self.__pkg_states[fmristr] = \ |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2371 |
(PKG_STATE_INSTALLED, f) |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
2372 |
|
516
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2373 |
def clear_pkg_state(self): |
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2374 |
self.__pkg_states = None |
567
ea1d96e269a4
3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents:
565
diff
changeset
|
2375 |
self.__manifest_cache = {} |
516
53da6297fb65
3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents:
499
diff
changeset
|
2376 |
|
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
2377 |
def strtofmri(self, myfmri): |
423
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
2378 |
return pkg.fmri.PkgFmri(myfmri, self.attrs["Build-Release"]) |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
2379 |
|
526
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2380 |
def strtomatchingfmri(self, myfmri): |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2381 |
return pkg.fmri.MatchingPkgFmri(myfmri, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2382 |
self.attrs["Build-Release"]) |
526
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2383 |
|
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2384 |
def load_constraints(self, progtrack): |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2385 |
"""Load constraints for all install pkgs""" |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2386 |
for fmri in self.gen_installed_pkgs(): |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2387 |
# skip loading if already done |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2388 |
if self.constraints.start_loading(fmri): |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
2389 |
mfst = self.get_manifest(fmri) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2390 |
for dep in mfst.gen_actions_by_type("depend", |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
2391 |
self.list_excludes()): |
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2392 |
progtrack.evaluate_progress() |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2393 |
f, con = dep.parse(self, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2394 |
fmri.get_name()) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2395 |
self.constraints.update_constraints(con) |
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2396 |
self.constraints.finish_loading(fmri) |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
2397 |
|
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2398 |
def get_installed_unbound_inc_list(self): |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2399 |
"""Returns list of packages containing incorporation |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2400 |
dependencies on which no other pkgs depend.""" |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
2401 |
|
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2402 |
inc_tuples = [] |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2403 |
dependents = set() |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
2404 |
|
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
2405 |
for fmri in self.gen_installed_pkgs(): |
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2406 |
fmri_name = fmri.get_pkg_stem() |
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
2407 |
mfst = self.get_manifest(fmri) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2408 |
for dep in mfst.gen_actions_by_type("depend", |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2409 |
self.list_excludes()): |
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2410 |
con_fmri = dep.get_constrained_fmri(self) |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2411 |
if con_fmri: |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2412 |
con_name = con_fmri.get_pkg_stem() |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2413 |
dependents.add(con_name) |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2414 |
inc_tuples.append((fmri_name, con_name)) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2415 |
# remove those incorporations which are depended on by other |
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2416 |
# incorporations. |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2417 |
deletions = 0 |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2418 |
for i, a in enumerate(inc_tuples[:]): |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2419 |
if a[0] in dependents: |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2420 |
del inc_tuples[i - deletions] |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2421 |
|
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2422 |
return list(set([ a[0] for a in inc_tuples ])) |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
2423 |
|
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
2424 |
def get_user_by_name(self, name): |
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2425 |
return portable.get_user_by_name(name, self.root, |
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2426 |
self.type != IMG_USER) |
173
da329417a206
18 Actions should use passwd and group databases from image, if possible
Danek Duvall <danek.duvall@sun.com>
parents:
172
diff
changeset
|
2427 |
|
339
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2428 |
def get_name_by_uid(self, uid, returnuid = False): |
173
da329417a206
18 Actions should use passwd and group databases from image, if possible
Danek Duvall <danek.duvall@sun.com>
parents:
172
diff
changeset
|
2429 |
# XXX What to do about IMG_PARTIAL? |
339
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2430 |
try: |
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2431 |
return portable.get_name_by_uid(uid, self.root, |
339
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2432 |
self.type != IMG_USER) |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2433 |
except KeyError: |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2434 |
if returnuid: |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2435 |
return uid |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2436 |
else: |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2437 |
raise |
243
ca57127811b8
399 pkg list on explicit packages fails with no output, exit status of 1
Stephen Hahn <sch@Sun.COM>
parents:
239
diff
changeset
|
2438 |
|
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
2439 |
def get_group_by_name(self, name): |
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2440 |
return portable.get_group_by_name(name, self.root, |
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2441 |
self.type != IMG_USER) |
173
da329417a206
18 Actions should use passwd and group databases from image, if possible
Danek Duvall <danek.duvall@sun.com>
parents:
172
diff
changeset
|
2442 |
|
339
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2443 |
def get_name_by_gid(self, gid, returngid = False): |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2444 |
try: |
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2445 |
return portable.get_name_by_gid(gid, self.root, |
339
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2446 |
self.type != IMG_USER) |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2447 |
except KeyError: |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2448 |
if returngid: |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2449 |
return gid |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2450 |
else: |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
2451 |
raise |
173
da329417a206
18 Actions should use passwd and group databases from image, if possible
Danek Duvall <danek.duvall@sun.com>
parents:
172
diff
changeset
|
2452 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2453 |
@staticmethod |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2454 |
def __multimatch(name, patterns, matcher): |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2455 |
"""Applies a matcher to a name across a list of patterns. |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2456 |
Returns all tuples of patterns which match the name. Each tuple |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2457 |
contains the index into the original list, the pattern itself, |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2458 |
the package version, the publisher, and the raw publisher |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2459 |
string.""" |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2460 |
return [ |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2461 |
(i, pat, pat.tuple()[2], |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2462 |
pat.get_publisher(), pat.get_publisher_str()) |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2463 |
for i, pat in enumerate(patterns) |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2464 |
if matcher(name, pat.tuple()[1]) |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2465 |
] |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2466 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2467 |
def __inventory(self, patterns=None, all_known=False, matcher=None, |
1045
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
2468 |
constraint=pkg.version.CONSTRAINT_AUTO, ordered=True): |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2469 |
"""Private method providing the back-end for inventory().""" |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2470 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2471 |
if not matcher: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2472 |
matcher = pkg.fmri.fmri_match |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
2473 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2474 |
if not patterns: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2475 |
patterns = [] |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2476 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2477 |
# Store the original patterns before we possibly turn them into |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2478 |
# PkgFmri objects, so we can give them back to the user in error |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2479 |
# messages. |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2480 |
opatterns = patterns[:] |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2481 |
|
526
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2482 |
illegals = [] |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2483 |
for i, pat in enumerate(patterns): |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2484 |
if not isinstance(pat, pkg.fmri.PkgFmri): |
526
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2485 |
try: |
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2486 |
if "*" in pat or "?" in pat: |
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2487 |
matcher = pkg.fmri.glob_match |
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2488 |
patterns[i] = \ |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2489 |
pkg.fmri.MatchingPkgFmri( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2490 |
pat, "5.11") |
526
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2491 |
else: |
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2492 |
patterns[i] = \ |
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2493 |
pkg.fmri.PkgFmri(pat, |
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2494 |
"5.11") |
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2495 |
except pkg.fmri.IllegalFmri, e: |
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2496 |
illegals.append(e) |
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2497 |
|
8c243883ae41
822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents:
518
diff
changeset
|
2498 |
if illegals: |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
2499 |
raise api_errors.InventoryException(illegal=illegals) |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2500 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2501 |
ppub = self.cfg_cache.preferred_publisher |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2502 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2503 |
# matchingpats is the set of all the patterns which matched a |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2504 |
# package in the catalog. This allows us to return partial |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2505 |
# failure if some patterns match and some don't. |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2506 |
# XXX It would be nice to keep track of why some patterns failed |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2507 |
# to match -- based on name, version, or publisher. |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2508 |
matchingpats = set() |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
2509 |
|
1045
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
2510 |
if ordered: |
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
2511 |
entries = sorted(self._catalog.keys()) |
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
2512 |
else: |
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
2513 |
entries = self._catalog.keys() |
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
2514 |
|
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
2515 |
for name in entries: |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2516 |
# Eliminate all patterns not matching "name". If there |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2517 |
# are no patterns left, go on to the next name, but only |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2518 |
# if there were any to start with. |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2519 |
matches = self.__multimatch(name, patterns, matcher) |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2520 |
if patterns and not matches: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2521 |
continue |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2522 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2523 |
newest = self._catalog[name]["versions"][-1] |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2524 |
for ver in reversed(self._catalog[name]["versions"]): |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2525 |
# If a pattern specified a version and that |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2526 |
# version isn't succeeded by "ver", then record |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2527 |
# the pattern for removal from consideration. |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2528 |
nomatch = [] |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2529 |
for i, match in enumerate(matches): |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2530 |
if match[2] and \ |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2531 |
not ver.is_successor(match[2], |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2532 |
constraint): |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2533 |
nomatch.append(i) |
221
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
2534 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2535 |
# Eliminate the name matches that didn't match |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2536 |
# on versions. We need to create a new list |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2537 |
# because we need to reuse the original |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2538 |
# "matches" for each new version. |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2539 |
vmatches = [ |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2540 |
matches[i] |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2541 |
for i, match in enumerate(matches) |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2542 |
if i not in nomatch |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2543 |
] |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2544 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2545 |
# If we deleted all contenders (if we had any to |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2546 |
# begin with), go on to the next version. |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2547 |
if matches and not vmatches: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2548 |
continue |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2549 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2550 |
# Like the version skipping above, do the same |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2551 |
# for publishers. |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2552 |
pubstate = self._catalog[name][str(ver)][1] |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2553 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2554 |
nomatch = [] |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2555 |
for i, match in enumerate(vmatches): |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2556 |
if match[3] and \ |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2557 |
match[3] not in pubstate: |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2558 |
nomatch.append(i) |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2559 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2560 |
pmatches = [ |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2561 |
vmatches[i] |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2562 |
for i, match in enumerate(vmatches) |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2563 |
if i not in nomatch |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2564 |
] |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2565 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2566 |
if vmatches and not pmatches: |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2567 |
continue |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
2568 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2569 |
# If no patterns were specified or any still- |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2570 |
# matching pattern specified no publisher, we |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2571 |
# use the entire list of publishers for this |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2572 |
# version. Otherwise, we use the intersection |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2573 |
# of the list of publishers in pubstate, and |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2574 |
# the publishers in the patterns. |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2575 |
aset = set(i[3] for i in pmatches) |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2576 |
if aset and None not in aset: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2577 |
publist = set( |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2578 |
m[3:5] |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2579 |
for m in pmatches |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2580 |
if m[3] in pubstate |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2581 |
) |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2582 |
else: |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2583 |
publist = zip(pubstate.keys(), |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2584 |
pubstate.keys()) |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2585 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2586 |
pfmri = self._catalog[name][str(ver)][0] |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2587 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2588 |
inst_state = self.get_pkg_state_by_fmri(pfmri) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2589 |
inst_pub = self.get_pkg_pub_by_fmri(pfmri) |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2590 |
state = { |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2591 |
"upgradable": ver != newest, |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2592 |
"frozen": False, |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2593 |
"incorporated": False, |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2594 |
"excludes": False |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2595 |
} |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2596 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2597 |
# We yield copies of the fmri objects in the |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2598 |
# catalog because we add the publishers in, and |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2599 |
# don't want to mess up the canonical catalog. |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2600 |
# If a pattern had specified a publisher as |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2601 |
# preferred, be sure to emit an fmri that way, |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2602 |
# too. |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2603 |
yielded = False |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2604 |
if all_known: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2605 |
for pub, rpub in publist: |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2606 |
nfmri = pfmri.copy() |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2607 |
nfmri.set_publisher(rpub, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2608 |
pub == ppub) |
703
4cb0ea696976
3273 image.inventory yields same dictionary multiple times for packages in multiple authorities
Danek Duvall <danek.duvall@sun.com>
parents:
696
diff
changeset
|
2609 |
st = state.copy() |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2610 |
if pub == inst_pub: |
703
4cb0ea696976
3273 image.inventory yields same dictionary multiple times for packages in multiple authorities
Danek Duvall <danek.duvall@sun.com>
parents:
696
diff
changeset
|
2611 |
st["state"] = \ |
423
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
2612 |
PKG_STATE_INSTALLED |
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
2613 |
else: |
703
4cb0ea696976
3273 image.inventory yields same dictionary multiple times for packages in multiple authorities
Danek Duvall <danek.duvall@sun.com>
parents:
696
diff
changeset
|
2614 |
st["state"] = \ |
423
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
2615 |
PKG_STATE_KNOWN |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2616 |
st["in_catalog"] = pubstate[pub] |
703
4cb0ea696976
3273 image.inventory yields same dictionary multiple times for packages in multiple authorities
Danek Duvall <danek.duvall@sun.com>
parents:
696
diff
changeset
|
2617 |
yield nfmri, st |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2618 |
yielded = True |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2619 |
elif inst_state == PKG_STATE_INSTALLED: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2620 |
nfmri = pfmri.copy() |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2621 |
nfmri.set_publisher(inst_pub, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2622 |
inst_pub == ppub) |
423
5c756997bf67
2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents:
419
diff
changeset
|
2623 |
state["state"] = inst_state |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2624 |
state["in_catalog"] = pubstate[inst_pub] |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2625 |
yield nfmri, state |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2626 |
yielded = True |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2627 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2628 |
if yielded: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2629 |
matchingpats |= set( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2630 |
i[:2] for i in pmatches) |
329 | 2631 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2632 |
nonmatchingpats = [ |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2633 |
opatterns[i] |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2634 |
for i, f in set(enumerate(patterns)) - matchingpats |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2635 |
] |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2636 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2637 |
if nonmatchingpats: |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
2638 |
raise api_errors.InventoryException( |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
2639 |
notfound=nonmatchingpats) |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2640 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2641 |
def inventory(self, *args, **kwargs): |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2642 |
"""Enumerate the package FMRIs in the image's catalog, yielding |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2643 |
a list of tuples of the format (fmri, pkg state dict). |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2644 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2645 |
If "patterns" is None (the default) or an empty sequence, all |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2646 |
package names will match. Otherwise, it is a list of patterns |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2647 |
to match against FMRIs in the catalog. |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2648 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2649 |
If "all_known" is False (the default), only installed packages |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2650 |
will be enumerated. If True, all known packages will be |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2651 |
enumerated. |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2652 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2653 |
The "matcher" parameter should specify a function taking two |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2654 |
string arguments: a name and a pattern, returning True if the |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2655 |
pattern matches the name, and False otherwise. By default, the |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2656 |
matcher will be pkg.fmri.fmri_match(). |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2657 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2658 |
The "constraint" parameter defines how a version specified in a |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2659 |
pattern matches a version in the catalog. By default, a natural |
1045
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
2660 |
"subsetting" constraint is used. |
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
2661 |
|
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
2662 |
The "ordered" parameter is a boolean value that indicates |
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
2663 |
whether the returned list should first be sorted by name before |
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
2664 |
being sorted by version (descending). By default, this is True. |
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
2665 |
""" |
161
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
2666 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2667 |
# "preferred" and "first_only" are private arguments that are |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2668 |
# currently only used in evaluate_fmri(), but could be made more |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2669 |
# generally useful. "preferred" ensures that all potential |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2670 |
# matches from the preferred publisher are generated before |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2671 |
# those from non-preferred publishers. In the current |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2672 |
# implementation, this consumes more memory. "first_only" |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2673 |
# signals us to return only the first match, which allows us to |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2674 |
# save all the memory that "preferred" currently eats up. |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2675 |
preferred = kwargs.pop("preferred", False) |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2676 |
first_only = kwargs.pop("first_only", False) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2677 |
ppub = self.cfg_cache.preferred_publisher |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
2678 |
|
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2679 |
if not preferred: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2680 |
for f in self.__inventory(*args, **kwargs): |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2681 |
yield f |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2682 |
else: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2683 |
nplist = [] |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2684 |
firstnp = None |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2685 |
for f in self.__inventory(*args, **kwargs): |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2686 |
if f[0].get_publisher() == ppub: |
419
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2687 |
yield f |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2688 |
if first_only: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2689 |
return |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2690 |
else: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2691 |
if first_only: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2692 |
if not firstnp: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2693 |
firstnp = f |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2694 |
else: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2695 |
nplist.append(f) |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2696 |
if first_only: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2697 |
yield firstnp |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2698 |
return |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2699 |
|
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2700 |
for f in nplist: |
a38f1ed7cf76
1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents:
418
diff
changeset
|
2701 |
yield f |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
2702 |
|
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2703 |
def update_index_dir(self, postfix="index"): |
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2704 |
"""Since the index directory will not reliably be updated when |
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2705 |
the image root is, this should be called prior to using the |
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2706 |
index directory. |
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2707 |
""" |
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2708 |
self.index_dir = os.path.join(self.imgdir, postfix) |
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2709 |
|
388
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2710 |
def incoming_download_dir(self): |
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2711 |
"""Return the directory path for incoming downloads |
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2712 |
that have yet to be completed. Once a file has been |
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2713 |
successfully downloaded, it is moved to the cached download |
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2714 |
directory.""" |
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2715 |
|
554
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
2716 |
return self.dl_cache_incoming |
388
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2717 |
|
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2718 |
def cached_download_dir(self): |
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2719 |
"""Return the directory path for cached content. |
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2720 |
Files that have been successfully downloaded live here.""" |
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2721 |
|
554
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
2722 |
return self.dl_cache_dir |
251
6c3d70b74865
470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
243
diff
changeset
|
2723 |
|
6c3d70b74865
470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
243
diff
changeset
|
2724 |
def cleanup_downloads(self): |
388
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2725 |
"""Clean up any downloads that were in progress but that |
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2726 |
did not successfully finish.""" |
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2727 |
|
554
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
2728 |
shutil.rmtree(self.dl_cache_incoming, True) |
388
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2729 |
|
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2730 |
def cleanup_cached_content(self): |
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2731 |
"""Delete the directory that stores all of our cached |
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2732 |
downloaded content. This may take a while for a large |
554
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
2733 |
directory hierarchy. Don't clean up caches if the |
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
2734 |
user overrode the underlying setting using PKG_CACHEDIR. """ |
388
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2735 |
|
554
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
2736 |
if not self.is_user_cache_dir and \ |
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
2737 |
self.cfg_cache.get_policy(imageconfig.FLUSH_CONTENT_CACHE): |
388
5a08791fb814
2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents:
384
diff
changeset
|
2738 |
msg("Deleting content cache") |
554
fe196874250d
3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents:
552
diff
changeset
|
2739 |
shutil.rmtree(self.dl_cache_dir, True) |
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
2740 |
|
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
2741 |
def salvagedir(self, path): |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2742 |
"""Called when directory contains something and it's not |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2743 |
supposed to because it's being deleted. XXX Need to work out a |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2744 |
better error passback mechanism. Path is rooted in /....""" |
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2745 |
|
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
2746 |
salvagedir = os.path.normpath( |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
2747 |
os.path.join(self.imgdir, "lost+found", |
384
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
383
diff
changeset
|
2748 |
path + "-" + time.strftime("%Y%m%dT%H%M%SZ"))) |
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
2749 |
|
405
16824ed83efe
2209 license install failure on Windows if license file already exists
Tom Mueller <Tom.Mueller@sun.com>
parents:
399
diff
changeset
|
2750 |
parent = os.path.dirname(salvagedir) |
16824ed83efe
2209 license install failure on Windows if license file already exists
Tom Mueller <Tom.Mueller@sun.com>
parents:
399
diff
changeset
|
2751 |
if not os.path.exists(parent): |
16824ed83efe
2209 license install failure on Windows if license file already exists
Tom Mueller <Tom.Mueller@sun.com>
parents:
399
diff
changeset
|
2752 |
os.makedirs(parent) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2753 |
shutil.move(os.path.normpath(os.path.join(self.root, path)), |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2754 |
salvagedir) |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
2755 |
# XXX need a better way to do this. |
384
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
383
diff
changeset
|
2756 |
emsg("\nWarning - directory %s not empty - contents preserved " |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
383
diff
changeset
|
2757 |
"in %s" % (path, salvagedir)) |
251
6c3d70b74865
470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
243
diff
changeset
|
2758 |
|
462
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
2759 |
def temporary_file(self): |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2760 |
"""create a temp file under image directory for various |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2761 |
purposes""" |
462
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
2762 |
tempdir = os.path.normpath(os.path.join(self.imgdir, "tmp")) |
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
2763 |
if not os.path.exists(tempdir): |
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
2764 |
os.makedirs(tempdir) |
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
2765 |
fd, name = tempfile.mkstemp(dir=tempdir) |
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
2766 |
os.close(fd) |
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
2767 |
return name |
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
2768 |
|
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2769 |
def __filter_install_matches(self, matches, names): |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2770 |
"""Attempts to eliminate redundant matches found during |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2771 |
packaging operations: |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2772 |
|
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2773 |
* First, stems of installed packages for publishers that |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2774 |
are now unknown (no longer present in the image |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2775 |
configuration) are dropped. |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2776 |
|
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2777 |
* Second, if multiple matches are still present, stems of |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2778 |
of installed packages, that are not presently in the |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2779 |
corresponding publisher's catalog, are dropped. |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2780 |
|
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2781 |
* Finally, if multiple matches are still present, all |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2782 |
stems except for those in state PKG_STATE_INSTALLED are |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2783 |
dropped. |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2784 |
|
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2785 |
Returns a list of the filtered matches, along with a dict of |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2786 |
their unique names and a dict containing package state |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2787 |
information.""" |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2788 |
|
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2789 |
olist = [] |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2790 |
onames = {} |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2791 |
# First eliminate any duplicate matches that are for unknown |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2792 |
# publishers (publishers which have been removed from the image |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2793 |
# configuration). |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2794 |
publist = [p.prefix for p in self.get_publishers().values()] |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2795 |
|
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2796 |
for m in matches: |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2797 |
if m.get_publisher() in publist: |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2798 |
stem = m.get_pkg_stem() |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2799 |
onames[stem] = names[stem] |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2800 |
olist.append(m) |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2801 |
|
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2802 |
# Next, if there are still multiple matches, eliminate fmris |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2803 |
# belonging to publishers that no longer have the fmri in their |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2804 |
# catalog. |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2805 |
found_state = False |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2806 |
if len(onames) > 1: |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2807 |
mlist = [] |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2808 |
mnames = {} |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2809 |
for m in olist: |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2810 |
stem = m.get_pkg_stem() |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2811 |
st = onames[stem] |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2812 |
if st["in_catalog"]: |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2813 |
if st["state"] == PKG_STATE_INSTALLED: |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2814 |
found_state = True |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2815 |
mnames[stem] = onames[stem] |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2816 |
mlist.append(m) |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2817 |
olist = mlist |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2818 |
onames = mnames |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2819 |
|
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2820 |
# Finally, if there are still multiple matches, and a known stem |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2821 |
# has been found in the provided state, then eliminate any stems |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2822 |
# that do not have the specified state. |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2823 |
if found_state and len(onames) > 1: |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2824 |
mlist = [] |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2825 |
mnames = {} |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2826 |
for m in olist: |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2827 |
stem = m.get_pkg_stem() |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2828 |
if onames[stem]["state"] == PKG_STATE_INSTALLED: |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2829 |
mnames[stem] = onames[stem] |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2830 |
mlist.append(m) |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2831 |
olist = mlist |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2832 |
onames = mnames |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2833 |
|
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2834 |
return olist, onames |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2835 |
|
625
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
621
diff
changeset
|
2836 |
def make_install_plan(self, pkg_list, progtrack, check_cancelation, |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
2837 |
noexecute, filters = None, verbose=False): |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2838 |
"""Take a list of packages, specified in pkg_list, and attempt |
329 | 2839 |
to assemble an appropriate image plan. This is a helper |
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2840 |
routine for some common operations in the client. |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2841 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2842 |
This method checks all publishers for a package match; |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2843 |
however, it defaults to choosing the preferred publisher |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2844 |
when an ambiguous package name is specified. If the user |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2845 |
wishes to install a package from a non-preferred publisher, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2846 |
the full FMRI that contains a publisher should be used |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2847 |
to name the package.""" |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2848 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2849 |
self.load_catalogs(progtrack) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
2850 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
2851 |
if filters is None: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
2852 |
filters = [] |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2853 |
|
172 | 2854 |
error = 0 |
625
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
621
diff
changeset
|
2855 |
ip = imageplan.ImagePlan(self, progtrack, check_cancelation, |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
2856 |
filters=filters, noexecute=noexecute) |
172 | 2857 |
|
625
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
621
diff
changeset
|
2858 |
progtrack.evaluate_start() |
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2859 |
self.load_constraints(progtrack) |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
2860 |
|
1141
a74d6815a7fc
4178 unfound_fmris is a poor name
Rich Burridge <rich.burridge@sun.com>
parents:
1133
diff
changeset
|
2861 |
unmatched_fmris = [] |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
2862 |
multiple_matches = [] |
616
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
2863 |
illegal_fmris = [] |
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2864 |
constraint_violations = [] |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2865 |
|
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2866 |
# order package list so that any unbound incorporations are |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2867 |
# done first |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2868 |
|
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2869 |
inc_list = self.get_installed_unbound_inc_list() |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2870 |
|
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2871 |
head = [] |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2872 |
tail = [] |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2873 |
|
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2874 |
|
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2875 |
for p in pkg_list: |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2876 |
if p in inc_list: |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2877 |
head.append(p) |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2878 |
else: |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2879 |
tail.append(p) |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2880 |
pkg_list = head + tail |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2881 |
|
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2882 |
# This approach works only for cases w/ simple |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2883 |
# incorporations; the apply_constraints_to_fmri |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2884 |
# call below binds the version too quickly. This |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2885 |
# awaits a proper solver. |
616
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
2886 |
|
172 | 2887 |
for p in pkg_list: |
625
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
621
diff
changeset
|
2888 |
progtrack.evaluate_progress() |
172 | 2889 |
try: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2890 |
conp = pkg.fmri.PkgFmri(p, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2891 |
self.attrs["Build-Release"]) |
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2892 |
except pkg.fmri.IllegalFmri: |
616
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
2893 |
illegal_fmris.append(p) |
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2894 |
error = 1 |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2895 |
continue |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2896 |
try: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2897 |
conp = \ |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2898 |
self.constraints.apply_constraints_to_fmri( |
1085
aa3274c0fe55
8392 backpublishing variant-aware SUNWipkg to 101 will break zones on those builds
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1075
diff
changeset
|
2899 |
conp, auto=True) |
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2900 |
except constraint.ConstraintException, e: |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2901 |
error = 1 |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2902 |
constraint_violations.extend(str(e).split("\n")) |
616
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
2903 |
continue |
931
2c497b23356a
7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents:
926
diff
changeset
|
2904 |
|
2c497b23356a
7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents:
926
diff
changeset
|
2905 |
# If we were passed in an fmri object or a string that |
2c497b23356a
7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents:
926
diff
changeset
|
2906 |
# anchors the package stem with the scheme, match on the |
2c497b23356a
7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents:
926
diff
changeset
|
2907 |
# stem exactly as given. Otherwise we can let the |
2c497b23356a
7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents:
926
diff
changeset
|
2908 |
# default, looser matching mechanism be used. |
2c497b23356a
7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents:
926
diff
changeset
|
2909 |
# inventory() will override if globbing characters are |
2c497b23356a
7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents:
926
diff
changeset
|
2910 |
# used. |
2c497b23356a
7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents:
926
diff
changeset
|
2911 |
matcher = None |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2912 |
if isinstance(p, pkg.fmri.PkgFmri) or \ |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2913 |
p.startswith("pkg:/"): |
931
2c497b23356a
7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents:
926
diff
changeset
|
2914 |
matcher = pkg.fmri.exact_name_match |
2c497b23356a
7200 package name matching too loose on upgrade
Danek Duvall <danek.duvall@sun.com>
parents:
926
diff
changeset
|
2915 |
|
616
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
2916 |
try: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2917 |
matches = list(self.inventory([conp], |
1045
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
2918 |
all_known=True, matcher=matcher, |
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
2919 |
ordered=False)) |
616
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
2920 |
except api_errors.InventoryException, e: |
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
2921 |
assert(not (e.notfound and e.illegal)) |
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
2922 |
assert(e.notfound or e.illegal) |
172 | 2923 |
error = 1 |
616
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
2924 |
if e.notfound: |
1141
a74d6815a7fc
4178 unfound_fmris is a poor name
Rich Burridge <rich.burridge@sun.com>
parents:
1133
diff
changeset
|
2925 |
unmatched_fmris.append(p) |
616
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
2926 |
else: |
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
2927 |
illegal_fmris.append(p) |
172 | 2928 |
continue |
2929 |
||
2930 |
pnames = {} |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2931 |
pmatch = [] |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2932 |
npnames = {} |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2933 |
npmatch = [] |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2934 |
for m, st in matches: |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2935 |
if m.preferred_publisher(): |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2936 |
pnames[m.get_pkg_stem()] = st |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2937 |
pmatch.append(m) |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2938 |
else: |
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2939 |
npnames[m.get_pkg_stem()] = st |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2940 |
npmatch.append(m) |
172 | 2941 |
|
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2942 |
if len(pnames) > 1: |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2943 |
# There can only be one preferred publisher, so |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2944 |
# filtering is pointless and these are truly |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2945 |
# ambiguous matches. |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
2946 |
multiple_matches.append((p, pnames.keys())) |
172 | 2947 |
error = 1 |
2948 |
continue |
|
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2949 |
elif not pnames and len(npnames) > 1: |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2950 |
npmatch, npnames = \ |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2951 |
self.__filter_install_matches(npmatch, |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2952 |
npnames) |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2953 |
if len(npnames) > 1: |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2954 |
# If there are still multiple matches |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2955 |
# after filtering, fail. |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2956 |
multiple_matches.append((p, |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2957 |
npnames.keys())) |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2958 |
error = 1 |
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2959 |
continue |
172 | 2960 |
|
2961 |
# matches is a list reverse sorted by version, so take |
|
2962 |
# the first; i.e., the latest. |
|
988
a851ba83a5aa
6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
964
diff
changeset
|
2963 |
if pmatch: |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2964 |
ip.propose_fmri(pmatch[0]) |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
2965 |
else: |
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2966 |
ip.propose_fmri(npmatch[0]) |
172 | 2967 |
|
2968 |
if error != 0: |
|
1141
a74d6815a7fc
4178 unfound_fmris is a poor name
Rich Burridge <rich.burridge@sun.com>
parents:
1133
diff
changeset
|
2969 |
raise api_errors.PlanCreationException(unmatched_fmris, |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
2970 |
multiple_matches, [], illegal_fmris, |
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2971 |
constraint_violations=constraint_violations) |
172 | 2972 |
|
2973 |
if verbose: |
|
384
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
383
diff
changeset
|
2974 |
msg(_("Before evaluation:")) |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
383
diff
changeset
|
2975 |
msg(ip) |
172 | 2976 |
|
539
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
2977 |
# A plan can be requested without actually performing an |
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
2978 |
# operation on the image. |
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
2979 |
if self.history.operation_name: |
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
2980 |
self.history.operation_start_state = ip.get_plan() |
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
2981 |
|
655
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2982 |
try: |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2983 |
ip.evaluate() |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2984 |
except constraint.ConstraintException, e: |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2985 |
raise api_errors.PlanCreationException( |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2986 |
constraint_violations=str(e).split("\n")) |
6eef82185057
2325 optional dependency enforcement can't handle fmris disappearing from the catalog
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
648
diff
changeset
|
2987 |
|
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
423
diff
changeset
|
2988 |
self.imageplan = ip |
172 | 2989 |
|
539
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
2990 |
if self.history.operation_name: |
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
2991 |
self.history.operation_end_state = \ |
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
2992 |
ip.get_plan(full=False) |
7486304966c5
1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents:
537
diff
changeset
|
2993 |
|
172 | 2994 |
if verbose: |
384
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
383
diff
changeset
|
2995 |
msg(_("After evaluation:")) |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
383
diff
changeset
|
2996 |
msg(ip.display()) |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
2997 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
2998 |
def make_uninstall_plan(self, fmri_list, recursive_removal, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
2999 |
progresstracker, check_cancelation, noexecute, verbose=False): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3000 |
ip = imageplan.ImagePlan(self, progresstracker, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3001 |
check_cancelation, recursive_removal, noexecute=noexecute) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3002 |
|
1087
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
3003 |
self.load_catalogs(progresstracker) |
293c0aa5f32e
8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents:
1086
diff
changeset
|
3004 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3005 |
err = 0 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3006 |
|
1141
a74d6815a7fc
4178 unfound_fmris is a poor name
Rich Burridge <rich.burridge@sun.com>
parents:
1133
diff
changeset
|
3007 |
unmatched_fmris = [] |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3008 |
multiple_matches = [] |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3009 |
missing_matches = [] |
616
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
3010 |
illegal_fmris = [] |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3011 |
|
625
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
621
diff
changeset
|
3012 |
progresstracker.evaluate_start() |
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
621
diff
changeset
|
3013 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3014 |
for ppat in fmri_list: |
625
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
621
diff
changeset
|
3015 |
progresstracker.evaluate_progress() |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3016 |
try: |
1045
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
3017 |
matches = list(self.inventory([ppat], |
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
3018 |
ordered=False)) |
616
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
3019 |
except api_errors.InventoryException, e: |
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
3020 |
assert(not (e.notfound and e.illegal)) |
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
3021 |
if e.notfound: |
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
3022 |
try: |
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
3023 |
list(self.inventory([ppat], |
1045
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
3024 |
all_known=True, |
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
3025 |
ordered=False)) |
616
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
3026 |
missing_matches.append(ppat) |
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
3027 |
except api_errors.InventoryException: |
1141
a74d6815a7fc
4178 unfound_fmris is a poor name
Rich Burridge <rich.burridge@sun.com>
parents:
1133
diff
changeset
|
3028 |
unmatched_fmris.append(ppat) |
616
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
3029 |
elif e.illegal: |
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
3030 |
illegal_fmris.append(ppat) |
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
3031 |
else: |
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
3032 |
raise RuntimeError("Caught inventory " |
1141
a74d6815a7fc
4178 unfound_fmris is a poor name
Rich Burridge <rich.burridge@sun.com>
parents:
1133
diff
changeset
|
3033 |
"exception without unmatched or " |
616
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
3034 |
"illegal fmris set.") |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3035 |
err = 1 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3036 |
continue |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3037 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3038 |
if len(matches) > 1: |
922
0074b10d84e0
6874 stack trace on install with ambiguous package names
Danek Duvall <danek.duvall@sun.com>
parents:
918
diff
changeset
|
3039 |
matchlist = [m for m, state in matches] |
0074b10d84e0
6874 stack trace on install with ambiguous package names
Danek Duvall <danek.duvall@sun.com>
parents:
918
diff
changeset
|
3040 |
multiple_matches.append((ppat, matchlist)) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3041 |
err = 1 |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3042 |
continue |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3043 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3044 |
# Propose the removal of the first (and only!) match. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3045 |
ip.propose_fmri_removal(matches[0][0]) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3046 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3047 |
if err == 1: |
1141
a74d6815a7fc
4178 unfound_fmris is a poor name
Rich Burridge <rich.burridge@sun.com>
parents:
1133
diff
changeset
|
3048 |
raise api_errors.PlanCreationException(unmatched_fmris, |
616
6d307b088d92
4056 make_uninstall_plan misreports trying to uninstall a known, but uninstalled package
Brock Pytlik <bpytlik@sun.com>
parents:
596
diff
changeset
|
3049 |
multiple_matches, missing_matches, illegal_fmris) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3050 |
if verbose: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3051 |
msg(_("Before evaluation:")) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3052 |
msg(ip) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3053 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3054 |
self.history.operation_start_state = ip.get_plan() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3055 |
ip.evaluate() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3056 |
self.history.operation_end_state = ip.get_plan(full=False) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3057 |
self.imageplan = ip |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3058 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3059 |
if verbose: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3060 |
msg(_("After evaluation:")) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3061 |
ip.display() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3062 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3063 |
def ipkg_is_up_to_date(self, actual_cmd, check_cancelation, noexecute, |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
3064 |
refresh_allowed=True, progtrack=None): |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3065 |
""" Test whether SUNWipkg is updated to the latest version |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3066 |
known to be available for this image """ |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3067 |
# |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3068 |
# This routine makes the distinction between the "target image", |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3069 |
# which will be altered, and the "running image", which is |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
3070 |
# to say whatever image appears to contain the version of the |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3071 |
# pkg command we're running. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3072 |
# |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3073 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3074 |
# |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3075 |
# There are two relevant cases here: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3076 |
# 1) Packaging code and image we're updating are the same |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3077 |
# image. (i.e. 'pkg image-update') |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3078 |
# |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3079 |
# 2) Packaging code's image and the image we're updating are |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3080 |
# different (i.e. 'pkg image-update -R') |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3081 |
# |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3082 |
# In general, we care about getting the user to run the |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3083 |
# most recent packaging code available for their build. So, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3084 |
# if we're not in the liveroot case, we create a new image |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3085 |
# which represents "/" on the system. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3086 |
# |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3087 |
|
625
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
621
diff
changeset
|
3088 |
if not progtrack: |
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
621
diff
changeset
|
3089 |
progtrack = progress.QuietProgressTracker() |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3090 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3091 |
img = self |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
922
diff
changeset
|
3092 |
|
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3093 |
if not img.is_liveroot(): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3094 |
newimg = Image() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3095 |
cmdpath = os.path.join(os.getcwd(), actual_cmd) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3096 |
cmdpath = os.path.realpath(cmdpath) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3097 |
cmddir = os.path.dirname(os.path.realpath(cmdpath)) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3098 |
# |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3099 |
# Find the path to ourselves, and use that |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3100 |
# as a way to locate the image we're in. It's |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3101 |
# not perfect-- we could be in a developer's |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3102 |
# workspace, for example. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3103 |
# |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3104 |
newimg.find_root(cmddir) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3105 |
newimg.load_config() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3106 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
3107 |
if refresh_allowed: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
3108 |
# If refreshing publisher metadata is allowed, |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
3109 |
# then perform a refresh so that a new SUNWipkg |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
3110 |
# can be discovered. |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3111 |
try: |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
3112 |
newimg.refresh_publishers( |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
3113 |
progtrack=progtrack) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3114 |
except api_errors.CatalogRefreshException, cre: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3115 |
cre.message = \ |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3116 |
_("SUNWipkg update check failed.") |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3117 |
raise |
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
3118 |
else: |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
3119 |
# If refresh wasn't called, the catalogs have to |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
3120 |
# be manually loaded. |
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
3121 |
newimg.load_catalogs(progtrack) |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3122 |
img = newimg |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3123 |
|
996
31d152a5212b
7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
993
diff
changeset
|
3124 |
# XXX call to progress tracker that SUNWipkg is being refreshed |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3125 |
|
625
e46b345645d6
3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents:
621
diff
changeset
|
3126 |
img.make_install_plan(["SUNWipkg"], progtrack, |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3127 |
check_cancelation, noexecute, filters = []) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3128 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3129 |
return img.imageplan.nothingtodo() |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3130 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3131 |
def installed_fmris_from_args(self, args): |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3132 |
"""Helper function to translate client command line arguments |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3133 |
into a list of installed fmris. Used by info, contents, |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3134 |
verify. |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3135 |
""" |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3136 |
found = [] |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3137 |
notfound = [] |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3138 |
illegals = [] |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3139 |
try: |
1045
62656c214151
8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents:
1037
diff
changeset
|
3140 |
for m in self.inventory(args, ordered=False): |
565
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3141 |
found.append(m[0]) |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3142 |
except api_errors.InventoryException, e: |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3143 |
illegals = e.illegal |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3144 |
notfound = e.notfound |
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3145 |
|
1fb4f05220b9
3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
562
diff
changeset
|
3146 |
return found, notfound, illegals |