author | Danek Duvall <danek.duvall@sun.com> |
Mon, 06 Aug 2007 14:53:13 -0700 | |
changeset 67 | 62c897652bbc |
parent 63 | ba3a4af65479 |
child 69 | 9eeb33eab728 |
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 |
||
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
26 |
import getopt |
26 | 27 |
import os |
34
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
28 |
import re |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
29 |
import urllib |
34
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
30 |
|
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
31 |
import pkg.catalog as catalog |
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
32 |
import pkg.fmri as fmri |
50 | 33 |
import pkg.manifest as manifest |
26 | 34 |
|
19 | 35 |
IMG_ENTIRE = 0 |
36 |
IMG_PARTIAL = 1 |
|
37 |
IMG_USER = 2 |
|
38 |
||
26 | 39 |
img_user_prefix = ".org.opensolaris,pkg" |
30 | 40 |
img_root_prefix = "var/pkg" |
26 | 41 |
|
19 | 42 |
class Image(object): |
43 |
"""An Image object is a directory tree containing the laid-down contents |
|
44 |
of a self-consistent graph of Packages. |
|
45 |
||
46 |
An Image has a root path. |
|
47 |
||
48 |
An Image of type IMG_ENTIRE does not have a parent Image. Other Image |
|
49 |
types must have a parent Image. The external state of the parent Image |
|
50 |
must be accessible from the Image's context, or duplicated within the |
|
51 |
Image (IMG_PARTIAL for zones, for instance). |
|
52 |
||
53 |
The parent of a user Image can be a partial Image. The parent of a |
|
54 |
partial Image must be an entire Image. |
|
55 |
||
56 |
An Image of type IMG_USER stores its external state at self.root + |
|
26 | 57 |
".org.opensolaris,pkg". |
19 | 58 |
|
59 |
An Image of type IMG_ENTIRE or IMG_PARTIAL stores its external state at |
|
60 |
self.root + "/var/pkg". |
|
61 |
||
26 | 62 |
An Image needs to be able to have a different repository set than the |
63 |
system's root Image. |
|
64 |
||
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
65 |
Directory layout |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
66 |
|
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
67 |
$IROOT/catalog |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
68 |
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
|
69 |
the escaped URI of the catalog. |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
70 |
|
30 | 71 |
$IROOT/file |
72 |
Directory containing file hashes of installed packages. |
|
73 |
||
74 |
$IROOT/pkg |
|
75 |
Directory containing manifests and states of installed packages. |
|
76 |
||
60
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
77 |
$IROOT/index |
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
78 |
Directory containing reverse-index databases. |
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
79 |
|
19 | 80 |
XXX Root path probably can't be absolute, so that we can combine or |
30 | 81 |
reuse Image contents. |
26 | 82 |
|
83 |
XXX Image file format? Image file manipulation API?""" |
|
84 |
||
85 |
def __init__(self): |
|
86 |
self.type = None |
|
87 |
self.root = None |
|
30 | 88 |
self.imgdir = None |
26 | 89 |
self.repo_uris = [] |
90 |
self.filter_tags = {} |
|
91 |
||
32
c26788b7217c
begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents:
30
diff
changeset
|
92 |
self.catalogs = {} |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
93 |
self.authorities = {} |
32
c26788b7217c
begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents:
30
diff
changeset
|
94 |
|
50 | 95 |
self.attrs = {} |
96 |
||
97 |
self.attrs["Policy-Require-Optional"] = False |
|
98 |
self.attrs["Policy-Pursue-Latest"] = True |
|
99 |
||
63
ba3a4af65479
add -R/$PKG_IMAGE to pkg, and -n and -v to install
Danek Duvall <danek.duvall@sun.com>
parents:
60
diff
changeset
|
100 |
def find_parent(self, d): |
26 | 101 |
# Ascend from current working directory to find first |
102 |
# encountered image. |
|
103 |
while True: |
|
104 |
if os.path.isdir("%s/%s" % (d, img_user_prefix)): |
|
105 |
# XXX Look at image file to determine filter |
|
106 |
# tags and repo URIs. |
|
107 |
self.type = IMG_USER |
|
108 |
self.root = d |
|
30 | 109 |
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
|
110 |
self.attrs["Build-Release"] = "5.11" |
26 | 111 |
return |
112 |
elif os.path.isdir("%s/%s" % (d, img_root_prefix)): |
|
113 |
# XXX Look at image file to determine filter |
|
114 |
# tags and repo URIs. |
|
115 |
# XXX Look at image file to determine if this |
|
116 |
# image is a partial image. |
|
117 |
self.type = IMG_ENTIRE |
|
118 |
self.root = d |
|
30 | 119 |
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
|
120 |
self.attrs["Build-Release"] = "5.11" |
26 | 121 |
return |
122 |
||
123 |
assert d != "/" |
|
124 |
||
63
ba3a4af65479
add -R/$PKG_IMAGE to pkg, and -n and -v to install
Danek Duvall <danek.duvall@sun.com>
parents:
60
diff
changeset
|
125 |
# 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
|
126 |
d = os.path.normpath(os.path.join(d, os.path.pardir)) |
26 | 127 |
|
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
128 |
def mkdirs(self): |
30 | 129 |
if not os.path.isdir(self.imgdir + "/catalog"): |
130 |
os.makedirs(self.imgdir + "/catalog") |
|
131 |
if not os.path.isdir(self.imgdir + "/file"): |
|
132 |
os.makedirs(self.imgdir + "/file") |
|
133 |
if not os.path.isdir(self.imgdir + "/pkg"): |
|
134 |
os.makedirs(self.imgdir + "/pkg") |
|
60
6bd5cd83cfb1
Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents:
59
diff
changeset
|
135 |
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
|
136 |
os.makedirs(self.imgdir + "/index") |
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
137 |
|
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
138 |
def set_attrs(self, type, root): |
19 | 139 |
self.type = type |
22
379f0f6809ff
pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents:
19
diff
changeset
|
140 |
self.root = root |
379f0f6809ff
pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents:
19
diff
changeset
|
141 |
if self.type == IMG_USER: |
30 | 142 |
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
|
143 |
else: |
30 | 144 |
self.imgdir = self.root + "/" + img_root_prefix |
19 | 145 |
|
29
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
146 |
def get_root(self): |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
147 |
return self.root |
f621f1df0849
fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents:
26
diff
changeset
|
148 |
|
19 | 149 |
def set_resource(self, resource): |
150 |
return |
|
151 |
||
50 | 152 |
def get_matching_pkgs(self, pfmri): |
153 |
"""Exact matches to the given FMRI. Returns a list of (catalog, |
|
154 |
pkg) pairs.""" |
|
34
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
155 |
|
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
156 |
m = [] |
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
157 |
for c in self.catalogs.values(): |
50 | 158 |
m.extend([(c, p) \ |
159 |
for p in c.get_matching_pkgs(pfmri, None)]) |
|
34
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
160 |
|
8b9613402116
refactor catalog and package to be common; improve bump-server
Stephen Hahn <sch@sun.com>
parents:
33
diff
changeset
|
161 |
return m |
32
c26788b7217c
begin client install; sequences are now timestamps; skeleton ELF module
Stephen Hahn <sch@sun.com>
parents:
30
diff
changeset
|
162 |
|
50 | 163 |
def get_regex_matching_fmris(self, regex): |
164 |
"""FMRIs matching the given regular expression. Returns of a |
|
165 |
list of (catalog, PkgFmri) pairs.""" |
|
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
166 |
|
50 | 167 |
m = [] |
168 |
for c in self.catalogs.values(): |
|
169 |
m.extend([(c, p) \ |
|
170 |
for p in c.get_regex_matching_fmris(regex)]) |
|
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
171 |
|
50 | 172 |
return m |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
173 |
|
50 | 174 |
def has_manifest(self, fmri): |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
175 |
mpath = fmri.get_dir_path() |
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
176 |
|
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
177 |
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
|
178 |
|
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
179 |
if (os.path.exists(local_mpath)): |
50 | 180 |
return True |
181 |
||
182 |
return False |
|
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
183 |
|
50 | 184 |
def get_manifest(self, fmri): |
185 |
m = manifest.Manifest() |
|
186 |
mcontent = file("%s/pkg/%s/manifest" % |
|
187 |
(self.imgdir, fmri.get_dir_path())).read() |
|
51
d04d55e16d0b
Simplify the action API and add real support for client-side installation
Danek Duvall <danek.duvall@sun.com>
parents:
50
diff
changeset
|
188 |
m.set_fmri(fmri) |
50 | 189 |
m.set_content(mcontent) |
190 |
return m |
|
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
191 |
|
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
192 |
def get_version_installed(self, pfmri): |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
193 |
pd = pfmri.get_pkg_stem() |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
194 |
pdir = "%s/pkg/%s" % (self.imgdir, |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
195 |
pfmri.get_dir_path(stemonly = True)) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
196 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
197 |
try: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
198 |
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
|
199 |
for vd in os.listdir(pdir) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
200 |
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
|
201 |
except OSError: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
202 |
raise LookupError, "no packages ever installed" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
203 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
204 |
if len(pkgs_inst) == 0: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
205 |
raise LookupError, "no packages installed" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
206 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
207 |
assert len(pkgs_inst) <= 1 |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
208 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
209 |
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
|
210 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
211 |
def is_installed(self, fmri): |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
212 |
"""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
|
213 |
installed in the current image.""" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
214 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
215 |
try: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
216 |
v = self.get_version_installed(fmri) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
217 |
except LookupError: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
218 |
return False |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
219 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
220 |
if v.is_successor(fmri): |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
221 |
return True |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
222 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
223 |
return False |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
224 |
|
67
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
225 |
def get_dependents(self, pfmri): |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
226 |
"""Return a list of the packages directly dependent on the given FMRI.""" |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
227 |
|
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
228 |
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
|
229 |
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
|
230 |
|
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
231 |
if not os.path.isdir(thedir): |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
232 |
return [] |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
233 |
|
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
234 |
for v in os.listdir(thedir): |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
235 |
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
|
236 |
self.attrs["Build-Release"]) |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
237 |
if pfmri.is_successor(f): |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
238 |
dependents = [ |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
239 |
urllib.unquote(d) |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
240 |
for d in os.listdir(os.path.join(thedir, v)) |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
241 |
] |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
242 |
|
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
243 |
return dependents |
62c897652bbc
Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents:
63
diff
changeset
|
244 |
|
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
245 |
def reload_catalogs(self): |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
246 |
cdir = "%s/%s" % (self.imgdir, "catalog") |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
247 |
for cf in os.listdir(cdir): |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
248 |
c = catalog.Catalog() |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
249 |
c.load("%s/%s" % (cdir, cf)) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
250 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
251 |
self.catalogs[cf] = c |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
252 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
253 |
# XXX XXX |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
254 |
# build up authorities |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
255 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
256 |
def display_catalogs(self): |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
257 |
for c in self.catalogs.values(): |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
258 |
c.display() |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
259 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
260 |
def display_inventory(self, args): |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
261 |
"""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
|
262 |
object from image.""" |
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
263 |
|
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
264 |
opts = [] |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
265 |
pargs = [] |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
266 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
267 |
verbose = False |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
268 |
upgradable_only = False |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
269 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
270 |
if len(args) > 0: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
271 |
opts, pargs = getopt.getopt(args, "uv") |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
272 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
273 |
for opt, arg in opts: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
274 |
if opt == "-u": |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
275 |
upgradable_only = True |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
276 |
if opt == "-v": |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
277 |
verbose = True |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
278 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
279 |
fmt_str = "%-50s %-10s %c%c%c%c" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
280 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
281 |
proot = "%s/pkg" % self.imgdir |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
282 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
283 |
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
|
284 |
for pd in os.listdir(proot) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
285 |
for vd in os.listdir("%s/%s" % (proot, pd)) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
286 |
if os.path.exists("%s/%s/%s/installed" % (proot, pd, vd)) ] |
50 | 287 |
|
59
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
288 |
if len(pkgs_inst) == 0: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
289 |
print "pkg: no packages installed" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
290 |
return |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
291 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
292 |
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
|
293 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
294 |
for p in pkgs_inst: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
295 |
f = fmri.PkgFmri(p, None) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
296 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
297 |
upgradable = "-" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
298 |
frozen = "-" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
299 |
incorporated = "-" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
300 |
excludes = "-" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
301 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
302 |
if len(self.get_matching_pkgs(f)) > 1: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
303 |
upgradable = "u" |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
304 |
elif upgradable_only: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
305 |
continue |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
306 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
307 |
if not verbose: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
308 |
pf = f.get_short_fmri() |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
309 |
else: |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
310 |
pf = str(f) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
311 |
|
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
312 |
print fmt_str % (pf, "installed", upgradable, frozen, |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
313 |
incorporated, excludes) |
eef94b0c0694
require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents:
51
diff
changeset
|
314 |
|
45
8a3f00dea14f
catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents:
39
diff
changeset
|
315 |
|
50 | 316 |
if __name__ == "__main__": |
317 |
# XXX Need to construct a trivial image and catalog. |
|
318 |
pass |