author | Danek Duvall <danek.duvall@sun.com> |
Fri, 12 Oct 2007 17:52:11 -0700 | |
changeset 145 | 08bee7fd13f6 |
parent 144 | ce619e0b453f |
child 146 | 9b9fcd56b8b2 |
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 |
||
23 |
# Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
|
24 |
# Use is subject to license terms. |
|
25 |
||
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
26 |
import ConfigParser |
144
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
27 |
import cPickle |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
28 |
import getopt |
26 | 29 |
import os |
34
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
30 |
import re |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
31 |
import urllib |
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
32 |
import urlparse |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
33 |
# 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
|
34 |
|
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
35 |
import pkg.catalog as catalog |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
36 |
import pkg.fmri as fmri |
50 | 37 |
import pkg.manifest as manifest |
26 | 38 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
39 |
import pkg.client.imageconfig as imageconfig |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
40 |
|
145
08bee7fd13f6
Add versioning to the protocols
Danek Duvall <danek.duvall@sun.com>
parents:
144
diff
changeset
|
41 |
from pkg.misc import versioned_urlopen |
08bee7fd13f6
Add versioning to the protocols
Danek Duvall <danek.duvall@sun.com>
parents:
144
diff
changeset
|
42 |
|
19 | 43 |
IMG_ENTIRE = 0 |
44 |
IMG_PARTIAL = 1 |
|
45 |
IMG_USER = 2 |
|
46 |
||
26 | 47 |
img_user_prefix = ".org.opensolaris,pkg" |
30 | 48 |
img_root_prefix = "var/pkg" |
26 | 49 |
|
19 | 50 |
class Image(object): |
51 |
"""An Image object is a directory tree containing the laid-down contents |
|
52 |
of a self-consistent graph of Packages. |
|
53 |
||
54 |
An Image has a root path. |
|
55 |
||
56 |
An Image of type IMG_ENTIRE does not have a parent Image. Other Image |
|
57 |
types must have a parent Image. The external state of the parent Image |
|
58 |
must be accessible from the Image's context, or duplicated within the |
|
59 |
Image (IMG_PARTIAL for zones, for instance). |
|
60 |
||
61 |
The parent of a user Image can be a partial Image. The parent of a |
|
62 |
partial Image must be an entire Image. |
|
63 |
||
64 |
An Image of type IMG_USER stores its external state at self.root + |
|
26 | 65 |
".org.opensolaris,pkg". |
19 | 66 |
|
67 |
An Image of type IMG_ENTIRE or IMG_PARTIAL stores its external state at |
|
68 |
self.root + "/var/pkg". |
|
69 |
||
26 | 70 |
An Image needs to be able to have a different repository set than the |
71 |
system's root Image. |
|
72 |
||
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
73 |
Directory layout |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
74 |
|
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
75 |
$IROOT/catalog |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
76 |
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
|
77 |
the escaped URI of the catalog. |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
78 |
|
30 | 79 |
$IROOT/file |
80 |
Directory containing file hashes of installed packages. |
|
81 |
||
82 |
$IROOT/pkg |
|
83 |
Directory containing manifests and states of installed packages. |
|
84 |
||
60
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
85 |
$IROOT/index |
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
86 |
Directory containing reverse-index databases. |
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
87 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
88 |
$IROOT/cfg_cache |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
89 |
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
|
90 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
91 |
$IROOT/state |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
92 |
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
|
93 |
|
19 | 94 |
XXX Root path probably can't be absolute, so that we can combine or |
30 | 95 |
reuse Image contents. |
26 | 96 |
|
97 |
XXX Image file format? Image file manipulation API?""" |
|
98 |
||
99 |
def __init__(self): |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
100 |
self.cfg_cache = None |
26 | 101 |
self.type = None |
102 |
self.root = None |
|
30 | 103 |
self.imgdir = None |
26 | 104 |
self.repo_uris = [] |
105 |
self.filter_tags = {} |
|
106 |
||
32
c26788b7217c
begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents:
30
diff
changeset
|
107 |
self.catalogs = {} |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
108 |
self.authorities = {} |
32
c26788b7217c
begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents:
30
diff
changeset
|
109 |
|
50 | 110 |
self.attrs = {} |
111 |
||
112 |
self.attrs["Policy-Require-Optional"] = False |
|
113 |
self.attrs["Policy-Pursue-Latest"] = True |
|
114 |
||
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
115 |
def find_root(self, d): |
26 | 116 |
# Ascend from current working directory to find first |
117 |
# encountered image. |
|
118 |
while True: |
|
119 |
if os.path.isdir("%s/%s" % (d, img_user_prefix)): |
|
120 |
# XXX Look at image file to determine filter |
|
121 |
# tags and repo URIs. |
|
122 |
self.type = IMG_USER |
|
123 |
self.root = d |
|
30 | 124 |
self.imgdir = "%s/%s" % (d, img_user_prefix) |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
125 |
self.attrs["Build-Release"] = "5.11" |
26 | 126 |
return |
127 |
elif os.path.isdir("%s/%s" % (d, img_root_prefix)): |
|
128 |
# XXX Look at image file to determine filter |
|
129 |
# tags and repo URIs. |
|
130 |
# XXX Look at image file to determine if this |
|
131 |
# image is a partial image. |
|
132 |
self.type = IMG_ENTIRE |
|
133 |
self.root = d |
|
30 | 134 |
self.imgdir = "%s/%s" % (d, img_root_prefix) |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
135 |
self.attrs["Build-Release"] = "5.11" |
26 | 136 |
return |
137 |
||
138 |
assert d != "/" |
|
139 |
||
63
ba3a4af65479
add -R/$PKG_IMAGE to pkg, and -n and -v to install
Danek Duvall <danek.duvall@sun.com>
parents:
60
diff
changeset
|
140 |
# XXX follow symlinks or not? |
ba3a4af65479
add -R/$PKG_IMAGE to pkg, and -n and -v to install
Danek Duvall <danek.duvall@sun.com>
parents:
60
diff
changeset
|
141 |
d = os.path.normpath(os.path.join(d, os.path.pardir)) |
26 | 142 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
143 |
def load_config(self): |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
144 |
"""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
|
145 |
location.""" |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
146 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
147 |
# 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
|
148 |
# configuration. |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
149 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
150 |
if self.root == None: |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
151 |
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
|
152 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
153 |
ic = imageconfig.ImageConfig() |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
154 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
155 |
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
|
156 |
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
|
157 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
158 |
self.cfg_cache = ic |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
159 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
160 |
# 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
|
161 |
# operation. |
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
162 |
def mkdirs(self): |
30 | 163 |
if not os.path.isdir(self.imgdir + "/catalog"): |
164 |
os.makedirs(self.imgdir + "/catalog") |
|
165 |
if not os.path.isdir(self.imgdir + "/file"): |
|
166 |
os.makedirs(self.imgdir + "/file") |
|
167 |
if not os.path.isdir(self.imgdir + "/pkg"): |
|
168 |
os.makedirs(self.imgdir + "/pkg") |
|
60
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
169 |
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
|
170 |
os.makedirs(self.imgdir + "/index") |
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
171 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
172 |
def set_attrs(self, type, root, is_zone, auth_name, auth_url): |
19 | 173 |
self.type = type |
22
379f0f6809ff
pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents:
19
diff
changeset
|
174 |
self.root = root |
379f0f6809ff
pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents:
19
diff
changeset
|
175 |
if self.type == IMG_USER: |
30 | 176 |
self.imgdir = self.root + "/" + img_user_prefix |
22
379f0f6809ff
pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents:
19
diff
changeset
|
177 |
else: |
30 | 178 |
self.imgdir = self.root + "/" + img_root_prefix |
19 | 179 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
180 |
self.mkdirs() |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
181 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
182 |
self.cfg_cache = imageconfig.ImageConfig() |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
183 |
|
111 | 184 |
if is_zone: |
185 |
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
|
186 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
187 |
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
|
188 |
self.cfg_cache.authorities[auth_name]["prefix"] = auth_name |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
189 |
self.cfg_cache.authorities[auth_name]["origin"] = auth_url |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
190 |
self.cfg_cache.authorities[auth_name]["mirrors"] = None |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
191 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
192 |
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
|
193 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
194 |
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
|
195 |
|
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
196 |
def get_root(self): |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
197 |
return self.root |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
198 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
199 |
def gen_authorities(self): |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
200 |
if not self.cfg_cache: |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
201 |
raise RuntimeError, "empty ImageConfig" |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
202 |
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
|
203 |
raise RuntimeError, "no defined authorities" |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
204 |
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
|
205 |
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
|
206 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
207 |
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
|
208 |
"""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
|
209 |
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
|
210 |
preferred authority.""" |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
211 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
212 |
# 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
|
213 |
# 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
|
214 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
215 |
if authority == None: |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
216 |
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
|
217 |
|
106
ed11fcd45545
pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents:
104
diff
changeset
|
218 |
o = self.cfg_cache.authorities[authority]["origin"] |
ed11fcd45545
pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents:
104
diff
changeset
|
219 |
|
ed11fcd45545
pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents:
104
diff
changeset
|
220 |
return re.sub("/+$", "", o) |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
221 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
222 |
def get_default_authority(self): |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
223 |
return self.cfg_cache.preferred_authority |
19 | 224 |
|
50 | 225 |
def get_matching_pkgs(self, pfmri): |
226 |
"""Exact matches to the given FMRI. Returns a list of (catalog, |
|
227 |
pkg) pairs.""" |
|
34
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
228 |
|
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
|
229 |
m = [ |
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
230 |
(c, p) |
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
231 |
for c in self.catalogs.values() |
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
232 |
for p in c.get_matching_pkgs(pfmri, None) |
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
233 |
] |
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
234 |
|
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
235 |
if not m: |
87
470cad54c43d
Fix bug in Image; allow for missing description in SysV depend file
Danek Duvall <danek.duvall@sun.com>
parents:
72
diff
changeset
|
236 |
raise KeyError, "package matching '%s' not found in catalog" \ |
470cad54c43d
Fix bug in Image; allow for missing description in SysV depend file
Danek Duvall <danek.duvall@sun.com>
parents:
72
diff
changeset
|
237 |
% pfmri |
34
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
238 |
|
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
239 |
return m |
32
c26788b7217c
begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents:
30
diff
changeset
|
240 |
|
50 | 241 |
def get_regex_matching_fmris(self, regex): |
242 |
"""FMRIs matching the given regular expression. Returns of a |
|
243 |
list of (catalog, PkgFmri) pairs.""" |
|
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
244 |
|
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
|
245 |
m = [ |
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
246 |
(c, p) |
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
247 |
for c in self.catalogs.values() |
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
248 |
for p in c.get_regex_matching_fmris(regex) |
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
249 |
] |
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
250 |
|
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
251 |
if not m: |
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
252 |
raise KeyError, "pattern '%s' not found in catalog" \ |
9eeb33eab728
Gracefully exit when trying to install packages on an image without a catalog.
Danek Duvall <danek.duvall@sun.com>
parents:
67
diff
changeset
|
253 |
% regex |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
254 |
|
50 | 255 |
return m |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
256 |
|
50 | 257 |
def has_manifest(self, fmri): |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
258 |
mpath = fmri.get_dir_path() |
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
259 |
|
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
260 |
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
|
261 |
|
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
262 |
if (os.path.exists(local_mpath)): |
50 | 263 |
return True |
264 |
||
265 |
return False |
|
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
266 |
|
50 | 267 |
def get_manifest(self, fmri): |
268 |
m = manifest.Manifest() |
|
72
9deed41412b3
Support for proper package upgrade.
Danek Duvall <danek.duvall@sun.com>
parents:
69
diff
changeset
|
269 |
|
144
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
270 |
fmri_dir_path = os.path.join(self.imgdir, "pkg", |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
271 |
fmri.get_dir_path()) |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
272 |
mpath = os.path.join(fmri_dir_path, "manifest") |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
273 |
|
72
9deed41412b3
Support for proper package upgrade.
Danek Duvall <danek.duvall@sun.com>
parents:
69
diff
changeset
|
274 |
# If the manifest isn't there, download and retry. |
9deed41412b3
Support for proper package upgrade.
Danek Duvall <danek.duvall@sun.com>
parents:
69
diff
changeset
|
275 |
try: |
144
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
276 |
mcontent = file(mpath).read() |
72
9deed41412b3
Support for proper package upgrade.
Danek Duvall <danek.duvall@sun.com>
parents:
69
diff
changeset
|
277 |
except IOError, e: |
9deed41412b3
Support for proper package upgrade.
Danek Duvall <danek.duvall@sun.com>
parents:
69
diff
changeset
|
278 |
if e.errno != errno.ENOENT: |
9deed41412b3
Support for proper package upgrade.
Danek Duvall <danek.duvall@sun.com>
parents:
69
diff
changeset
|
279 |
raise |
9deed41412b3
Support for proper package upgrade.
Danek Duvall <danek.duvall@sun.com>
parents:
69
diff
changeset
|
280 |
retrieve.get_manifest(self, fmri) |
144
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
281 |
mcontent = file(mpath).read() |
72
9deed41412b3
Support for proper package upgrade.
Danek Duvall <danek.duvall@sun.com>
parents:
69
diff
changeset
|
282 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
283 |
m.set_fmri(self, fmri) |
50 | 284 |
m.set_content(mcontent) |
144
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
285 |
|
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
286 |
# Pickle the manifest's indices, for searching |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
287 |
pfile = file(os.path.join(fmri_dir_path, "index"), "wb") |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
288 |
m.pickle(pfile) |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
289 |
pfile.close() |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
290 |
|
50 | 291 |
return m |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
292 |
|
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
293 |
def get_version_installed(self, pfmri): |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
294 |
pd = pfmri.get_pkg_stem() |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
295 |
pdir = "%s/pkg/%s" % (self.imgdir, |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
296 |
pfmri.get_dir_path(stemonly = True)) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
297 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
298 |
try: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
299 |
pkgs_inst = [ urllib.unquote("%s@%s" % (pd, vd)) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
300 |
for vd in os.listdir(pdir) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
301 |
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
|
302 |
except OSError: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
303 |
raise LookupError, "no packages ever installed" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
304 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
305 |
if len(pkgs_inst) == 0: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
306 |
raise LookupError, "no packages installed" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
307 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
308 |
assert len(pkgs_inst) <= 1 |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
309 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
310 |
return fmri.PkgFmri(pkgs_inst[0], None) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
311 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
312 |
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
|
313 |
"""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
|
314 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
315 |
if os.path.exists("%s/pkg/%s/installed" % (self.imgdir, |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
316 |
pfmri.get_dir_path())): |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
317 |
return "installed" |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
318 |
|
106
ed11fcd45545
pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents:
104
diff
changeset
|
319 |
return "known" |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
320 |
|
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
|
321 |
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
|
322 |
"""Check that the version given in the FMRI or a successor is |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
323 |
installed in the current image.""" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
324 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
325 |
try: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
326 |
v = self.get_version_installed(fmri) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
327 |
except LookupError: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
328 |
return False |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
329 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
330 |
if v.is_successor(fmri): |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
331 |
return True |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
332 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
333 |
return False |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
334 |
|
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
|
335 |
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
|
336 |
"""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
|
337 |
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
|
338 |
|
a1e20e9a9845
add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents:
116
diff
changeset
|
339 |
try: |
a1e20e9a9845
add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents:
116
diff
changeset
|
340 |
v = self.get_version_installed(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
|
341 |
except LookupError: |
a1e20e9a9845
add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents:
116
diff
changeset
|
342 |
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
|
343 |
|
a1e20e9a9845
add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents:
116
diff
changeset
|
344 |
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
|
345 |
|
67
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
346 |
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
|
347 |
"""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
|
348 |
FMRI.""" |
67
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
349 |
|
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
350 |
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
|
351 |
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
|
352 |
|
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
353 |
if not os.path.isdir(thedir): |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
354 |
return [] |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
355 |
|
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
356 |
for v in os.listdir(thedir): |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
357 |
f = fmri.PkgFmri(pfmri.get_pkg_stem() + "@" + v, |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
358 |
self.attrs["Build-Release"]) |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
359 |
if pfmri.is_successor(f): |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
360 |
dependents = [ |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
361 |
urllib.unquote(d) |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
362 |
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
|
363 |
if os.path.exists( |
1861fdf62519
on uninstall, don't complain about uninstalled dependents
Danek Duvall <danek.duvall@sun.com>
parents:
135
diff
changeset
|
364 |
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
|
365 |
] |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
366 |
|
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
367 |
return dependents |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
368 |
|
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
369 |
def retrieve_catalogs(self): |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
370 |
for auth in self.gen_authorities(): |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
371 |
# XXX Mirror selection and retrieval policy? |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
372 |
|
145
08bee7fd13f6
Add versioning to the protocols
Danek Duvall <danek.duvall@sun.com>
parents:
144
diff
changeset
|
373 |
c, v = versioned_urlopen(auth["origin"], "catalog", [0]) |
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
374 |
|
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
375 |
# compare headers |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
376 |
data = c.read() |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
377 |
|
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
378 |
# Filename should be reduced to host\:port |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
379 |
cfile = file("%s/catalog/%s" % (self.imgdir, |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
380 |
auth["prefix"]), "w") |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
381 |
print >>cfile, data |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
382 |
|
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
383 |
def reload_catalogs(self): |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
384 |
cdir = "%s/%s" % (self.imgdir, "catalog") |
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
385 |
for auth in self.gen_authorities(): |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
386 |
c = catalog.Catalog() |
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
387 |
c.load("%s/%s" % (cdir, auth["prefix"])) |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
388 |
|
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
389 |
self.catalogs[auth["prefix"]] = c |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
390 |
|
106
ed11fcd45545
pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents:
104
diff
changeset
|
391 |
def gen_known_packages(self): |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
392 |
for c in self.catalogs.values(): |
106
ed11fcd45545
pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents:
104
diff
changeset
|
393 |
for pf in c.gen_package_versions(): |
ed11fcd45545
pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents:
104
diff
changeset
|
394 |
yield pf |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
395 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
396 |
def display_inventory(self, args): |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
397 |
"""XXX Reimplement if we carve out the inventory as a has-a |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
398 |
object from image.""" |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
399 |
|
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
400 |
opts = [] |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
401 |
pargs = [] |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
402 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
403 |
all_known = False |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
404 |
verbose = False |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
405 |
upgradable_only = False |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
406 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
407 |
if len(args) > 0: |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
408 |
opts, pargs = getopt.getopt(args, "auv") |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
409 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
410 |
for opt, arg in opts: |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
411 |
if opt == "-a": |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
412 |
all_known = True |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
413 |
if opt == "-u": |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
414 |
upgradable_only = True |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
415 |
if opt == "-v": |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
416 |
verbose = True |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
417 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
418 |
if verbose: |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
419 |
fmt_str = "%-64s %-10s %c%c%c%c" |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
420 |
else: |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
421 |
fmt_str = "%-50s %-10s %c%c%c%c" |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
422 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
423 |
proot = "%s/pkg" % self.imgdir |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
424 |
|
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
425 |
if len(pargs): |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
426 |
pkgs_known = [ m[1] |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
427 |
for p in pargs |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
428 |
for m in self.get_regex_matching_fmris(p) ] |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
429 |
|
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
430 |
elif all_known: |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
431 |
pkgs_known = [ pf for pf in |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
432 |
self.gen_known_packages() ] |
50 | 433 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
434 |
else: |
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
435 |
pkgs_known = [ fmri.PkgFmri(urllib.unquote("%s@%s" % |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
436 |
(pd, vd)), None) |
106
ed11fcd45545
pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents:
104
diff
changeset
|
437 |
for pd in sorted(os.listdir(proot)) |
ed11fcd45545
pkg status -a; allow trailing / in URL; don't write 404 into manifest;
"Stephen Hahn <sch@sun.com>"
parents:
104
diff
changeset
|
438 |
for vd in sorted(os.listdir("%s/%s" % (proot, pd))) |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
439 |
if os.path.exists("%s/%s/%s/installed" % |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
440 |
(proot, pd, vd)) ] |
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
441 |
|
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
442 |
if len(pkgs_known) == 0: |
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
443 |
if len(pargs): |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
444 |
print "pkg: no matching packages installed" |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
445 |
else: |
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
446 |
print "pkg: no packages installed" |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
447 |
return |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
448 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
449 |
print fmt_str % ("FMRI", "STATE", "U", "F", "I", "X") |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
450 |
|
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
451 |
for p in pkgs_known: |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
452 |
upgradable = "-" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
453 |
frozen = "-" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
454 |
incorporated = "-" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
455 |
excludes = "-" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
456 |
|
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
457 |
if len(self.get_matching_pkgs(p)) > 1: |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
458 |
upgradable = "u" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
459 |
elif upgradable_only: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
460 |
continue |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
461 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
462 |
if not verbose: |
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
463 |
pf = p.get_short_fmri() |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
464 |
else: |
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
465 |
pf = p.get_fmri(self.get_default_authority()) |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
466 |
|
116
9c9942a52984
(image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents:
111
diff
changeset
|
467 |
print fmt_str % (pf, self.get_pkg_state_by_fmri(p), |
104
ecfc64baf22e
add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents:
87
diff
changeset
|
468 |
upgradable, frozen, incorporated, excludes) |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
469 |
|
144
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
470 |
def search(self, args): |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
471 |
"""Search the image for the token in args[0].""" |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
472 |
|
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
473 |
idxdir = os.path.join(self.imgdir, "pkg") |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
474 |
|
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
475 |
# 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
|
476 |
def idx_to_fmri(index): |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
477 |
return fmri.PkgFmri(urllib.unquote( |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
478 |
os.path.dirname(index[len(idxdir) + 1:])), None) |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
479 |
|
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
480 |
indices = ( |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
481 |
(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
|
482 |
for dir, dirnames, filenames in os.walk(idxdir) |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
483 |
if "manifest" in filenames |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
484 |
) |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
485 |
|
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
486 |
for index, mfst in indices: |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
487 |
# 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
|
488 |
# manifest. |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
489 |
try: |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
490 |
d = cPickle.load(file(index)) |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
491 |
except: |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
492 |
m = manifest.Manifest() |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
493 |
try: |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
494 |
mcontent = file(mfst).read() |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
495 |
except: |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
496 |
# XXX log something? |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
497 |
continue |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
498 |
m.set_content(mcontent) |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
499 |
try: |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
500 |
m.pickle(file(index, "wb")) |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
501 |
except: |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
502 |
pass |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
503 |
d = m.search_dict() |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
504 |
|
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
505 |
for k, v in d.items(): |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
506 |
if args[0] in v: |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
507 |
yield k, idx_to_fmri(index) |
ce619e0b453f
Fix unscalable search indexing
Danek Duvall <danek.duvall@sun.com>
parents:
139
diff
changeset
|
508 |
|
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
509 |
|
50 | 510 |
if __name__ == "__main__": |
511 |
# XXX Need to construct a trivial image and catalog. |
|
512 |
pass |