author | johansen <johansen@sun.com> |
Fri, 25 Apr 2008 10:48:09 -0700 | |
changeset 356 | 672e0af33ea8 |
parent 347 | d3768c3508b2 |
child 383 | 08762e4dac3c |
permissions | -rw-r--r-- |
19 | 1 |
#!/usr/bin/python |
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 |
||
221
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
23 |
# Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
19 | 24 |
# Use is subject to license terms. |
25 |
||
144
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
26 |
import cPickle |
161
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
27 |
import errno |
26 | 28 |
import os |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
29 |
import urllib |
201
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
30 |
import urllib2 |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
31 |
import httplib |
251
6c3d70b74865
470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
243
diff
changeset
|
32 |
import shutil |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
33 |
import sys |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
34 |
import time |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
35 |
import types |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
36 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
37 |
# import uuid # XXX interesting 2.5 module |
34
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
38 |
|
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
39 |
import pkg.catalog as catalog |
215
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
40 |
import pkg.updatelog as updatelog |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
41 |
import pkg.fmri |
50 | 42 |
import pkg.manifest as manifest |
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
43 |
import pkg.misc as misc |
175
8d591677690b
22 Specifying a version on the "pkg install" commandline makes no difference
Danek Duvall <danek.duvall@sun.com>
parents:
173
diff
changeset
|
44 |
import pkg.version as version |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
45 |
import pkg.client.imageconfig as imageconfig |
172 | 46 |
import pkg.client.imageplan as imageplan |
161
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
47 |
import pkg.client.retrieve as retrieve |
251
6c3d70b74865
470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
243
diff
changeset
|
48 |
import pkg.client.filelist as filelist |
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
49 |
import pkg.portable as portable |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
50 |
|
145
08bee7fd13f6
Add versioning to the protocols
Danek Duvall <danek.duvall@sun.com>
parents:
144
diff
changeset
|
51 |
from pkg.misc import versioned_urlopen |
319
39b8b5c538bf
1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents:
316
diff
changeset
|
52 |
from pkg.client.imagetypes import * |
19 | 53 |
|
26 | 54 |
img_user_prefix = ".org.opensolaris,pkg" |
30 | 55 |
img_root_prefix = "var/pkg" |
26 | 56 |
|
19 | 57 |
class Image(object): |
58 |
"""An Image object is a directory tree containing the laid-down contents |
|
59 |
of a self-consistent graph of Packages. |
|
60 |
||
61 |
An Image has a root path. |
|
62 |
||
63 |
An Image of type IMG_ENTIRE does not have a parent Image. Other Image |
|
64 |
types must have a parent Image. The external state of the parent Image |
|
65 |
must be accessible from the Image's context, or duplicated within the |
|
66 |
Image (IMG_PARTIAL for zones, for instance). |
|
67 |
||
68 |
The parent of a user Image can be a partial Image. The parent of a |
|
69 |
partial Image must be an entire Image. |
|
70 |
||
71 |
An Image of type IMG_USER stores its external state at self.root + |
|
26 | 72 |
".org.opensolaris,pkg". |
19 | 73 |
|
74 |
An Image of type IMG_ENTIRE or IMG_PARTIAL stores its external state at |
|
75 |
self.root + "/var/pkg". |
|
76 |
||
26 | 77 |
An Image needs to be able to have a different repository set than the |
78 |
system's root Image. |
|
79 |
||
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
80 |
Directory layout |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
81 |
|
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
82 |
$IROOT/catalog |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
83 |
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
|
84 |
the escaped URI of the catalog. |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
85 |
|
30 | 86 |
$IROOT/file |
87 |
Directory containing file hashes of installed packages. |
|
88 |
||
89 |
$IROOT/pkg |
|
90 |
Directory containing manifests and states of installed packages. |
|
91 |
||
60
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
92 |
$IROOT/index |
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
93 |
Directory containing reverse-index databases. |
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
94 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
95 |
$IROOT/cfg_cache |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
96 |
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
|
97 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
98 |
$IROOT/state |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
99 |
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
|
100 |
|
19 | 101 |
XXX Root path probably can't be absolute, so that we can combine or |
30 | 102 |
reuse Image contents. |
26 | 103 |
|
104 |
XXX Image file format? Image file manipulation API?""" |
|
105 |
||
106 |
def __init__(self): |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
107 |
self.cfg_cache = None |
26 | 108 |
self.type = None |
109 |
self.root = None |
|
30 | 110 |
self.imgdir = None |
271
ec8a7669bff2
659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
268
diff
changeset
|
111 |
self.img_prefix = None |
26 | 112 |
self.repo_uris = [] |
113 |
self.filter_tags = {} |
|
32
c26788b7217c
begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents:
30
diff
changeset
|
114 |
self.catalogs = {} |
c26788b7217c
begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents:
30
diff
changeset
|
115 |
|
50 | 116 |
self.attrs = {} |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
117 |
self.link_actions = None |
315
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
118 |
self.installed_pkg_cache = None |
50 | 119 |
|
120 |
self.attrs["Policy-Require-Optional"] = False |
|
121 |
self.attrs["Policy-Pursue-Latest"] = True |
|
122 |
||
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
123 |
self.imageplan = None # valid after evaluation succceds |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
124 |
|
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
125 |
# contains a dictionary w/ key = pkgname, value is miminum |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
126 |
# frmi.XXX Needs rewrite using graph follower |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
127 |
self.optional_dependencies = {} |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
128 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
129 |
def find_root(self, d): |
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
130 |
# Ascend from the given directory d to find first |
26 | 131 |
# encountered image. |
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
132 |
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
|
133 |
# 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
|
134 |
d = os.path.realpath(d) |
26 | 135 |
while 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
|
136 |
if os.path.isdir(os.path.join(d, img_user_prefix)): |
26 | 137 |
# XXX Look at image file to determine filter |
138 |
# tags and repo URIs. |
|
139 |
self.type = IMG_USER |
|
140 |
self.root = d |
|
271
ec8a7669bff2
659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
268
diff
changeset
|
141 |
self.img_prefix = img_user_prefix |
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
142 |
self.imgdir = os.path.join(d, self.img_prefix) |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
143 |
self.attrs["Build-Release"] = "5.11" |
26 | 144 |
return |
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
145 |
elif os.path.isdir(os.path.join(d, img_root_prefix)): |
26 | 146 |
# XXX Look at image file to determine filter |
147 |
# tags and repo URIs. |
|
148 |
# XXX Look at image file to determine if this |
|
149 |
# image is a partial image. |
|
150 |
self.type = IMG_ENTIRE |
|
151 |
self.root = d |
|
271
ec8a7669bff2
659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
268
diff
changeset
|
152 |
self.img_prefix = img_root_prefix |
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
153 |
self.imgdir = os.path.join(d, self.img_prefix) |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
154 |
self.attrs["Build-Release"] = "5.11" |
26 | 155 |
return |
156 |
||
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
157 |
# 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
|
158 |
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
|
159 |
d = os.path.normpath(os.path.join(d, os.path.pardir)) |
26 | 160 |
|
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
161 |
# 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
|
162 |
# 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
|
163 |
# |
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
164 |
# (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
|
165 |
if d == oldpath: |
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
166 |
raise ValueError, "directory %s not contained within an image" % startd |
26 | 167 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
168 |
def load_config(self): |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
169 |
"""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
|
170 |
location.""" |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
171 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
172 |
# 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
|
173 |
# configuration. |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
174 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
175 |
if self.root == None: |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
176 |
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
|
177 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
178 |
ic = imageconfig.ImageConfig() |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
179 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
180 |
if os.path.isfile("%s/cfg_cache" % self.imgdir): |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
181 |
ic.read("%s/cfg_cache" % self.imgdir) |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
182 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
183 |
self.cfg_cache = ic |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
184 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
185 |
# 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
|
186 |
# operation. |
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
187 |
def mkdirs(self): |
30 | 188 |
if not os.path.isdir(self.imgdir + "/catalog"): |
189 |
os.makedirs(self.imgdir + "/catalog") |
|
190 |
if not os.path.isdir(self.imgdir + "/file"): |
|
191 |
os.makedirs(self.imgdir + "/file") |
|
192 |
if not os.path.isdir(self.imgdir + "/pkg"): |
|
193 |
os.makedirs(self.imgdir + "/pkg") |
|
60
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
194 |
if not os.path.isdir(self.imgdir + "/index"): |
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
195 |
os.makedirs(self.imgdir + "/index") |
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
196 |
|
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
197 |
def set_attrs(self, type, root, is_zone, auth_name, auth_url, |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
198 |
ssl_key = None, ssl_cert = None): |
19 | 199 |
self.type = type |
22
379f0f6809ff
pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents:
19
diff
changeset
|
200 |
self.root = root |
379f0f6809ff
pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents:
19
diff
changeset
|
201 |
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
|
202 |
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
|
203 |
else: |
271
ec8a7669bff2
659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
268
diff
changeset
|
204 |
self.img_prefix = img_root_prefix |
ec8a7669bff2
659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
268
diff
changeset
|
205 |
self.imgdir = os.path.join(self.root, self.img_prefix) |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
206 |
self.mkdirs() |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
207 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
208 |
self.cfg_cache = imageconfig.ImageConfig() |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
209 |
|
111 | 210 |
if is_zone: |
211 |
self.cfg_cache.filters["opensolaris.zone"] = "nonglobal" |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
212 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
213 |
self.cfg_cache.authorities[auth_name] = {} |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
214 |
self.cfg_cache.authorities[auth_name]["prefix"] = auth_name |
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
215 |
self.cfg_cache.authorities[auth_name]["origin"] = \ |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
216 |
misc.url_affix_trailing_slash(auth_url) |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
217 |
self.cfg_cache.authorities[auth_name]["mirrors"] = [] |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
218 |
self.cfg_cache.authorities[auth_name]["ssl_key"] = ssl_key |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
219 |
self.cfg_cache.authorities[auth_name]["ssl_cert"] = ssl_cert |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
220 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
221 |
self.cfg_cache.preferred_authority = auth_name |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
222 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
223 |
self.cfg_cache.write("%s/cfg_cache" % self.imgdir) |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
224 |
|
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
225 |
def is_liveroot(self): |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
226 |
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
|
227 |
|
344
4c887185d780
528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents:
342
diff
changeset
|
228 |
def is_zone(self): |
4c887185d780
528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents:
342
diff
changeset
|
229 |
zone = self.cfg_cache.filters.get("opensolaris.zone", "") |
4c887185d780
528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents:
342
diff
changeset
|
230 |
return zone == "nonglobal" |
4c887185d780
528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents:
342
diff
changeset
|
231 |
|
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
232 |
def get_root(self): |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
233 |
return self.root |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
234 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
235 |
def gen_authorities(self): |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
236 |
if not self.cfg_cache: |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
237 |
raise RuntimeError, "empty ImageConfig" |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
238 |
if not self.cfg_cache.authorities: |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
239 |
raise RuntimeError, "no defined authorities" |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
240 |
for a in self.cfg_cache.authorities: |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
241 |
yield self.cfg_cache.authorities[a] |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
242 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
243 |
def get_url_by_authority(self, authority = None): |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
244 |
"""Return the URL prefix associated with the given authority. |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
245 |
For the undefined case, represented by None, return the |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
246 |
preferred authority.""" |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
247 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
248 |
# 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
|
249 |
# 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
|
250 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
251 |
if authority == None: |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
252 |
authority = self.cfg_cache.preferred_authority |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
253 |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
254 |
try: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
255 |
o = self.cfg_cache.authorities[authority]["origin"] |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
256 |
except KeyError: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
257 |
# If the authority that we're trying to get no longer |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
258 |
# exists, fall back to preferred authority. |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
259 |
authority = self.cfg_cache.preferred_authority |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
260 |
o = self.cfg_cache.authorities[authority]["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
|
261 |
|
146
9b9fcd56b8b2
Reduce use of the re module, for performance.
Danek Duvall <danek.duvall@sun.com>
parents:
145
diff
changeset
|
262 |
return o.rstrip("/") |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
263 |
|
322
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
264 |
def get_ssl_credentials(self, authority = None, origin = None): |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
265 |
"""Return a tuple containing (ssl_key, ssl_cert) for the |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
266 |
specified authority prefix. If the authority isn't specified, |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
267 |
attempt to determine the authority by the given origin. If |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
268 |
neither is specified, use the preferred authority. |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
269 |
""" |
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
270 |
|
322
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
271 |
if authority is None: |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
272 |
if origin is None: |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
273 |
authority = self.cfg_cache.preferred_authority |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
274 |
else: |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
275 |
auths = self.cfg_cache.authorities |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
276 |
for pfx, auth in auths.iteritems(): |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
277 |
if auth["origin"] == origin: |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
278 |
authority = pfx |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
279 |
break |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
280 |
else: |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
281 |
return None |
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
282 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
283 |
try: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
284 |
authent = self.cfg_cache.authorities[authority] |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
285 |
except KeyError: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
286 |
authority = self.cfg_cache.preferred_authority |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
287 |
authent = self.cfg_cache.authorities[authority] |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
288 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
289 |
return (authent["ssl_key"], authent["ssl_cert"]) |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
290 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
291 |
def get_default_authority(self): |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
292 |
return self.cfg_cache.preferred_authority |
19 | 293 |
|
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
294 |
def has_authority(self, auth_name): |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
295 |
return auth_name in self.cfg_cache.authorities |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
296 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
297 |
def delete_authority(self, auth_name): |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
298 |
if not self.has_authority(auth_name): |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
299 |
raise KeyError, "no such authority '%s'" % auth_name |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
300 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
301 |
self.cfg_cache.delete_authority(auth_name) |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
302 |
self.cfg_cache.write("%s/cfg_cache" % self.imgdir) |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
303 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
304 |
def get_authority(self, auth_name): |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
305 |
if not self.has_authority(auth_name): |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
306 |
raise KeyError, "no such authority '%s'" % auth_name |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
307 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
308 |
return self.cfg_cache.authorities[auth_name] |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
309 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
310 |
def split_authority(self, auth): |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
311 |
prefix = auth["prefix"] |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
312 |
update_dt = None |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
313 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
314 |
try: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
315 |
cat = self.catalogs[prefix] |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
316 |
except KeyError: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
317 |
cat = None |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
318 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
319 |
if cat: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
320 |
update_dt = cat.last_modified() |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
321 |
if update_dt: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
322 |
update_dt = catalog.ts_to_datetime(update_dt) |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
323 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
324 |
return (prefix, auth["origin"], auth["ssl_key"], |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
325 |
auth["ssl_cert"], update_dt) |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
326 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
327 |
def set_preferred_authority(self, auth_name): |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
328 |
if not self.has_authority(auth_name): |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
329 |
raise KeyError, "no such authority '%s'" % auth_name |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
330 |
self.cfg_cache.preferred_authority = auth_name |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
331 |
self.cfg_cache.write("%s/cfg_cache" % self.imgdir) |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
332 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
333 |
def set_authority(self, auth_name, origin_url = None, ssl_key = None, |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
334 |
ssl_cert = None, mirrors = []): |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
335 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
336 |
auths = self.cfg_cache.authorities |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
337 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
338 |
if auth_name in auths: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
339 |
# If authority already exists, only update non-NULL |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
340 |
# values passed to set_authority |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
341 |
if origin_url: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
342 |
auths[auth_name]["origin"] = \ |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
343 |
misc.url_affix_trailing_slash(origin_url) |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
344 |
if ssl_key: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
345 |
auths[auth_name]["ssl_key"] = ssl_key |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
346 |
if ssl_cert: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
347 |
auths[auth_name]["ssl_cert"] = ssl_cert |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
348 |
if mirrors: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
349 |
auths[auth_name]["mirrors"] = mirrors |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
350 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
351 |
else: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
352 |
auths[auth_name] = {} |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
353 |
auths[auth_name]["prefix"] = auth_name |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
354 |
auths[auth_name]["origin"] = \ |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
355 |
misc.url_affix_trailing_slash(origin_url) |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
356 |
auths[auth_name]["mirrors"] = mirrors |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
357 |
auths[auth_name]["ssl_key"] = ssl_key |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
358 |
auths[auth_name]["ssl_cert"] = ssl_cert |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
359 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
360 |
self.cfg_cache.write("%s/cfg_cache" % self.imgdir) |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
361 |
|
161
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
362 |
def get_matching_fmris(self, patterns, matcher = None, |
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
363 |
constraint = None, counthash = None): |
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
364 |
"""Iterate through all catalogs, looking for packages matching |
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
365 |
'pattern', based on the function in 'matcher' and the versioning |
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
366 |
constraint described by 'constraint'. If 'matcher' is None, |
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
367 |
uses fmri subset matching as the default. Returns a list of |
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
368 |
(catalog, fmri) pairs. If 'counthash' is a dictionary, instead |
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
369 |
store the number of matched fmris for each package name which |
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
370 |
was matched.""" |
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
371 |
|
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
372 |
# XXX Do we want to recognize regex (some) metacharacters and |
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
373 |
# switch automatically to the regex matcher? |
221
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
374 |
|
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
375 |
# XXX If the patterns contain an authority, we could reduce the |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
376 |
# number of catalogs searched by only looking at catalogs whose |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
377 |
# authorities match FMRIs in the pattern. |
34
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
378 |
|
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
379 |
# Check preferred authority first, if package isn't found here, |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
380 |
# then check all authorities. |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
381 |
|
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
382 |
cat = self.catalogs[self.cfg_cache.preferred_authority] |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
383 |
|
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
384 |
m = cat.get_matching_fmris(patterns, matcher, |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
385 |
constraint, counthash) |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
386 |
|
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
387 |
for k, c in self.catalogs.items(): |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
388 |
if k == self.cfg_cache.preferred_authority: |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
389 |
continue |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
390 |
m.extend(c.get_matching_fmris(patterns, matcher, |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
391 |
constraint, counthash)) |
69
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
392 |
|
221
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
393 |
ips = [ ip for ip in self.gen_installed_pkgs() if ip not in m ] |
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
394 |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
395 |
m.extend(catalog.extract_matching_fmris(ips, patterns, |
221
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
396 |
matcher, constraint, counthash)) |
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
397 |
|
69
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
398 |
if not m: |
221
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
399 |
raise KeyError, "packages matching '%s' not found in catalog or image" \ |
161
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
400 |
% patterns |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
401 |
|
50 | 402 |
return m |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
403 |
|
235
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
404 |
def verify(self, fmri, progresstracker, **args): |
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
405 |
""" generator that returns any errors in installed pkgs |
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
406 |
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
|
407 |
|
235
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
408 |
for act in self.get_manifest(fmri, filtered = True).actions: |
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
409 |
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
|
410 |
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
|
411 |
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
|
412 |
if errors: |
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
413 |
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
|
414 |
errors) |
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
415 |
yield (actname, 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
|
416 |
|
237
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
417 |
def gen_installed_actions(self): |
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
418 |
""" generates actions in installed image """ |
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
419 |
|
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
420 |
for fmri in self.gen_installed_pkgs(): |
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
|
421 |
for act in self.get_manifest(fmri, filtered = True).actions: |
237
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
422 |
yield act |
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
423 |
|
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
424 |
def get_link_actions(self): |
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
|
425 |
""" return a dictionary of hardlink action lists indexed by |
237
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
426 |
target """ |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
427 |
if self.link_actions != None: |
237
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
428 |
return self.link_actions |
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
429 |
|
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
|
430 |
d = {} |
237
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
431 |
for act in self.gen_installed_actions(): |
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
432 |
if act.name == "hardlink": |
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
433 |
t = act.get_target_path() |
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
434 |
if t in d: |
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
435 |
d[t].append(act) |
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
436 |
else: |
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
437 |
d[t] = [act] |
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
438 |
self.link_actions = d |
6ece196588cb
348 files that move from pkg to pkg can cause problems during upgrade
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
235
diff
changeset
|
439 |
return d |
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
|
440 |
|
50 | 441 |
def has_manifest(self, fmri): |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
442 |
mpath = fmri.get_dir_path() |
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
443 |
|
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
444 |
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
|
445 |
|
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
446 |
if (os.path.exists(local_mpath)): |
50 | 447 |
return True |
448 |
||
449 |
return False |
|
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
450 |
|
329 | 451 |
def _fetch_manifest(self, fmri): |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
452 |
"""Perform steps necessary to get manifest from remote host |
329 | 453 |
and write resulting contents to disk. Helper routine for |
454 |
get_manifest. Does not filter the results, caller must do |
|
455 |
that. """ |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
456 |
|
50 | 457 |
m = manifest.Manifest() |
315
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
458 |
m.set_fmri(self, fmri) |
72
9deed41412b3
Support for proper package upgrade.
Danek Duvall <danek.duvall@sun.com>
parents:
69
diff
changeset
|
459 |
|
144
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
460 |
fmri_dir_path = os.path.join(self.imgdir, "pkg", |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
461 |
fmri.get_dir_path()) |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
462 |
mpath = os.path.join(fmri_dir_path, "manifest") |
315
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
463 |
ipath = os.path.join(fmri_dir_path, "index") |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
464 |
|
315
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
465 |
# Get manifest as a string from the remote host, then build |
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
466 |
# it up into an in-memory manifest, then write the finished |
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
467 |
# representation to disk. |
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
468 |
mcontent = retrieve.get_manifest(self, fmri) |
50 | 469 |
m.set_content(mcontent) |
144
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
470 |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
471 |
# Write the originating authority into the manifest. |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
472 |
# Manifests prior to this change won't contain this information. |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
473 |
# In that case, the client attempts to re-download the manifest |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
474 |
# from the depot. |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
475 |
if not fmri.has_authority(): |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
476 |
m["authority"] = self.get_default_authority() |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
477 |
else: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
478 |
m["authority"] = fmri.get_authority() |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
479 |
|
341
42383445191b
1144 "pkg list -as" fails when unable to write to the pkg directory
Danek Duvall <danek.duvall@sun.com>
parents:
340
diff
changeset
|
480 |
try: |
42383445191b
1144 "pkg list -as" fails when unable to write to the pkg directory
Danek Duvall <danek.duvall@sun.com>
parents:
340
diff
changeset
|
481 |
m.store(mpath, ipath) |
347
d3768c3508b2
1397 fix for 1144 incomplete
Danek Duvall <danek.duvall@sun.com>
parents:
344
diff
changeset
|
482 |
except EnvironmentError, e: |
341
42383445191b
1144 "pkg list -as" fails when unable to write to the pkg directory
Danek Duvall <danek.duvall@sun.com>
parents:
340
diff
changeset
|
483 |
if e.errno not in (errno.EROFS, errno.EACCES): |
42383445191b
1144 "pkg list -as" fails when unable to write to the pkg directory
Danek Duvall <danek.duvall@sun.com>
parents:
340
diff
changeset
|
484 |
raise |
144
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
485 |
|
50 | 486 |
return m |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
487 |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
488 |
def _valid_manifest(self, fmri, manifest): |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
489 |
"""Check authority attached to manifest. Make sure |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
490 |
it matches authority specified in FMRI.""" |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
491 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
492 |
authority = fmri.get_authority() |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
493 |
if not authority: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
494 |
authority = self.get_default_authority() |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
495 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
496 |
if not "authority" in manifest: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
497 |
return False |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
498 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
499 |
if manifest["authority"] != authority: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
500 |
return False |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
501 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
502 |
return True |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
503 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
504 |
def get_manifest(self, fmri, filtered = False): |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
505 |
"""Find on-disk manifest and create in-memory Manifest |
329 | 506 |
object, applying appropriate filters as needed.""" |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
507 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
508 |
m = manifest.Manifest() |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
509 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
510 |
fmri_dir_path = os.path.join(self.imgdir, "pkg", |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
511 |
fmri.get_dir_path()) |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
512 |
mpath = os.path.join(fmri_dir_path, "manifest") |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
513 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
514 |
# If the manifest isn't there, download. |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
515 |
if not os.path.exists(mpath): |
329 | 516 |
m = self._fetch_manifest(fmri) |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
517 |
else: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
518 |
mcontent = file(mpath).read() |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
519 |
m.set_fmri(self, fmri) |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
520 |
m.set_content(mcontent) |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
521 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
522 |
# If the manifest isn't from the correct authority, or |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
523 |
# no authority is attached to the manifest, download a new one. |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
524 |
if not self._valid_manifest(fmri, m): |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
525 |
try: |
329 | 526 |
m = self._fetch_manifest(fmri) |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
527 |
except NameError: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
528 |
# In thise case, the client has failed to |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
529 |
# download a new manifest with the same name. |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
530 |
# We can either give up or drive on. It makes |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
531 |
# the most sense to do the best we can with what |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
532 |
# we have. Keep the old manifest and drive on. |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
533 |
pass |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
534 |
|
329 | 535 |
# XXX perhaps all of the below should live in Manifest.filter()? |
536 |
if filtered: |
|
537 |
filters = [] |
|
538 |
try: |
|
539 |
f = file("%s/filters" % fmri_dir_path, "r") |
|
540 |
except IOError, e: |
|
541 |
if e.errno != errno.ENOENT: |
|
542 |
raise |
|
543 |
else: |
|
544 |
filters = [ |
|
545 |
(l.strip(), compile( |
|
546 |
l.strip(), "<filter string>", "eval")) |
|
547 |
for l in f.readlines() |
|
548 |
] |
|
549 |
m.filter(filters) |
|
550 |
||
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
551 |
return m |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
552 |
|
331
4f332d6b4036
1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents:
329
diff
changeset
|
553 |
def installed_file_authority(self, filepath): |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
554 |
"""Find the pkg's installed file named by filepath. |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
555 |
Return the authority that installed this package.""" |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
556 |
|
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
557 |
read_only = False |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
558 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
559 |
try: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
560 |
f = file(filepath, "r+") |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
561 |
except IOError, e: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
562 |
if e.errno == errno.EACCES or e.errno == errno.EROFS: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
563 |
read_only = True |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
564 |
else: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
565 |
raise |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
566 |
if read_only: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
567 |
f = file(filepath, "r") |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
568 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
569 |
flines = f.readlines() |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
570 |
newauth = None |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
571 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
572 |
try: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
573 |
version, auth = flines |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
574 |
except ValueError: |
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
575 |
# If we get a ValueError, we've encoutered an |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
576 |
# 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
|
577 |
# 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
|
578 |
# to assume that the package was installed from |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
579 |
# the preferred authority. Here, we set up |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
580 |
# the authority to record that. |
356
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
581 |
if flines: |
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
582 |
auth = flines[0] |
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
583 |
auth = auth.strip() |
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
584 |
newauth = "%s_%s" % (pkg.fmri.PREF_AUTH_PFX, |
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
585 |
auth) |
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
586 |
else: |
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
587 |
newauth = "%s_%s" % (pkg.fmri.PREF_AUTH_PFX, |
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
588 |
self.get_default_authority()) |
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
589 |
|
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
590 |
# Exception handler is only part of this code that |
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
591 |
# sets newauth |
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
592 |
auth = newauth |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
593 |
|
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
594 |
if newauth and not read_only: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
595 |
# This is where we actually update the installed |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
596 |
# file with the new authority. |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
597 |
f.seek(0) |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
598 |
f.writelines(["VERSION_1\n", newauth]) |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
599 |
|
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
600 |
f.close() |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
601 |
|
356
672e0af33ea8
1536 empty installed files generate tracebacks
johansen <johansen@sun.com>
parents:
347
diff
changeset
|
602 |
assert auth |
331
4f332d6b4036
1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents:
329
diff
changeset
|
603 |
|
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
604 |
return auth |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
605 |
|
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
606 |
def install_file_present(self, fmri): |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
607 |
"""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
|
608 |
on the system. Otherwise, returns false.""" |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
609 |
|
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
610 |
return os.path.exists("%s/pkg/%s/installed" % (self.imgdir, |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
611 |
fmri.get_dir_path())) |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
612 |
|
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
613 |
def add_install_file(self, fmri): |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
614 |
"""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
|
615 |
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
|
616 |
installed.""" |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
617 |
|
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
618 |
f = file("%s/pkg/%s/installed" % (self.imgdir, |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
619 |
fmri.get_dir_path()), "w") |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
620 |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
621 |
f.writelines(["VERSION_1\n", fmri.get_authority_str()]) |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
622 |
f.close() |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
623 |
|
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
624 |
def remove_install_file(self, fmri): |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
625 |
"""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
|
626 |
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
|
627 |
installed.""" |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
628 |
|
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
629 |
os.unlink("%s/pkg/%s/installed" % (self.imgdir, |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
630 |
fmri.get_dir_path())) |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
631 |
|
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
632 |
def _get_version_installed(self, pfmri): |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
633 |
pd = pfmri.get_pkg_stem() |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
634 |
pdir = "%s/pkg/%s" % (self.imgdir, |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
635 |
pfmri.get_dir_path(stemonly = True)) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
636 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
637 |
try: |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
638 |
pkgs_inst = [ (urllib.unquote("%s@%s" % (pd, vd)), |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
639 |
"%s/%s/installed" % (pdir, vd)) |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
640 |
for vd in os.listdir(pdir) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
641 |
if os.path.exists("%s/%s/installed" % (pdir, vd)) ] |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
642 |
except OSError: |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
643 |
return None |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
644 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
645 |
if len(pkgs_inst) == 0: |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
646 |
return None |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
647 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
648 |
assert len(pkgs_inst) <= 1 |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
649 |
|
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
650 |
auth = self.installed_file_authority(pkgs_inst[0][1]) |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
651 |
|
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
652 |
return pkg.fmri.PkgFmri(pkgs_inst[0][0], authority = auth) |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
653 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
654 |
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
|
655 |
"""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
|
656 |
|
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
657 |
if self.install_file_present(pfmri): |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
658 |
return "installed" |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
659 |
|
106
ed11fcd45545
pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents:
104
diff
changeset
|
660 |
return "known" |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
661 |
|
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
662 |
def fmri_set_default_authority(self, fmri): |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
663 |
"""If the FMRI supplied as an argument does not have |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
664 |
an authority, set it to the image's preferred authority.""" |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
665 |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
666 |
if fmri.has_authority(): |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
667 |
return |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
668 |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
669 |
fmri.set_authority(self.get_default_authority(), True) |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
670 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
671 |
def get_catalog(self, fmri, exception = False): |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
672 |
"""Given a FMRI, look at the authority and return the |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
673 |
correct catalog for this image.""" |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
674 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
675 |
# If FMRI has no authority, or is default authority, |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
676 |
# then return the catalog for the preferred authority |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
677 |
if not fmri.has_authority() or fmri.preferred_authority(): |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
678 |
cat = self.catalogs[self.get_default_authority()] |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
679 |
else: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
680 |
try: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
681 |
cat = self.catalogs[fmri.get_authority()] |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
682 |
except KeyError: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
683 |
# If the authority that installed this package |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
684 |
# has vanished, pick the default authority |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
685 |
# instead. |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
686 |
if exception: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
687 |
raise |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
688 |
else: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
689 |
cat = self.catalogs[\ |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
690 |
self.get_default_authority()] |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
691 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
692 |
return cat |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
693 |
|
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
|
694 |
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
|
695 |
"""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
|
696 |
installed in the current image.""" |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
697 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
698 |
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
|
699 |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
700 |
if v and not fmri.has_authority(): |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
701 |
fmri.set_authority(v.get_authority_str()) |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
702 |
elif not fmri.has_authority(): |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
703 |
fmri.set_authority(self.get_default_authority(), True) |
266
5e5bff6fedce
582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents:
260
diff
changeset
|
704 |
|
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
705 |
if v and self.fmri_is_successor(v, fmri): |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
706 |
return True |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
707 |
else: |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
708 |
try: |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
709 |
cat = self.get_catalog(fmri, exception = True) |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
710 |
except KeyError: |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
711 |
return False |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
712 |
|
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
713 |
# 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
|
714 |
# packages that are equivalent to fmri. |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
715 |
rpkgs = cat.rename_newer_pkgs(fmri) |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
716 |
for f in rpkgs: |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
717 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
718 |
v = self._get_version_installed(f) |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
719 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
720 |
if v and self.fmri_is_successor(v, fmri): |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
721 |
return True |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
722 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
723 |
return False |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
724 |
|
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
725 |
def older_version_installed(self, fmri): |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
726 |
"""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
|
727 |
older version of the package is installed. This takes |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
728 |
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
|
729 |
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
|
730 |
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
|
731 |
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
|
732 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
733 |
v = self._get_version_installed(fmri) |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
734 |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
735 |
assert fmri.has_authority() |
268
3d53da66d4a4
582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents:
266
diff
changeset
|
736 |
|
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
737 |
if v: |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
738 |
return v |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
739 |
else: |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
740 |
cat = self.get_catalog(fmri) |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
741 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
742 |
rpkgs = cat.rename_older_pkgs(fmri) |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
743 |
for f in rpkgs: |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
744 |
v = self._get_version_installed(f) |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
745 |
if v and self.fmri_is_successor(fmri, v): |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
746 |
return v |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
747 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
748 |
return None |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
749 |
|
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
|
750 |
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
|
751 |
"""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
|
752 |
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
|
753 |
|
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
754 |
# All FMRIs passed to is_installed shall have an authority |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
755 |
assert fmri.has_authority() |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
756 |
|
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
757 |
v = self._get_version_installed(fmri) |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
758 |
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
|
759 |
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
|
760 |
|
a1e20e9a9845
add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents:
116
diff
changeset
|
761 |
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
|
762 |
|
67
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
763 |
def get_dependents(self, pfmri): |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
764 |
"""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
|
765 |
FMRI.""" |
67
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
766 |
|
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
767 |
thedir = os.path.join(self.imgdir, "index", "depend", |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
768 |
urllib.quote(str(pfmri.get_pkg_stem())[5:], "")) |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
769 |
|
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
770 |
if not os.path.isdir(thedir): |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
771 |
return [] |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
772 |
|
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
773 |
for v in os.listdir(thedir): |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
774 |
f = pkg.fmri.PkgFmri(pfmri.get_pkg_stem() + "@" + v, |
67
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
775 |
self.attrs["Build-Release"]) |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
776 |
if self.fmri_is_successor(pfmri, f): |
67
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
777 |
dependents = [ |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
778 |
urllib.unquote(d) |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
779 |
for d in os.listdir(os.path.join(thedir, v)) |
139
1861fdf62519
on uninstall, don't complain about uninstalled dependents
Danek Duvall <danek.duvall@sun.com>
parents:
135
diff
changeset
|
780 |
if os.path.exists( |
1861fdf62519
on uninstall, don't complain about uninstalled dependents
Danek Duvall <danek.duvall@sun.com>
parents:
135
diff
changeset
|
781 |
os.path.join(thedir, v, d, "installed")) |
67
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
782 |
] |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
783 |
|
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
784 |
return dependents |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
785 |
|
215
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
786 |
def retrieve_catalogs(self, full_refresh = False): |
201
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
787 |
failed = [] |
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
788 |
total = 0 |
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
789 |
succeeded = 0 |
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
790 |
cat = None |
215
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
791 |
ts = 0 |
201
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
792 |
|
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
793 |
for auth in self.gen_authorities(): |
201
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
794 |
total += 1 |
215
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
795 |
|
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
796 |
if auth["prefix"] in self.catalogs: |
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
797 |
cat = self.catalogs[auth["prefix"]] |
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
798 |
ts = cat.last_modified() |
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
799 |
|
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
800 |
# Although we may have a catalog with a |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
801 |
# timestamp, the user may have changed the |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
802 |
# origin URL for the authority. If this has |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
803 |
# occurred, we need to perform a full refresh. |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
804 |
if cat.origin() != auth["origin"]: |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
805 |
full_refresh = True |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
806 |
|
215
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
807 |
if ts and not full_refresh: |
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
808 |
hdr = {'If-Modified-Since': ts} |
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
809 |
else: |
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
810 |
hdr = {} |
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
811 |
|
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
812 |
ssl_tuple = self.get_ssl_credentials(auth["prefix"]) |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
813 |
|
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
814 |
# XXX Mirror selection and retrieval policy? |
235
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
815 |
try: |
201
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
816 |
c, v = versioned_urlopen(auth["origin"], |
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
817 |
"catalog", [0], ssl_creds = ssl_tuple, |
319
39b8b5c538bf
1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents:
316
diff
changeset
|
818 |
headers = hdr, imgtype = self.type) |
215
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
819 |
except urllib2.HTTPError, e: |
260
a1b77322abb2
255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents:
259
diff
changeset
|
820 |
# Server returns NOT_MODIFIED if catalog is up |
a1b77322abb2
255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents:
259
diff
changeset
|
821 |
# to date |
a1b77322abb2
255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents:
259
diff
changeset
|
822 |
if e.code == httplib.NOT_MODIFIED: |
215
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
823 |
succeeded += 1 |
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
824 |
else: |
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
825 |
failed.append((auth, e)) |
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
826 |
continue |
c10719939c6d
245 Need incremental update mechanism for the catalog
johansen <johansen@sun.com>
parents:
208
diff
changeset
|
827 |
|
201
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
828 |
except urllib2.URLError, e: |
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
829 |
failed.append((auth, e)) |
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
830 |
continue |
285
538afd6a9d3e
763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents:
281
diff
changeset
|
831 |
except ValueError, e: |
538afd6a9d3e
763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents:
281
diff
changeset
|
832 |
failed.append((auth, e)) |
538afd6a9d3e
763 pkg image-create /foo , pkg image-create /tmp/foo both yield (different) tracebacks
Danek Duvall <danek.duvall@sun.com>
parents:
281
diff
changeset
|
833 |
continue |
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
|
834 |
|
157
504b9e6d213c
Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents:
146
diff
changeset
|
835 |
# root for this catalog |
504b9e6d213c
Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents:
146
diff
changeset
|
836 |
croot = "%s/catalog/%s" % (self.imgdir, auth["prefix"]) |
504b9e6d213c
Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents:
146
diff
changeset
|
837 |
|
201
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
838 |
try: |
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
839 |
updatelog.recv(c, croot, ts, auth) |
201
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
840 |
except IOError, e: |
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
841 |
failed.append((auth, e)) |
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
842 |
else: |
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
843 |
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
|
844 |
|
201
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
845 |
if failed: |
63e78f600aa7
185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents:
195
diff
changeset
|
846 |
raise RuntimeError, (failed, total, 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
|
847 |
|
235
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
848 |
def load_catalogs(self, progresstracker): |
157
504b9e6d213c
Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents:
146
diff
changeset
|
849 |
for auth in self.gen_authorities(): |
504b9e6d213c
Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents:
146
diff
changeset
|
850 |
croot = "%s/catalog/%s" % (self.imgdir, auth["prefix"]) |
235
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
851 |
progresstracker.catalog_start(auth["prefix"]) |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
852 |
if auth["prefix"] == self.cfg_cache.preferred_authority: |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
853 |
authpfx = "%s_%s" % (pkg.fmri.PREF_AUTH_PFX, |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
854 |
auth["prefix"]) |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
855 |
c = catalog.Catalog(croot, authority = authpfx) |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
856 |
else: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
857 |
c = catalog.Catalog(croot, |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
858 |
authority = auth["prefix"]) |
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
859 |
self.catalogs[auth["prefix"]] = c |
235
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
860 |
progresstracker.catalog_done() |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
861 |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
862 |
def fmri_is_same_pkg(self, cfmri, pfmri): |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
863 |
"""Determine whether fmri and pfmri share the same package |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
864 |
name, even if they're not equivalent versions. This |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
865 |
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
|
866 |
the same because of a rename operation.""" |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
867 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
868 |
# If authorities don't match, this can't be a successor |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
869 |
if not pkg.fmri.is_same_authority(cfmri.authority, pfmri.authority): |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
870 |
return False |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
871 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
872 |
# 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
|
873 |
# 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
|
874 |
# rename. |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
875 |
if cfmri.is_same_pkg(pfmri): |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
876 |
return True |
329 | 877 |
|
878 |
# Get the catalog for the correct authority |
|
879 |
cat = self.get_catalog(cfmri) |
|
880 |
return cat.rename_is_same_pkg(cfmri, pfmri) |
|
881 |
||
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
882 |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
883 |
def fmri_is_successor(self, cfmri, pfmri): |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
884 |
"""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
|
885 |
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
|
886 |
package is a successor. This routine takes two FMRIs, and |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
887 |
if they have the same authority, checks if they've been |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
888 |
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
|
889 |
routine from the catalog. Otherwise, this runs the standard |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
890 |
fmri.is_successor() code.""" |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
891 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
892 |
# If authorities don't match, this can't be a successor |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
893 |
if not pkg.fmri.is_same_authority(cfmri.authority, pfmri.authority): |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
894 |
return False |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
895 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
896 |
# Get the catalog for the correct authority |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
897 |
cat = self.get_catalog(cfmri) |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
898 |
|
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
899 |
# 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
|
900 |
# 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
|
901 |
# rename. |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
902 |
if cfmri.is_successor(pfmri): |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
903 |
return True |
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
904 |
else: |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
905 |
return cat.rename_is_successor(cfmri, pfmri) |
258
b3b7592412ec
270 Need ability to rename packages
johansen <johansen@sun.com>
parents:
251
diff
changeset
|
906 |
|
157
504b9e6d213c
Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents:
146
diff
changeset
|
907 |
def gen_known_package_fmris(self): |
221
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
908 |
"""Generate the list of known packages, being the union of the |
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
909 |
catalogs and the installed image.""" |
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
910 |
|
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
911 |
li = [ x for x in self.gen_installed_pkgs() ] |
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
912 |
|
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
913 |
# Generate those packages in the set of catalogs. |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
914 |
for c in self.catalogs.values(): |
157
504b9e6d213c
Catalog should be on-disk instead of in memory
johansen <johansen@sun.com>
parents:
146
diff
changeset
|
915 |
for pf in c.fmris(): |
221
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
916 |
if pf in li: |
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
917 |
li.remove(pf) |
106
ed11fcd45545
pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents:
104
diff
changeset
|
918 |
yield pf |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
919 |
|
221
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
920 |
def gen_installed_pkgs(self): |
315
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
921 |
if self.installed_pkg_cache is not None: |
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
922 |
return iter(self.installed_pkg_cache) |
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
923 |
else: |
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
924 |
return self.gen_installed_pkgs_forreal() |
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
925 |
|
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
926 |
def gen_installed_pkgs_forreal(self): |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
927 |
proot = "%s/pkg" % self.imgdir |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
928 |
|
315
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
929 |
self.installed_pkg_cache = [] |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
930 |
for pd in sorted(os.listdir(proot)): |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
931 |
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
|
932 |
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
|
933 |
if not os.path.exists(path): |
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
934 |
continue |
226
8939051a496c
376 image must use default authority when none specified
johansen <johansen@sun.com>
parents:
222
diff
changeset
|
935 |
|
331
4f332d6b4036
1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents:
329
diff
changeset
|
936 |
fmristr = urllib.unquote("%s@%s" % (pd, vd)) |
226
8939051a496c
376 image must use default authority when none specified
johansen <johansen@sun.com>
parents:
222
diff
changeset
|
937 |
auth = self.installed_file_authority(path) |
331
4f332d6b4036
1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents:
329
diff
changeset
|
938 |
f = pkg.fmri.PkgFmri(fmristr, authority = auth) |
226
8939051a496c
376 image must use default authority when none specified
johansen <johansen@sun.com>
parents:
222
diff
changeset
|
939 |
|
315
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
940 |
self.installed_pkg_cache.append(f) |
989c801f050b
1076 action __cmp__, action __str__ and manifest loading could all be faster
Dan Price <dp@eng.sun.com>
parents:
313
diff
changeset
|
941 |
yield f |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
942 |
|
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
943 |
def strtofmri(self, myfmri): |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
944 |
ret = pkg.fmri.PkgFmri(myfmri, |
331
4f332d6b4036
1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents:
329
diff
changeset
|
945 |
self.attrs["Build-Release"]) |
4f332d6b4036
1266 Client loses track of authority preference, chaos ensues
johansen <johansen@sun.com>
parents:
329
diff
changeset
|
946 |
|
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
947 |
return ret |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
948 |
|
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
949 |
def update_optional_dependency(self, inputfmri): |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
950 |
"""Updates pkgname to min fmri mapping if fmri is newer""" |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
951 |
|
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
952 |
myfmri = inputfmri |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
953 |
|
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
954 |
if isinstance(myfmri, str): |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
955 |
name = pkg.fmri.extract_pkg_name(myfmri) |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
956 |
myfmri = self.strtofmri(myfmri) |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
957 |
else: |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
958 |
name = myfmri.get_name() |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
959 |
|
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
960 |
ofmri = self.optional_dependencies.get(name, None) |
316
d6ba58c63264
1039 circular dependency in packages is detected at install-time
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
315
diff
changeset
|
961 |
if not ofmri or self.fmri_is_successor(myfmri, ofmri): |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
962 |
self.optional_dependencies[name] = myfmri |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
963 |
|
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
964 |
def apply_optional_dependencies(self, myfmri): |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
965 |
"""Updates an fmri if optional dependencies require a newer version. |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
966 |
Doesn't handle catalog renames... to ease programming for now, |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
967 |
unversioned fmris are returned upgraded""" |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
968 |
|
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
969 |
if isinstance(myfmri, str): |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
970 |
name = pkg.fmri.extract_pkg_name(myfmri) |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
971 |
myfmri = self.strtofmri(myfmri) |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
972 |
else: |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
973 |
name = myfmri.get_name() |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
974 |
|
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
975 |
minfmri = self.optional_dependencies.get(name, None) |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
976 |
if not minfmri: |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
977 |
return myfmri |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
978 |
|
316
d6ba58c63264
1039 circular dependency in packages is detected at install-time
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
315
diff
changeset
|
979 |
if self.fmri_is_successor(minfmri, myfmri): |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
980 |
return minfmri |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
981 |
return myfmri |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
982 |
|
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
983 |
def load_optional_dependencies(self): |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
984 |
for fmri in self.gen_installed_pkgs(): |
342
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
341
diff
changeset
|
985 |
mfst = self.get_manifest(fmri, filtered = True) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
341
diff
changeset
|
986 |
|
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
341
diff
changeset
|
987 |
for dep in mfst.gen_actions_by_type("depend"): |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
341
diff
changeset
|
988 |
required, min_fmri, max_fmri = dep.parse(self) |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
989 |
if required == False: |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
990 |
self.update_optional_dependency(min_fmri) |
195
b23d0425f0f7
11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents:
192
diff
changeset
|
991 |
|
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
992 |
def get_user_by_name(self, name): |
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
993 |
return portable.get_user_by_name(name, self.root, |
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
994 |
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
|
995 |
|
339
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
996 |
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
|
997 |
# 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
|
998 |
try: |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
999 |
return portable.get_name_by_uid(uid, self.root, |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
1000 |
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
|
1001 |
except KeyError: |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
1002 |
if returnuid: |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
1003 |
return uid |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
1004 |
else: |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
1005 |
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
|
1006 |
|
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
1007 |
def get_group_by_name(self, name): |
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
1008 |
return portable.get_group_by_name(name, self.root, |
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
1009 |
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
|
1010 |
|
339
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
1011 |
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
|
1012 |
try: |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
1013 |
return portable.get_name_by_gid(gid, self.root, |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
1014 |
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
|
1015 |
except KeyError: |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
1016 |
if returngid: |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
1017 |
return gid |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
1018 |
else: |
d8e57580599b
1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents:
331
diff
changeset
|
1019 |
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
|
1020 |
|
219
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1021 |
def gen_inventory(self, patterns, all_known=False): |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1022 |
"""Iterating the package inventory, yielding per-package info. |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
1023 |
|
219
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1024 |
Yielded data are of the form package,dict, where dict is: |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1025 |
state : package installation state |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1026 |
frozen, |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1027 |
incorporated, |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1028 |
excludes, |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1029 |
upgradable : Booleans indicating the aforementioned flags. |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1030 |
""" |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1031 |
pkgs_known = [] |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1032 |
badpats = [] |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
1033 |
|
219
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1034 |
if patterns: |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1035 |
for p in patterns: |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1036 |
try: |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1037 |
# XXX dp: not sure if this is |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1038 |
# right with respect to the code |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1039 |
# 6 or 7 lines further below. |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1040 |
for m in self.get_matching_fmris(p): |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1041 |
if all_known or self.is_installed(m): |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1042 |
pkgs_known.extend([ m ]) |
219
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1043 |
except KeyError: |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1044 |
badpats.append(p) |
221
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
1045 |
|
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
1046 |
pkgs_known.extend( |
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
1047 |
[ x for x in self.gen_installed_pkgs() |
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
1048 |
for p in patterns |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1049 |
if pkg.fmri.fmri_match(x.get_pkg_stem(), p) |
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
|
1050 |
and not x in pkgs_known ] ) |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
1051 |
else: |
221
e1dbb27a23b5
52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents:
219
diff
changeset
|
1052 |
pkgs_known = sorted(self.gen_installed_pkgs()) |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
1053 |
|
329 | 1054 |
counthash = {} |
1055 |
if pkgs_known: |
|
1056 |
# |
|
1057 |
# Walk the installed packages looking for those |
|
1058 |
# which have upgrades available. |
|
1059 |
# |
|
1060 |
self.get_matching_fmris(pkgs_known, |
|
1061 |
counthash = counthash) |
|
1062 |
||
1063 |
# |
|
1064 |
# If needed, merge in the rest of the known packages; we don't |
|
1065 |
# compute upgradability for those, since it's very expensive. |
|
1066 |
# |
|
1067 |
if all_known and not patterns: |
|
1068 |
pkgs_all_known = [ pf for pf in |
|
1069 |
self.gen_known_package_fmris() ] |
|
1070 |
pkgs_known += pkgs_all_known |
|
1071 |
pkgs_known = sorted(set(pkgs_known)) |
|
161
e0322fe7842c
Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents:
157
diff
changeset
|
1072 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
1073 |
for p in pkgs_known: |
329 | 1074 |
if counthash.get(p, 0) > 1: |
219
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1075 |
upgradable = True |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1076 |
else: |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1077 |
upgradable = False |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1078 |
inventory = { |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1079 |
"state": self.get_pkg_state_by_fmri(p), |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1080 |
"frozen": False, |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1081 |
"incorporated": False, |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1082 |
"excludes": False, |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1083 |
"upgradable": upgradable} |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1084 |
yield p, inventory |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
1085 |
|
219
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1086 |
if badpats: |
f303ff108edd
60 'pkg status does_not_exist' throws a traceback
Richard Lowe <richlowe@richlowe.net>
parents:
215
diff
changeset
|
1087 |
raise RuntimeError, badpats |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
1088 |
|
204
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1089 |
def local_search(self, args): |
144
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1090 |
"""Search the image for the token in args[0].""" |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1091 |
idxdir = os.path.join(self.imgdir, "pkg") |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1092 |
|
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1093 |
# Convert a full directory path to the FMRI it represents. |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1094 |
def idx_to_fmri(index): |
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1095 |
return pkg.fmri.PkgFmri(urllib.unquote(os.path.dirname( |
190
ca8aa1e0e90d
53 pkg search separates package name from version with "/", not "@"
Danek Duvall <danek.duvall@sun.com>
parents:
183
diff
changeset
|
1096 |
index[len(idxdir) + 1:]).replace("/", "@")), None) |
144
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1097 |
|
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1098 |
indices = ( |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1099 |
(os.path.join(dir, "index"), os.path.join(dir, "manifest")) |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1100 |
for dir, dirnames, filenames in os.walk(idxdir) |
163
eeacdf67f937
search only installed packages, and don't complain about unwriteable indices
Danek Duvall <danek.duvall@sun.com>
parents:
161
diff
changeset
|
1101 |
if "manifest" in filenames and "installed" in filenames |
144
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1102 |
) |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1103 |
|
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1104 |
for index, mfst in indices: |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1105 |
# Try loading the index; if that fails, try parsing the |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1106 |
# manifest. |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1107 |
try: |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1108 |
d = cPickle.load(file(index)) |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1109 |
except: |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1110 |
m = manifest.Manifest() |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1111 |
try: |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1112 |
mcontent = file(mfst).read() |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1113 |
except: |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1114 |
# XXX log something? |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1115 |
continue |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1116 |
m.set_content(mcontent) |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1117 |
try: |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1118 |
m.pickle(file(index, "wb")) |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1119 |
except: |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1120 |
pass |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1121 |
d = m.search_dict() |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1122 |
|
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1123 |
for k, v in d.items(): |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1124 |
if args[0] in v: |
302
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1125 |
# Yield the index name (such as |
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1126 |
# "basename", the fmri, and then |
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1127 |
# the "match results" which |
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1128 |
# include the action name and |
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1129 |
# the value of the key attribute |
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1130 |
try: |
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1131 |
yield k, idx_to_fmri(index), \ |
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1132 |
v[args[0]][0], v[args[0]][1] |
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1133 |
except TypeError: |
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1134 |
yield k, idx_to_fmri(index), \ |
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1135 |
"", "" |
144
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
1136 |
|
204
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1137 |
def remote_search(self, args, servers = None): |
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1138 |
"""Search for the token in args[0] on the servers in 'servers'. |
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1139 |
If 'servers' is empty or None, search on all known servers.""" |
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1140 |
failed = [] |
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1141 |
|
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1142 |
if not servers: |
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1143 |
servers = self.gen_authorities() |
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1144 |
|
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1145 |
for auth in servers: |
322
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
1146 |
ssl_tuple = self.get_ssl_credentials( |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
1147 |
authority = auth.get("prefix", None), |
e1b078577730
1101 pkg search -s <server> returns a traceback
Danek Duvall <danek.duvall@sun.com>
parents:
319
diff
changeset
|
1148 |
origin = auth["origin"]) |
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
1149 |
|
204
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1150 |
try: |
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1151 |
res, v = versioned_urlopen(auth["origin"], |
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
307
diff
changeset
|
1152 |
"search", [0], urllib.quote(args[0], ""), |
319
39b8b5c538bf
1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents:
316
diff
changeset
|
1153 |
ssl_creds = ssl_tuple, imgtype = self.type) |
204
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1154 |
except urllib2.HTTPError, e: |
260
a1b77322abb2
255 Symbolic HTTP response codes should be used
Shawn Walker <swalker@opensolaris.org>
parents:
259
diff
changeset
|
1155 |
if e.code != httplib.NOT_FOUND: |
204
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1156 |
failed.append((auth, e)) |
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1157 |
continue |
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1158 |
except urllib2.URLError, e: |
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1159 |
failed.append((auth, e)) |
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1160 |
continue |
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1161 |
|
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1162 |
for l in res.read().splitlines(): |
302
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1163 |
fields = l.split() |
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1164 |
if len(fields) < 4: |
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1165 |
yield fields[:2] + [ "", "" ] |
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1166 |
else: |
a5268194080e
981 pkg search could have more useful output
Danek Duvall <danek.duvall@sun.com>
parents:
301
diff
changeset
|
1167 |
yield fields[:4] |
204
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1168 |
if failed: |
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1169 |
raise RuntimeError, failed |
8f650d596aec
72 pkg command throws an exception when no search arguments are given
Danek Duvall <danek.duvall@sun.com>
parents:
201
diff
changeset
|
1170 |
|
251
6c3d70b74865
470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
243
diff
changeset
|
1171 |
def get_download_dir(self): |
6c3d70b74865
470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
243
diff
changeset
|
1172 |
return os.path.normpath(os.path.join( |
6c3d70b74865
470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
243
diff
changeset
|
1173 |
self.imgdir, |
271
ec8a7669bff2
659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
268
diff
changeset
|
1174 |
"download", |
251
6c3d70b74865
470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
243
diff
changeset
|
1175 |
str(os.getpid()))) |
6c3d70b74865
470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
243
diff
changeset
|
1176 |
|
6c3d70b74865
470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
243
diff
changeset
|
1177 |
def cleanup_downloads(self): |
6c3d70b74865
470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
243
diff
changeset
|
1178 |
shutil.rmtree(self.get_download_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
|
1179 |
|
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1180 |
def salvagedir(self, path): |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1181 |
"""Called when directory contains something and it's not supposed |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1182 |
to because it's being deleted. XXX Need to work out a better error |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1183 |
passback mechanism. Path is rooted in /....""" |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1184 |
|
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1185 |
salvagedir = os.path.normpath( |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1186 |
os.path.join(self.imgdir, "lost+found", |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1187 |
path + "-" + time.strftime("%Y-%m-%d+%H:%M:%S"))) |
289
c2e63370fb2b
160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents:
285
diff
changeset
|
1188 |
|
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1189 |
os.makedirs(salvagedir) |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1190 |
shutil.move(os.path.normpath(os.path.join(self.root, path)), salvagedir) |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1191 |
# XXX need a better way to do this. |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1192 |
print >> sys.stderr, \ |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1193 |
"\nWarning - directory %s not empty - contents preserved in %s" % \ |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1194 |
(path, salvagedir) |
251
6c3d70b74865
470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
243
diff
changeset
|
1195 |
|
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1196 |
def expanddirs(self, dirs): |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1197 |
""" given a set of directories, return expanded set that includes |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1198 |
all components""" |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1199 |
out = set() |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1200 |
for d in dirs: |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1201 |
p = d |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1202 |
while p != "": |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1203 |
out.add(p) |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1204 |
p = os.path.dirname(p) |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1205 |
return out |
329 | 1206 |
|
1207 |
||
1208 |
def make_install_plan(self, pkg_list, progress, filters = [], |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1209 |
verbose = False, noexecute = False): |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1210 |
"""Take a list of packages, specified in pkg_list, and attempt |
329 | 1211 |
to assemble an appropriate image plan. This is a helper |
1212 |
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
|
1213 |
|
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1214 |
This method checks all authorities for a package match; |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1215 |
however, it defaults to choosing the preferred authority |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1216 |
when an ambiguous package name is specified. If the user |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1217 |
wishes to install a package from a non-preferred authority, |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1218 |
the full FMRI that contains an authority should be used |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1219 |
to name the package.""" |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1220 |
|
172 | 1221 |
error = 0 |
235
61994d15c39b
373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents:
226
diff
changeset
|
1222 |
ip = imageplan.ImagePlan(self, progress, filters = filters) |
172 | 1223 |
|
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1224 |
self.load_optional_dependencies() |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1225 |
|
172 | 1226 |
for p in pkg_list: |
1227 |
try: |
|
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1228 |
conp = self.apply_optional_dependencies(p) |
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1229 |
matches = self.get_matching_fmris(conp, |
175
8d591677690b
22 Specifying a version on the "pkg install" commandline makes no difference
Danek Duvall <danek.duvall@sun.com>
parents:
173
diff
changeset
|
1230 |
constraint = version.CONSTRAINT_AUTO) |
172 | 1231 |
except KeyError: |
1232 |
# XXX Module directly printing. |
|
1233 |
print _("""\ |
|
1234 |
pkg: no package matching '%s' could be found in current catalog |
|
175
8d591677690b
22 Specifying a version on the "pkg install" commandline makes no difference
Danek Duvall <danek.duvall@sun.com>
parents:
173
diff
changeset
|
1235 |
suggest relaxing pattern, refreshing and/or examining catalogs""") % p |
172 | 1236 |
error = 1 |
1237 |
continue |
|
1238 |
||
1239 |
pnames = {} |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1240 |
pmatch = [] |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1241 |
npnames = {} |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1242 |
npmatch = [] |
172 | 1243 |
for m in matches: |
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1244 |
if m.preferred_authority(): |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1245 |
pnames[m.get_pkg_stem()] = 1 |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1246 |
pmatch.append(m) |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1247 |
else: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1248 |
npnames[m.get_pkg_stem()] = 1 |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1249 |
npmatch.append(m) |
172 | 1250 |
|
1251 |
if len(pnames.keys()) > 1: |
|
1252 |
# XXX Module directly printing. |
|
1253 |
print \ |
|
175
8d591677690b
22 Specifying a version on the "pkg install" commandline makes no difference
Danek Duvall <danek.duvall@sun.com>
parents:
173
diff
changeset
|
1254 |
_("pkg: '%s' matches multiple packages") % p |
172 | 1255 |
for k in pnames.keys(): |
1256 |
print "\t%s" % k |
|
1257 |
error = 1 |
|
1258 |
continue |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1259 |
elif len(pnames.keys()) < 1 and len(npnames.keys()) > 1: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1260 |
# XXX Module directly printing. |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1261 |
print \ |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1262 |
_("pkg: '%s' matches multiple packages") % p |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1263 |
for k in npnames.keys(): |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1264 |
print "\t%s" % k |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1265 |
error = 1 |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1266 |
continue |
172 | 1267 |
|
1268 |
# matches is a list reverse sorted by version, so take |
|
1269 |
# the first; i.e., the latest. |
|
296
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1270 |
if len(pmatch) > 0: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1271 |
ip.propose_fmri(pmatch[0]) |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1272 |
else: |
576858fb8376
398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents:
289
diff
changeset
|
1273 |
ip.propose_fmri(npmatch[0]) |
172 | 1274 |
|
1275 |
if error != 0: |
|
1276 |
raise RuntimeError, "Unable to assemble image plan" |
|
1277 |
||
1278 |
if verbose: |
|
1279 |
print _("Before evaluation:") |
|
1280 |
print ip |
|
1281 |
||
1282 |
ip.evaluate() |
|
307
3a857fd8b787
787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
302
diff
changeset
|
1283 |
self.imageplan = ip |
172 | 1284 |
|
1285 |
if verbose: |
|
1286 |
print _("After evaluation:") |
|
329 | 1287 |
print ip.display() |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
1288 |
|
50 | 1289 |
if __name__ == "__main__": |
1290 |
pass |