author | Brad Hall <bhall@eng.sun.com> |
Tue, 15 Jul 2008 18:00:30 -0700 | |
changeset 420 | 0b6ecdba5641 |
parent 409 | 713e20963dc2 |
child 440 | cbd8cd1564a9 |
permissions | -rwxr-xr-x |
409
713e20963dc2
2314 shebang lines should use minimum python version
Shawn Walker <swalker@opensolaris.org>
parents:
375
diff
changeset
|
1 |
#!/usr/bin/python2.4 |
375
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
2 |
# |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
3 |
# CDDL HEADER START |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
4 |
# |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
5 |
# The contents of this file are subject to the terms of the |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
6 |
# Common Development and Distribution License (the "License"). |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
7 |
# You may not use this file except in compliance with the License. |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
8 |
# |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
9 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
10 |
# or http://www.opensolaris.org/os/licensing. |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
11 |
# See the License for the specific language governing permissions |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
12 |
# and limitations under the License. |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
13 |
# |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
15 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
16 |
# If applicable, add the following below this CDDL HEADER, with the |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
19 |
# |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
20 |
# CDDL HEADER END |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
21 |
# |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
22 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
23 |
# |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
24 |
# Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
25 |
# Use is subject to license terms. |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
26 |
# |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
27 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
28 |
import sys |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
29 |
import os |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
30 |
import traceback |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
31 |
import getopt |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
32 |
import urllib |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
33 |
import tempfile |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
34 |
import gettext |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
35 |
import shutil |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
36 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
37 |
import pkg.fmri |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
38 |
import pkg.pkgtarfile as ptf |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
39 |
import pkg.catalog as catalog |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
40 |
import pkg.actions as actions |
420
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
41 |
from pkg.misc import versioned_urlopen, gunzip_from_stream |
375
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
42 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
43 |
def usage(usage_error = None): |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
44 |
""" Emit a usage message and optionally prefix it with a more |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
45 |
specific error message. Causes program to exit. """ |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
46 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
47 |
pname = os.path.basename(sys.argv[0]) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
48 |
if usage_error: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
49 |
print >> sys.stderr, pname + ": " + usage_error |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
50 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
51 |
print >> sys.stderr, _("""\ |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
52 |
Usage: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
53 |
pkgrecv -s server [-d dir] pkgfmri ... |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
54 |
pkgrecv -s server -n""") |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
55 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
56 |
sys.exit(2) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
57 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
58 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
59 |
def error(error): |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
60 |
""" Emit an error message prefixed by the command name """ |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
61 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
62 |
pname = os.path.basename(sys.argv[0]) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
63 |
print >> sys.stderr, pname + ": " + error |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
64 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
65 |
def hashes_from_mfst(manifest): |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
66 |
"""Given a path to a manifest, open the file and read through the |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
67 |
actions. Return a set of all content hashes found in the manifest.""" |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
68 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
69 |
hashes = set() |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
70 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
71 |
try: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
72 |
f = file(manifest, "r") |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
73 |
except: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
74 |
error(_("Unable to open manifest: %s") % manifest) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
75 |
sys.exit(1) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
76 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
77 |
for line in f: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
78 |
line = line.lstrip() |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
79 |
if not line or line[0] == "#": |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
80 |
continue |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
81 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
82 |
try: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
83 |
action = actions.fromstr(line) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
84 |
except: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
85 |
continue |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
86 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
87 |
if hasattr(action, "hash"): |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
88 |
hashes.add(action.hash) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
89 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
90 |
f.close() |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
91 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
92 |
return hashes |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
93 |
|
420
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
94 |
def fetch_files_byhash(server_url, hashes, pkgdir, keep_compressed): |
375
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
95 |
"""Given a list of files named by content hash, download from |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
96 |
server_url into pkgdir.""" |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
97 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
98 |
req_dict = { } |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
99 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
100 |
for i, k in enumerate(hashes): |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
101 |
str = "File-Name-%s" % i |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
102 |
req_dict[str] = k |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
103 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
104 |
req_str = urllib.urlencode(req_dict) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
105 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
106 |
try: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
107 |
f, v = versioned_urlopen(server_url, "filelist", [0], |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
108 |
data = req_str) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
109 |
except: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
110 |
error(_("Unable to download files from: %s") % server_url) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
111 |
sys.exit(1) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
112 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
113 |
tar_stream = ptf.PkgTarFile.open(mode = "r|", fileobj = f) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
114 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
115 |
if not os.path.exists(pkgdir): |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
116 |
try: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
117 |
os.makedirs(pkgdir) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
118 |
except: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
119 |
error(_("Unable to create directory: %s") % pkgdir) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
120 |
sys.exit(1) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
121 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
122 |
for info in tar_stream: |
420
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
123 |
gzfobj = None |
375
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
124 |
try: |
420
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
125 |
if not keep_compressed: |
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
126 |
# Uncompress as we retrieve the files |
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
127 |
gzfobj = tar_stream.extractfile(info) |
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
128 |
fpath = os.path.join(pkgdir, info.name) |
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
129 |
outfile = open(fpath, "wb") |
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
130 |
gunzip_from_stream(gzfobj, outfile) |
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
131 |
outfile.close() |
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
132 |
gzfobj.close() |
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
133 |
else: |
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
134 |
# We want to keep the files compressed on disk |
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
135 |
tar_stream.extract_to(info, pkgdir, info.name) |
375
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
136 |
except: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
137 |
error(_("Unable to extract file: %s") % info.name) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
138 |
sys.exit(1) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
139 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
140 |
tar_stream.close() |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
141 |
f.close() |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
142 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
143 |
def fetch_manifest(server_url, fmri, basedir): |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
144 |
"""Fetch the manifest for package-fmri 'fmri' from the server |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
145 |
in 'server_url'. Put manifest in a directory named by package stem""" |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
146 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
147 |
# Request manifest from server |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
148 |
try: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
149 |
m, v = versioned_urlopen(server_url, "manifest", [0], |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
150 |
fmri.get_url_path()) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
151 |
except: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
152 |
error(_("Unable to download manifest %s from %s") % |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
153 |
(fmri.get_url_path(), server_url)) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
154 |
sys.exit(1) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
155 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
156 |
# join pkgname onto basedir. Manifest goes here |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
157 |
opath = os.path.join(basedir, urllib.quote(fmri.pkg_name, "")) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
158 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
159 |
# Create directories if they don't exist |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
160 |
if not os.path.exists(opath): |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
161 |
try: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
162 |
os.makedirs(opath) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
163 |
except: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
164 |
error(_("Unable to create directory: %s") % opath) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
165 |
sys.exit(1) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
166 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
167 |
# Open manifest |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
168 |
opath = os.path.join(opath, "manifest") |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
169 |
try: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
170 |
ofile = file(opath, "w") |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
171 |
except: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
172 |
error(_("Unable to open file: %s") % opath) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
173 |
sys.exit(1) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
174 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
175 |
# Read from server, write to file |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
176 |
try: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
177 |
mfst = m.read() |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
178 |
except: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
179 |
error(_("Error occurred while reading from: %s") % server_url) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
180 |
sys.exit(1) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
181 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
182 |
try: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
183 |
ofile.write(mfst) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
184 |
except: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
185 |
error(_("Error occurred while writing to: %s") % opath) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
186 |
sys.exit(1) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
187 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
188 |
# Close it up |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
189 |
ofile.close() |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
190 |
m.close() |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
191 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
192 |
return opath |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
193 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
194 |
def list_newest_fmris(cat): |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
195 |
"""Look through the catalog 'cat' and return the newest version |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
196 |
of a fmri found for a given package.""" |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
197 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
198 |
fm_hash = { } |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
199 |
fm_list = [ ] |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
200 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
201 |
# Order all fmris by package name |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
202 |
for f in cat.fmris(): |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
203 |
if f.pkg_name in fm_hash: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
204 |
fm_hash[f.pkg_name].append(f) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
205 |
else: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
206 |
fm_hash[f.pkg_name] = [ f ] |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
207 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
208 |
# sort each fmri list |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
209 |
for k in fm_hash.keys(): |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
210 |
fm_hash[k].sort(reverse = True) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
211 |
l = fm_hash[k] |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
212 |
fm_list.append(l[0]) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
213 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
214 |
for e in fm_list: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
215 |
print e |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
216 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
217 |
def fetch_catalog(server_url): |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
218 |
"""Fetch the catalog from the server_url.""" |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
219 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
220 |
# open connection for catalog |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
221 |
try: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
222 |
c, v = versioned_urlopen(server_url, "catalog", [0]) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
223 |
except: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
224 |
error(_("Unable to download catalog from: %s") % server_url) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
225 |
sys.exit(1) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
226 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
227 |
# make a tempdir for catalog |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
228 |
dl_dir = tempfile.mkdtemp() |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
229 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
230 |
# call catalog.recv to pull down catalog |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
231 |
try: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
232 |
catalog.recv(c, dl_dir) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
233 |
except: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
234 |
error(_("Error while reading from: %s") % server_url) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
235 |
sys.exit(1) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
236 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
237 |
# close connection to server |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
238 |
c.close() |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
239 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
240 |
# instantiate catalog object |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
241 |
cat = catalog.Catalog(dl_dir) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
242 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
243 |
# return (catalog, tmpdir path) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
244 |
return cat, dl_dir |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
245 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
246 |
def main_func(): |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
247 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
248 |
server = None |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
249 |
basedir = None |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
250 |
newfmri = False |
420
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
251 |
keep_compressed = False |
375
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
252 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
253 |
# XXX /usr/lib/locale is OpenSolaris-specific. |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
254 |
gettext.install("pkgrecv", "/usr/lib/locale") |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
255 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
256 |
try: |
420
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
257 |
opts, pargs = getopt.getopt(sys.argv[1:], "s:d:nk") |
375
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
258 |
except getopt.GetoptError, e: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
259 |
usage(_("Illegal option -- %s") % e.opt) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
260 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
261 |
for opt, arg in opts: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
262 |
if opt == "-s": |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
263 |
server = arg |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
264 |
if opt == "-d": |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
265 |
basedir = arg |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
266 |
if opt == "-n": |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
267 |
newfmri = True |
420
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
268 |
if opt == "-k": |
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
269 |
keep_compressed = True |
375
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
270 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
271 |
if not server: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
272 |
usage(_("must specify a server")) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
273 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
274 |
if not server.startswith("http://"): |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
275 |
server = "http://%s" % server |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
276 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
277 |
if newfmri: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
278 |
if pargs or len(pargs) > 0: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
279 |
usage(_("-n takes no options")) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
280 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
281 |
cat, dir = fetch_catalog(server) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
282 |
list_newest_fmris(cat) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
283 |
shutil.rmtree(dir) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
284 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
285 |
else: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
286 |
if pargs == None or len(pargs) == 0: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
287 |
usage(_("must specify at least one pkgfmri")) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
288 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
289 |
if not basedir: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
290 |
basedir = os.getcwd() |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
291 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
292 |
for pkgfmri in pargs: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
293 |
if not pkgfmri.startswith("pkg:/"): |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
294 |
pkgfmri = "pkg:/%s" % pkgfmri |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
295 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
296 |
try: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
297 |
fmri = pkg.fmri.PkgFmri(pkgfmri) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
298 |
except AssertionError: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
299 |
error(_("pkgfmri %s needs a version string") % |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
300 |
pkgfmri) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
301 |
return 1 |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
302 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
303 |
mfstpath = fetch_manifest(server, fmri, basedir) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
304 |
content_hashes = hashes_from_mfst(mfstpath) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
305 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
306 |
fetch_files_byhash(server, content_hashes, |
420
0b6ecdba5641
2272 pkgrecv should uncompress by default
Brad Hall <bhall@eng.sun.com>
parents:
409
diff
changeset
|
307 |
os.path.dirname(mfstpath), keep_compressed) |
375
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
308 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
309 |
return 0 |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
310 |
|
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
311 |
if __name__ == "__main__": |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
312 |
try: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
313 |
ret = main_func() |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
314 |
except SystemExit, e: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
315 |
raise e |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
316 |
except KeyboardInterrupt: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
317 |
print "Interrupted" |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
318 |
sys.exit(1) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
319 |
except: |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
320 |
traceback.print_exc() |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
321 |
sys.exit(99) |
fa5286b09191
1773 Want tool to obtain contents of packages
johansen <johansen@sun.com>
parents:
diff
changeset
|
322 |
sys.exit(ret) |