author | Alasdair Lumsden <al@everycity.co.uk> |
Sat, 03 Sep 2011 23:27:12 +0000 | |
branch | oi_151a |
changeset 2522 | 8cb391c2269d |
parent 2112 | 5e0694e53b38 |
child 2546 | 2b1fa6a54b5e |
permissions | -rw-r--r-- |
1516
8c950a3b4171
10485 move pkg(5) to Python 2.6
Rich Burridge <rich.burridge@sun.com>
parents:
1507
diff
changeset
|
1 |
#!/usr/bin/python |
46
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
2 |
# |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
3 |
# CDDL HEADER START |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
4 |
# |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
5 |
# The contents of this file are subject to the terms of the |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
6 |
# Common Development and Distribution License (the "License"). |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
7 |
# You may not use this file except in compliance with the License. |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
8 |
# |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
9 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
10 |
# or http://www.opensolaris.org/os/licensing. |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
11 |
# See the License for the specific language governing permissions |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
12 |
# and limitations under the License. |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
13 |
# |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
15 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
16 |
# If applicable, add the following below this CDDL HEADER, with the |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
19 |
# |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
20 |
# CDDL HEADER END |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
21 |
# |
86a10bea7bb6
commonize file/ prefix handling; sketch manifest difference algorithm
Stephen Hahn <sch@sun.com>
parents:
diff
changeset
|
22 |
|
1895
0a260cc2a689
15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents:
1836
diff
changeset
|
23 |
# Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. |
119
537d69114be4
Implement bundled file downloads using filelist
johansen <johansen@sun.com>
parents:
108
diff
changeset
|
24 |
|
873
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
25 |
import calendar |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
26 |
import cStringIO |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
27 |
import datetime |
384
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
28 |
import errno |
1516
8c950a3b4171
10485 move pkg(5) to Python 2.6
Rich Burridge <rich.burridge@sun.com>
parents:
1507
diff
changeset
|
29 |
import hashlib |
873
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
30 |
import locale |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
31 |
import OpenSSL.crypto as osc |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
32 |
import operator |
119
537d69114be4
Implement bundled file downloads using filelist
johansen <johansen@sun.com>
parents:
108
diff
changeset
|
33 |
import os |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
34 |
import pkg.client.api_errors as api_errors |
873
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
35 |
import pkg.portable as portable |
386
5cd680466abe
2147 depot should check port instead of showing traceback if port binding fails
Shawn Walker <swalker@opensolaris.org>
parents:
384
diff
changeset
|
36 |
import platform |
5cd680466abe
2147 depot should check port instead of showing traceback if port binding fails
Shawn Walker <swalker@opensolaris.org>
parents:
384
diff
changeset
|
37 |
import re |
873
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
38 |
import shutil |
1507
b956ea23d3a6
11735 pkg history data files should not be executable
Richard Lowe <richlowe@richlowe.net>
parents:
1505
diff
changeset
|
39 |
import stat |
1035
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
40 |
import struct |
873
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
41 |
import sys |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
42 |
import time |
145
08bee7fd13f6
Add versioning to the protocols
Danek Duvall <danek.duvall@sun.com>
parents:
119
diff
changeset
|
43 |
import urllib |
08bee7fd13f6
Add versioning to the protocols
Danek Duvall <danek.duvall@sun.com>
parents:
119
diff
changeset
|
44 |
import urlparse |
342
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
45 |
import zlib |
462
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
46 |
|
2026
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
47 |
from pkg.pkggzip import PkgGzipFile |
319
39b8b5c538bf
1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents:
310
diff
changeset
|
48 |
from pkg.client.imagetypes import img_type_names, IMG_NONE |
39b8b5c538bf
1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents:
310
diff
changeset
|
49 |
from pkg import VERSION |
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
285
diff
changeset
|
50 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
51 |
# Minimum number of days to issue warning before a certificate expires |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
52 |
MIN_WARN_DAYS = datetime.timedelta(days=30) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
53 |
|
1352
5c92c9d342ef
11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents:
1318
diff
changeset
|
54 |
# Copied from image.py as image.py can't be imported here (circular reference). |
5c92c9d342ef
11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents:
1318
diff
changeset
|
55 |
PKG_STATE_INSTALLED = 2 |
5c92c9d342ef
11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents:
1318
diff
changeset
|
56 |
|
2026
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
57 |
# Constant string used across many modules as a property name. |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
58 |
SIGNATURE_POLICY = "signature-policy" |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
59 |
|
1023
73f73773b4c9
6358 Release Notes message after Update All needs to be updated
John Rice <john.rice@sun.com>
parents:
956
diff
changeset
|
60 |
def get_release_notes_url(): |
73f73773b4c9
6358 Release Notes message after Update All needs to be updated
John Rice <john.rice@sun.com>
parents:
956
diff
changeset
|
61 |
"""Return a release note URL pointing to the correct release notes |
73f73773b4c9
6358 Release Notes message after Update All needs to be updated
John Rice <john.rice@sun.com>
parents:
956
diff
changeset
|
62 |
for this version""" |
73f73773b4c9
6358 Release Notes message after Update All needs to be updated
John Rice <john.rice@sun.com>
parents:
956
diff
changeset
|
63 |
|
73f73773b4c9
6358 Release Notes message after Update All needs to be updated
John Rice <john.rice@sun.com>
parents:
956
diff
changeset
|
64 |
# TBD: replace with a call to api.info() that can return a "release" |
73f73773b4c9
6358 Release Notes message after Update All needs to be updated
John Rice <john.rice@sun.com>
parents:
956
diff
changeset
|
65 |
# attribute of form YYYYMM against the SUNWsolnm package |
2522
8cb391c2269d
Updating release notes link
Alasdair Lumsden <al@everycity.co.uk>
parents:
2112
diff
changeset
|
66 |
return "http://wiki.openindiana.org/oi/oi_151a+Release+Notes" |
1023
73f73773b4c9
6358 Release Notes message after Update All needs to be updated
John Rice <john.rice@sun.com>
parents:
956
diff
changeset
|
67 |
|
443
5ffa5b7dac9c
2589 pyc files generate lots of verify chaff
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
429
diff
changeset
|
68 |
def time_to_timestamp(t): |
462
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
69 |
"""convert seconds since epoch to %Y%m%dT%H%M%SZ format""" |
443
5ffa5b7dac9c
2589 pyc files generate lots of verify chaff
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
429
diff
changeset
|
70 |
# XXX optimize? |
5ffa5b7dac9c
2589 pyc files generate lots of verify chaff
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
429
diff
changeset
|
71 |
return time.strftime("%Y%m%dT%H%M%SZ", time.gmtime(t)) |
5ffa5b7dac9c
2589 pyc files generate lots of verify chaff
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
429
diff
changeset
|
72 |
|
5ffa5b7dac9c
2589 pyc files generate lots of verify chaff
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
429
diff
changeset
|
73 |
def timestamp_to_time(ts): |
462
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
74 |
"""convert %Y%m%dT%H%M%SZ format to seconds since epoch""" |
443
5ffa5b7dac9c
2589 pyc files generate lots of verify chaff
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
429
diff
changeset
|
75 |
# XXX optimize? |
5ffa5b7dac9c
2589 pyc files generate lots of verify chaff
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
429
diff
changeset
|
76 |
return calendar.timegm(time.strptime(ts, "%Y%m%dT%H%M%SZ")) |
5ffa5b7dac9c
2589 pyc files generate lots of verify chaff
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
429
diff
changeset
|
77 |
|
462
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
78 |
def copyfile(src_path, dst_path): |
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
79 |
"""copy a file, preserving attributes, ownership, etc. where possible""" |
873
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
80 |
fs = os.lstat(src_path) |
462
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
81 |
shutil.copy2(src_path, dst_path) |
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
82 |
try: |
873
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
83 |
portable.chown(dst_path, fs.st_uid, fs.st_gid) |
462
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
84 |
except OSError, e: |
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
85 |
if e.errno != errno.EPERM: |
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
86 |
raise |
956
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
87 |
def expanddirs(dirs): |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
88 |
"""given a set of directories, return expanded set that includes |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
89 |
all components""" |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
90 |
out = set() |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
91 |
for d in dirs: |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
92 |
p = d |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
93 |
while p != "": |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
94 |
out.add(p) |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
95 |
p = os.path.dirname(p) |
adf6bdfdb3b5
6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
941
diff
changeset
|
96 |
return out |
462
910600c14093
45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
461
diff
changeset
|
97 |
|
310
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
285
diff
changeset
|
98 |
def url_affix_trailing_slash(u): |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
285
diff
changeset
|
99 |
if u[-1] != '/': |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
285
diff
changeset
|
100 |
u = u + '/' |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
285
diff
changeset
|
101 |
|
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
285
diff
changeset
|
102 |
return u |
8fa744df663a
975 Catalogs need to know their origins
johansen <johansen@sun.com>
parents:
285
diff
changeset
|
103 |
|
696
6bbfd2dece6f
4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents:
670
diff
changeset
|
104 |
_client_version = "pkg/%s (%s %s; %s %s; %%s; %%s)" % \ |
319
39b8b5c538bf
1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents:
310
diff
changeset
|
105 |
(VERSION, portable.util.get_canonical_os_name(), platform.machine(), |
39b8b5c538bf
1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents:
310
diff
changeset
|
106 |
portable.util.get_os_release(), platform.version()) |
39b8b5c538bf
1104 want custom user-agent string
Danek Duvall <danek.duvall@sun.com>
parents:
310
diff
changeset
|
107 |
|
1191
a48bee2a4b2e
305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents:
1142
diff
changeset
|
108 |
def user_agent_str(img, client_name): |
a48bee2a4b2e
305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents:
1142
diff
changeset
|
109 |
|
a48bee2a4b2e
305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents:
1142
diff
changeset
|
110 |
if not img or img.type is None: |
a48bee2a4b2e
305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents:
1142
diff
changeset
|
111 |
imgtype = IMG_NONE |
a48bee2a4b2e
305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents:
1142
diff
changeset
|
112 |
else: |
a48bee2a4b2e
305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents:
1142
diff
changeset
|
113 |
imgtype = img.type |
a48bee2a4b2e
305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents:
1142
diff
changeset
|
114 |
|
a48bee2a4b2e
305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents:
1142
diff
changeset
|
115 |
useragent = _client_version % (img_type_names[imgtype], client_name) |
a48bee2a4b2e
305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents:
1142
diff
changeset
|
116 |
|
a48bee2a4b2e
305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents:
1142
diff
changeset
|
117 |
return useragent |
a48bee2a4b2e
305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents:
1142
diff
changeset
|
118 |
|
327
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
119 |
_hostname_re = re.compile("^[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9]+\.?)*$") |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
120 |
_invalid_host_chars = re.compile(".*[^a-zA-Z0-9\-\.]+") |
1895
0a260cc2a689
15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents:
1836
diff
changeset
|
121 |
_valid_proto = ["file", "http", "https"] |
327
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
122 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
123 |
def valid_pub_prefix(prefix): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
124 |
"""Verify that the publisher prefix only contains valid characters.""" |
327
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
125 |
|
1142
64d164b5bf04
9164 misc.valid_pub_prefix and misc.valid_pub_url should handle None
Shawn Walker <srw@sun.com>
parents:
1072
diff
changeset
|
126 |
if not prefix: |
64d164b5bf04
9164 misc.valid_pub_prefix and misc.valid_pub_url should handle None
Shawn Walker <srw@sun.com>
parents:
1072
diff
changeset
|
127 |
return False |
64d164b5bf04
9164 misc.valid_pub_prefix and misc.valid_pub_url should handle None
Shawn Walker <srw@sun.com>
parents:
1072
diff
changeset
|
128 |
|
327
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
129 |
# This is a workaround for the the hostname_re being slow when |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
130 |
# it comes to finding invalid characters in the prefix string. |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
131 |
if _invalid_host_chars.match(prefix): |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
132 |
# prefix bad chars |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
133 |
return False |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
134 |
|
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
135 |
if _hostname_re.match(prefix): |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
136 |
return True |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
137 |
|
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
138 |
return False |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
139 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
140 |
def valid_pub_url(url): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
141 |
"""Verify that the publisher URL contains only valid characters.""" |
327
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
142 |
|
1142
64d164b5bf04
9164 misc.valid_pub_prefix and misc.valid_pub_url should handle None
Shawn Walker <srw@sun.com>
parents:
1072
diff
changeset
|
143 |
if not url: |
64d164b5bf04
9164 misc.valid_pub_prefix and misc.valid_pub_url should handle None
Shawn Walker <srw@sun.com>
parents:
1072
diff
changeset
|
144 |
return False |
64d164b5bf04
9164 misc.valid_pub_prefix and misc.valid_pub_url should handle None
Shawn Walker <srw@sun.com>
parents:
1072
diff
changeset
|
145 |
|
327
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
146 |
# First split the URL and check if the scheme is one we support |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
147 |
o = urlparse.urlsplit(url) |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
148 |
|
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
149 |
if not o[0] in _valid_proto: |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
150 |
return False |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
151 |
|
1895
0a260cc2a689
15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents:
1836
diff
changeset
|
152 |
if o[0] == "file": |
0a260cc2a689
15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents:
1836
diff
changeset
|
153 |
scheme, netloc, path, params, query, fragment = \ |
0a260cc2a689
15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents:
1836
diff
changeset
|
154 |
urlparse.urlparse(url, "file", allow_fragments=0) |
0a260cc2a689
15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents:
1836
diff
changeset
|
155 |
path = urllib.url2pathname(path) |
0a260cc2a689
15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents:
1836
diff
changeset
|
156 |
if not os.path.abspath(path): |
0a260cc2a689
15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents:
1836
diff
changeset
|
157 |
return False |
0a260cc2a689
15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents:
1836
diff
changeset
|
158 |
# No further validation to be done. |
0a260cc2a689
15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents:
1836
diff
changeset
|
159 |
return True |
0a260cc2a689
15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents:
1836
diff
changeset
|
160 |
|
327
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
161 |
# Next verify that the network location is valid |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
162 |
host, port = urllib.splitport(o[1]) |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
163 |
|
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
164 |
if not host or _invalid_host_chars.match(host): |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
165 |
return False |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
166 |
|
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
167 |
if _hostname_re.match(host): |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
168 |
return True |
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
169 |
|
6c6bd07efe8d
1031 authority prefix needs validation
johansen <johansen@sun.com>
parents:
319
diff
changeset
|
170 |
return False |
342
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
171 |
|
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
172 |
def gunzip_from_stream(gz, outfile): |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
173 |
"""Decompress a gzipped input stream into an output stream. |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
174 |
|
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
175 |
The argument 'gz' is an input stream of a gzipped file (XXX make it do |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
176 |
either a gzipped file or raw zlib compressed data), and 'outfile' is is |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
177 |
an output stream. gunzip_from_stream() decompresses data from 'gz' and |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
178 |
writes it to 'outfile', and returns the hexadecimal SHA-1 sum of that |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
179 |
data. |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
180 |
""" |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
181 |
|
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
182 |
FHCRC = 2 |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
183 |
FEXTRA = 4 |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
184 |
FNAME = 8 |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
185 |
FCOMMENT = 16 |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
186 |
|
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
187 |
# Read the header |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
188 |
magic = gz.read(2) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
189 |
if magic != "\037\213": |
621
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
576
diff
changeset
|
190 |
raise zlib.error, "Not a gzipped file" |
342
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
191 |
method = ord(gz.read(1)) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
192 |
if method != 8: |
621
6c144915eed1
551 IPS should handle socket errors
johansen <johansen@sun.com>
parents:
576
diff
changeset
|
193 |
raise zlib.error, "Unknown compression method" |
342
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
194 |
flag = ord(gz.read(1)) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
195 |
gz.read(6) # Discard modtime, extraflag, os |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
196 |
|
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
197 |
# Discard an extra field |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
198 |
if flag & FEXTRA: |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
199 |
xlen = ord(gz.read(1)) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
200 |
xlen = xlen + 256 * ord(gz.read(1)) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
201 |
gz.read(xlen) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
202 |
|
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
203 |
# Discard a null-terminated filename |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
204 |
if flag & FNAME: |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
205 |
while True: |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
206 |
s = gz.read(1) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
207 |
if not s or s == "\000": |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
208 |
break |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
209 |
|
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
210 |
# Discard a null-terminated comment |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
211 |
if flag & FCOMMENT: |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
212 |
while True: |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
213 |
s = gz.read(1) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
214 |
if not s or s == "\000": |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
215 |
break |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
216 |
|
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
217 |
# Discard a 16-bit CRC |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
218 |
if flag & FHCRC: |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
219 |
gz.read(2) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
220 |
|
1516
8c950a3b4171
10485 move pkg(5) to Python 2.6
Rich Burridge <rich.burridge@sun.com>
parents:
1507
diff
changeset
|
221 |
shasum = hashlib.sha1() |
342
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
222 |
dcobj = zlib.decompressobj(-zlib.MAX_WBITS) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
223 |
|
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
224 |
while True: |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
225 |
buf = gz.read(64 * 1024) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
226 |
if buf == "": |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
227 |
ubuf = dcobj.flush() |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
228 |
shasum.update(ubuf) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
229 |
outfile.write(ubuf) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
230 |
break |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
231 |
ubuf = dcobj.decompress(buf) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
232 |
shasum.update(ubuf) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
233 |
outfile.write(ubuf) |
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
234 |
|
5e1f4d8429bf
669 Need method to print package licenses before installation
Danek Duvall <danek.duvall@sun.com>
parents:
327
diff
changeset
|
235 |
return shasum.hexdigest() |
384
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
236 |
|
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
237 |
class PipeError(Exception): |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
238 |
""" Pipe exception. """ |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
239 |
|
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
240 |
def __init__(self, args=None): |
1516
8c950a3b4171
10485 move pkg(5) to Python 2.6
Rich Burridge <rich.burridge@sun.com>
parents:
1507
diff
changeset
|
241 |
self._args = args |
384
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
242 |
|
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
243 |
def msg(*text): |
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
409
diff
changeset
|
244 |
""" Emit a message. """ |
384
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
245 |
|
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
246 |
try: |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
247 |
print ' '.join([str(l) for l in text]) |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
248 |
except IOError, e: |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
249 |
if e.errno == errno.EPIPE: |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
250 |
raise PipeError, e |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
251 |
raise |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
252 |
|
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
253 |
def emsg(*text): |
429
6c9cbb6e6600
983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents:
409
diff
changeset
|
254 |
""" Emit a message to sys.stderr. """ |
384
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
255 |
|
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
256 |
try: |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
257 |
print >> sys.stderr, ' '.join([str(l) for l in text]) |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
258 |
except IOError, e: |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
259 |
if e.errno == errno.EPIPE: |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
260 |
raise PipeError, e |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
261 |
raise |
9d4746e5dd3e
115 pkg needs to not have a cow on a SIGPIPE
Shawn Walker <swalker@opensolaris.org>
parents:
351
diff
changeset
|
262 |
|
791
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
263 |
def setlocale(category, loc=None, printer=None): |
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
264 |
"""Wraps locale.setlocale(), falling back to the C locale if the desired |
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
265 |
locale is broken or unavailable. The 'printer' parameter should be a |
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
266 |
function which takes a string and displays it. If 'None' (the default), |
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
267 |
setlocale() will print the message to stderr.""" |
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
268 |
|
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
269 |
if printer is None: |
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
270 |
printer = emsg |
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
271 |
|
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
272 |
try: |
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
273 |
locale.setlocale(category, loc) |
1318
a12f41da2189
8263 misc.setlocale should handle locale.getdefaultlocale failure
Tom Mueller <Tom.Mueller@sun.com>
parents:
1191
diff
changeset
|
274 |
# Because of Python bug 813449, getdefaultlocale may fail |
a12f41da2189
8263 misc.setlocale should handle locale.getdefaultlocale failure
Tom Mueller <Tom.Mueller@sun.com>
parents:
1191
diff
changeset
|
275 |
# with a ValueError even if setlocale succeeds. So we call |
1507
b956ea23d3a6
11735 pkg history data files should not be executable
Richard Lowe <richlowe@richlowe.net>
parents:
1505
diff
changeset
|
276 |
# it here to prevent having this error raised if it is |
1318
a12f41da2189
8263 misc.setlocale should handle locale.getdefaultlocale failure
Tom Mueller <Tom.Mueller@sun.com>
parents:
1191
diff
changeset
|
277 |
# called later by other non-pkg(5) code. |
a12f41da2189
8263 misc.setlocale should handle locale.getdefaultlocale failure
Tom Mueller <Tom.Mueller@sun.com>
parents:
1191
diff
changeset
|
278 |
locale.getdefaultlocale() |
a12f41da2189
8263 misc.setlocale should handle locale.getdefaultlocale failure
Tom Mueller <Tom.Mueller@sun.com>
parents:
1191
diff
changeset
|
279 |
except (locale.Error, ValueError): |
791
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
280 |
try: |
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
281 |
dl = " '%s.%s'" % locale.getdefaultlocale() |
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
282 |
except ValueError: |
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
283 |
dl = "" |
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
284 |
printer("Unable to set locale%s; locale package may be broken " |
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
285 |
"or\nnot installed. Reverting to C locale." % dl) |
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
286 |
locale.setlocale(category, "C") |
123e9401e939
5778 Inability to set locale leads to stack trace
Danek Duvall <danek.duvall@sun.com>
parents:
779
diff
changeset
|
287 |
|
1035
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
288 |
def bytes_to_str(bytes, format=None): |
451
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
289 |
"""Returns a human-formatted string representing the number of bytes |
1035
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
290 |
in the largest unit possible. If provided, 'format' should be a string |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
291 |
which can be formatted with a dictionary containing a float 'num' and |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
292 |
string 'unit'.""" |
451
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
293 |
|
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
294 |
units = [ |
660
ea2809ad4582
4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents:
641
diff
changeset
|
295 |
(_("B"), 2**10), |
ea2809ad4582
4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents:
641
diff
changeset
|
296 |
(_("kB"), 2**20), |
ea2809ad4582
4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents:
641
diff
changeset
|
297 |
(_("MB"), 2**30), |
ea2809ad4582
4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents:
641
diff
changeset
|
298 |
(_("GB"), 2**40), |
ea2809ad4582
4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents:
641
diff
changeset
|
299 |
(_("TB"), 2**50), |
ea2809ad4582
4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents:
641
diff
changeset
|
300 |
(_("PB"), 2**60), |
ea2809ad4582
4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents:
641
diff
changeset
|
301 |
(_("EB"), 2**70) |
451
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
302 |
] |
386
5cd680466abe
2147 depot should check port instead of showing traceback if port binding fails
Shawn Walker <swalker@opensolaris.org>
parents:
384
diff
changeset
|
303 |
|
451
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
304 |
for uom, limit in units: |
660
ea2809ad4582
4126 I10n update for IPS CLI PM and UM
John Rice <john.rice@sun.com>
parents:
641
diff
changeset
|
305 |
if uom != _("EB") and bytes >= limit: |
451
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
306 |
# Try the next largest unit of measure unless this is |
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
307 |
# the largest or if the byte size is within the current |
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
308 |
# unit of measure's range. |
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
309 |
continue |
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
310 |
else: |
1035
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
311 |
if not format: |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
312 |
format = "%(num).2f %(unit)s" |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
313 |
return format % { |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
314 |
"num": round(bytes / float(limit / 2**10), 2), |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
315 |
"unit": uom |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
316 |
} |
451
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
317 |
|
2028
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
318 |
def get_rel_path(request, uri, pub=None): |
451
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
319 |
# Calculate the depth of the current request path relative to our base |
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
320 |
# uri. path_info always ends with a '/' -- so ignore it when |
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
321 |
# calculating depth. |
2028
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
322 |
rpath = request.path_info |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
323 |
if pub: |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
324 |
rpath = rpath.replace("/%s/" % pub, "/") |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
325 |
depth = rpath.count("/") - 1 |
451
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
326 |
return ("../" * depth) + uri |
74f1fe85fe2d
1324 RSS / Atom feeds of repository updates
Shawn Walker <shawn.walker@sun.com>
parents:
443
diff
changeset
|
327 |
|
487
9cb85c3d8491
2556 client should measure download progress by compressed size
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
328 |
def get_pkg_otw_size(action): |
9cb85c3d8491
2556 client should measure download progress by compressed size
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
329 |
"""Takes a file action and returns the over-the-wire size of |
9cb85c3d8491
2556 client should measure download progress by compressed size
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
330 |
a package as an integer. The OTW size is the compressed size, |
9cb85c3d8491
2556 client should measure download progress by compressed size
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
331 |
pkg.csize. If that value isn't available, it returns pkg.size. |
9cb85c3d8491
2556 client should measure download progress by compressed size
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
332 |
If pkg.size isn't available, return zero.""" |
9cb85c3d8491
2556 client should measure download progress by compressed size
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
333 |
|
9cb85c3d8491
2556 client should measure download progress by compressed size
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
334 |
size = action.attrs.get("pkg.csize", 0) |
9cb85c3d8491
2556 client should measure download progress by compressed size
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
335 |
if size == 0: |
9cb85c3d8491
2556 client should measure download progress by compressed size
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
336 |
size = action.attrs.get("pkg.size", 0) |
9cb85c3d8491
2556 client should measure download progress by compressed size
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
337 |
|
9cb85c3d8491
2556 client should measure download progress by compressed size
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
338 |
return int(size) |
9cb85c3d8491
2556 client should measure download progress by compressed size
johansen <johansen@sun.com>
parents:
462
diff
changeset
|
339 |
|
873
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
340 |
def get_data_digest(data, length=None, return_content=False): |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
341 |
"""Returns a tuple of (SHA-1 hexdigest, content). |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
342 |
|
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
343 |
'data' should be a file-like object or a pathname to a file. |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
344 |
|
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
345 |
'length' should be an integer value representing the size of |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
346 |
the contents of data in bytes. |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
347 |
|
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
348 |
'return_content' is a boolean value indicating whether the |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
349 |
second tuple value should contain the content of 'data' or |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
350 |
if the content should be discarded during processing.""" |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
351 |
|
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
352 |
bufsz = 128 * 1024 |
1974
6af683c5bde5
9203 pkgrecv should check for valid destination before beginning download
johansen <johansen@opensolaris.org>
parents:
1970
diff
changeset
|
353 |
closefobj = False |
873
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
354 |
if isinstance(data, basestring): |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
355 |
f = file(data, "rb", bufsz) |
1974
6af683c5bde5
9203 pkgrecv should check for valid destination before beginning download
johansen <johansen@opensolaris.org>
parents:
1970
diff
changeset
|
356 |
closefobj = True |
873
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
357 |
else: |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
358 |
f = data |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
359 |
|
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
360 |
if length is None: |
1038
2514d758e462
7908 publishing api and tools should use os.stat not os.lstat for file size
Shawn Walker <srw@sun.com>
parents:
1035
diff
changeset
|
361 |
length = os.stat(data).st_size |
873
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
362 |
|
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
363 |
# Read the data in chunks and compute the SHA1 hash as it comes in. A |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
364 |
# large read on some platforms (e.g. Windows XP) may fail. |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
365 |
content = cStringIO.StringIO() |
1516
8c950a3b4171
10485 move pkg(5) to Python 2.6
Rich Burridge <rich.burridge@sun.com>
parents:
1507
diff
changeset
|
366 |
fhash = hashlib.sha1() |
873
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
367 |
while length > 0: |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
368 |
data = f.read(min(bufsz, length)) |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
369 |
if return_content: |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
370 |
content.write(data) |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
371 |
fhash.update(data) |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
372 |
|
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
373 |
l = len(data) |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
374 |
if l == 0: |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
375 |
break |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
376 |
length -= l |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
377 |
content.reset() |
1974
6af683c5bde5
9203 pkgrecv should check for valid destination before beginning download
johansen <johansen@opensolaris.org>
parents:
1970
diff
changeset
|
378 |
if closefobj: |
6af683c5bde5
9203 pkgrecv should check for valid destination before beginning download
johansen <johansen@opensolaris.org>
parents:
1970
diff
changeset
|
379 |
f.close() |
873
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
380 |
|
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
381 |
return fhash.hexdigest(), content.read() |
b95d76c53b5e
2691 ability to publish packages to local disk repository
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
838
diff
changeset
|
382 |
|
2026
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
383 |
def compute_compressed_attrs(fname, file_path, data, size, compress_dir, |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
384 |
bufsz=64*1024): |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
385 |
"""Returns the size and hash of the compressed data. If the file |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
386 |
located at file_path doesn't exist or isn't gzipped, it creates a file |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
387 |
in compress_dir named fname.""" |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
388 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
389 |
# |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
390 |
# This check prevents compressing a file which is already compressed. |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
391 |
# This takes CPU load off the depot on large imports of mostly-the-same |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
392 |
# stuff. And in general it saves disk bandwidth, and on ZFS in |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
393 |
# particular it saves us space in differential snapshots. We also need |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
394 |
# to check that the destination is in the same compression format as |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
395 |
# the source, as we must have properly formed files for chash/csize |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
396 |
# properties to work right. |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
397 |
# |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
398 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
399 |
fileneeded = True |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
400 |
if file_path: |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
401 |
if PkgGzipFile.test_is_pkggzipfile(file_path): |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
402 |
fileneeded = False |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
403 |
opath = file_path |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
404 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
405 |
if fileneeded: |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
406 |
opath = os.path.join(compress_dir, fname) |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
407 |
ofile = PkgGzipFile(opath, "wb") |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
408 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
409 |
nbuf = size / bufsz |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
410 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
411 |
for n in range(0, nbuf): |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
412 |
l = n * bufsz |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
413 |
h = (n + 1) * bufsz |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
414 |
ofile.write(data[l:h]) |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
415 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
416 |
m = nbuf * bufsz |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
417 |
ofile.write(data[m:]) |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
418 |
ofile.close() |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
419 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
420 |
data = None |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
421 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
422 |
# Now that the file has been compressed, determine its |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
423 |
# size. |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
424 |
fs = os.stat(opath) |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
425 |
csize = str(fs.st_size) |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
426 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
427 |
# Compute the SHA hash of the compressed file. In order for this to |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
428 |
# work correctly, we have to use the PkgGzipFile class. It omits |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
429 |
# filename and timestamp information from the gzip header, allowing us |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
430 |
# to generate deterministic hashes for different files with identical |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
431 |
# content. |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
432 |
cfile = open(opath, "rb") |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
433 |
chash = hashlib.sha1() |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
434 |
while True: |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
435 |
cdata = cfile.read(bufsz) |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
436 |
if cdata == "": |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
437 |
break |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
438 |
chash.update(cdata) |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
439 |
cfile.close() |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
440 |
return csize, chash |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
441 |
|
1035
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
442 |
def __getvmusage(): |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
443 |
"""Return the amount of virtual memory in bytes currently in use.""" |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
444 |
|
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
445 |
# This works only on Solaris, in 32-bit mode. It may not work on older |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
446 |
# or newer versions than 5.11. Ideally, we would use libproc, or check |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
447 |
# sbrk(0), but this is expedient. In most cases (there's a small chance |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
448 |
# the file will decode, but incorrectly), failure will raise an |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
449 |
# exception, and we'll fail safe. |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
450 |
try: |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
451 |
# Read just the psinfo_t, not the tacked-on lwpsinfo_t |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
452 |
psinfo_arr = file("/proc/self/psinfo").read(232) |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
453 |
psinfo = struct.unpack("6i5I4LHH6L16s80siiIIc3x7i", psinfo_arr) |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
454 |
vsz = psinfo[11] * 1024 |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
455 |
except Exception: |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
456 |
vsz = None |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
457 |
|
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
458 |
return vsz |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
459 |
|
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
460 |
def out_of_memory(): |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
461 |
"""Return an out of memory message, for use in a MemoryError handler.""" |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
462 |
|
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
463 |
vsz = bytes_to_str(__getvmusage(), format="%(num).0f%(unit)s") |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
464 |
|
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
465 |
if vsz is not None: |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
466 |
error = """\ |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
467 |
There is not enough memory to complete the requested operation. At least |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
468 |
%(vsz)s of virtual memory was in use by this command before it ran out of memory. |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
469 |
You must add more memory (swap or physical) or allow the system to access more |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
470 |
existing memory, or quit other programs that may be consuming memory, and try |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
471 |
the operation again.""" |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
472 |
else: |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
473 |
error = """\ |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
474 |
There is not enough memory to complete the requested operation. You must |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
475 |
add more memory (swap or physical) or allow the system to access more existing |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
476 |
memory, or quit other programs that may be consuming memory, and try the |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
477 |
operation again.""" |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
478 |
|
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
479 |
return _(error) % locals() |
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
480 |
|
0e243b7eb121
2297 top level error handler for out of memory conditions needed
Danek Duvall <danek.duvall@sun.com>
parents:
1026
diff
changeset
|
481 |
|
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
482 |
# ImmutableDict and EmptyI for argument defaults |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
483 |
EmptyI = tuple() |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
484 |
|
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
485 |
class ImmutableDict(dict): |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
486 |
def __init__(self, default=EmptyI): |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
487 |
dict.__init__(self, default) |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
488 |
|
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
489 |
def __setitem__(self, item, value): |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
490 |
self.__oops() |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
491 |
|
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
492 |
def __delitem__(self, item, value): |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
493 |
self.__oops() |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
494 |
|
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
495 |
def pop(self, item, default=None): |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
496 |
self.__oops() |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
497 |
|
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
498 |
def popitem(self): |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
499 |
self.__oops() |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
500 |
|
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
501 |
def setdefault(self, item, default=None): |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
502 |
self.__oops() |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
503 |
|
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
504 |
def update(self, d): |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
505 |
self.__oops() |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
506 |
|
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
507 |
def copy(self): |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
508 |
return ImmutableDict() |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
509 |
|
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
510 |
def clear(self): |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
511 |
self.__oops() |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
512 |
|
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
513 |
def __oops(self): |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
514 |
raise TypeError, "Item assignment to ImmutableDict" |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
515 |
|
1505
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
516 |
# A way to have a dictionary be a property |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
517 |
|
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
518 |
class DictProperty(object): |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
519 |
class __InternalProxy(object): |
2026
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
520 |
def __init__(self, obj, fget, fset, fdel, iteritems, keys, |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
521 |
values, iterator, fgetdefault, fsetdefault, update, pop): |
1505
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
522 |
self.__obj = obj |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
523 |
self.__fget = fget |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
524 |
self.__fset = fset |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
525 |
self.__fdel = fdel |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
526 |
self.__iteritems = iteritems |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
527 |
self.__keys = keys |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
528 |
self.__values = values |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
529 |
self.__iter = iterator |
2026
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
530 |
self.__fgetdefault = fgetdefault |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
531 |
self.__fsetdefault = fsetdefault |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
532 |
self.__update = update |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
533 |
self.__pop = pop |
1505
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
534 |
|
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
535 |
def __getitem__(self, key): |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
536 |
if self.__fget is None: |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
537 |
raise AttributeError, "unreadable attribute" |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
538 |
|
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
539 |
return self.__fget(self.__obj, key) |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
540 |
|
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
541 |
def __setitem__(self, key, value): |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
542 |
if self.__fset is None: |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
543 |
raise AttributeError, "can't set attribute" |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
544 |
self.__fset(self.__obj, key, value) |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
545 |
|
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
546 |
def __delitem__(self, key): |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
547 |
if self.__fdel is None: |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
548 |
raise AttributeError, "can't delete attribute" |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
549 |
self.__fdel(self.__obj, key) |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
550 |
|
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
551 |
def iteritems(self): |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
552 |
if self.__iteritems is None: |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
553 |
raise AttributeError, "can't iterate over items" |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
554 |
return self.__iteritems(self.__obj) |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
555 |
|
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
556 |
def keys(self): |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
557 |
if self.__keys is None: |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
558 |
raise AttributeError, "can't iterate over keys" |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
559 |
return self.__keys(self.__obj) |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
560 |
|
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
561 |
def values(self): |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
562 |
if self.__values is None: |
2028
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
563 |
raise AttributeError, "can't iterate over " \ |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
564 |
"values" |
1505
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
565 |
return self.__values(self.__obj) |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
566 |
|
2026
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
567 |
def get(self, key, default=None): |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
568 |
if self.__fgetdefault is None: |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
569 |
raise AttributeError, "can't use get" |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
570 |
return self.__fgetdefault(self.__obj, key, default) |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
571 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
572 |
def setdefault(self, key, default=None): |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
573 |
if self.__fsetdefault is None: |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
574 |
raise AttributeError, "can't use setdefault" |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
575 |
return self.__fsetdefault(self.__obj, key, default) |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
576 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
577 |
def update(self, d): |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
578 |
if self.__update is None: |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
579 |
raise AttributeError, "can't use update" |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
580 |
return self.__update(self.__obj, d) |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
581 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
582 |
def pop(self, d, default): |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
583 |
if self.__pop is None: |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
584 |
raise AttributeError, "can't use pop" |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
585 |
return self.__pop(self.__obj, d, default) |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
586 |
|
1505
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
587 |
def __iter__(self): |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
588 |
if self.__iter is None: |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
589 |
raise AttributeError, "can't iterate" |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
590 |
return self.__iter(self.__obj) |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
591 |
|
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
592 |
def __init__(self, fget=None, fset=None, fdel=None, iteritems=None, |
2026
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
593 |
keys=None, values=None, iterator=None, doc=None, fgetdefault=None, |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
594 |
fsetdefault=None, update=None, pop=None): |
1505
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
595 |
self.__fget = fget |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
596 |
self.__fset = fset |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
597 |
self.__fdel = fdel |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
598 |
self.__iteritems = iteritems |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
599 |
self.__doc__ = doc |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
600 |
self.__keys = keys |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
601 |
self.__values = values |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
602 |
self.__iter = iterator |
2026
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
603 |
self.__fgetdefault = fgetdefault |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
604 |
self.__fsetdefault = fsetdefault |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
605 |
self.__update = update |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
606 |
self.__pop = pop |
1505
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
607 |
|
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
608 |
def __get__(self, obj, objtype=None): |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
609 |
if obj is None: |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
610 |
return self |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
611 |
return self.__InternalProxy(obj, self.__fget, self.__fset, |
2026
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
612 |
self.__fdel, self.__iteritems, self.__keys, self.__values, |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
613 |
self.__iter, self.__fgetdefault, self.__fsetdefault, |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
614 |
self.__update, self.__pop) |
1505
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
615 |
|
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
616 |
|
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
617 |
def get_sorted_publishers(pubs, preferred=None): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
618 |
spubs = [] |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
619 |
for p in sorted(pubs, key=operator.attrgetter("prefix")): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
620 |
if preferred and preferred == p.prefix: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
621 |
spubs.insert(0, p) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
622 |
else: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
623 |
spubs.append(p) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
624 |
return spubs |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
625 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
626 |
def build_cert(path, uri=None, pub=None): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
627 |
"""Take the file given in path, open it, and use it to create |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
628 |
an X509 certificate object. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
629 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
630 |
'uri' is an optional value indicating the uri associated with or that |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
631 |
requires the certificate for access. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
632 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
633 |
'pub' is an optional string value containing the name (prefix) of a |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
634 |
related publisher.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
635 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
636 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
637 |
cf = file(path, "rb") |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
638 |
certdata = cf.read() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
639 |
cf.close() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
640 |
except EnvironmentError, e: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
641 |
if e.errno == errno.ENOENT: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
642 |
raise api_errors.NoSuchCertificate(path, uri=uri, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
643 |
publisher=pub) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
644 |
if e.errno == errno.EACCES: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
645 |
raise api_errors.PermissionsException(e.filename) |
1431
62b6033670e4
10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents:
1352
diff
changeset
|
646 |
if e.errno == errno.EROFS: |
62b6033670e4
10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents:
1352
diff
changeset
|
647 |
raise api_errors.ReadOnlyFileSystemException(e.filename) |
926
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
648 |
raise |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
649 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
650 |
try: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
651 |
return osc.load_certificate(osc.FILETYPE_PEM, certdata) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
652 |
except osc.Error, e: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
653 |
# OpenSSL.crypto.Error |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
654 |
raise api_errors.InvalidCertificate(path, uri=uri, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
655 |
publisher=pub) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
656 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
657 |
def validate_ssl_cert(ssl_cert, prefix=None, uri=None): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
658 |
"""Validates the indicated certificate and returns a pyOpenSSL object |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
659 |
representing it if it is valid.""" |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
660 |
cert = build_cert(ssl_cert, uri=uri, pub=prefix) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
661 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
662 |
if cert.has_expired(): |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
663 |
raise api_errors.ExpiredCertificate(ssl_cert, uri=uri, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
664 |
publisher=prefix) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
665 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
666 |
now = datetime.datetime.utcnow() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
667 |
nb = cert.get_notBefore() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
668 |
t = time.strptime(nb, "%Y%m%d%H%M%SZ") |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
669 |
nbdt = datetime.datetime.utcfromtimestamp( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
670 |
calendar.timegm(t)) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
671 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
672 |
# PyOpenSSL's has_expired() doesn't validate the notBefore |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
673 |
# time on the certificate. Don't ask me why. |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
674 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
675 |
if nbdt > now: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
676 |
raise api_errors.NotYetValidCertificate(ssl_cert, uri=uri, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
677 |
publisher=prefix) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
678 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
679 |
na = cert.get_notAfter() |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
680 |
t = time.strptime(na, "%Y%m%d%H%M%SZ") |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
681 |
nadt = datetime.datetime.utcfromtimestamp( |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
682 |
calendar.timegm(t)) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
683 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
684 |
diff = nadt - now |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
685 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
686 |
if diff <= MIN_WARN_DAYS: |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
687 |
raise api_errors.ExpiringCertificate(ssl_cert, uri=uri, |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
688 |
publisher=prefix, days=diff.days) |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
689 |
|
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
690 |
return cert |
6ee411c9026a
5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents:
873
diff
changeset
|
691 |
|
2026
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
692 |
# Used for the conversion of the signature value between hex and binary. |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
693 |
char_list = "0123456789abcdef" |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
694 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
695 |
def binary_to_hex(s): |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
696 |
"""Converts a string of bytes to a hexadecimal representation. |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
697 |
""" |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
698 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
699 |
res = "" |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
700 |
for i, p in enumerate(s): |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
701 |
p = ord(p) |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
702 |
a = char_list[p % 16] |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
703 |
p = p/16 |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
704 |
b = char_list[p % 16] |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
705 |
res += b + a |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
706 |
return res |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
707 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
708 |
def hex_to_binary(s): |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
709 |
"""Converts a string of hex digits to the binary representation. |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
710 |
""" |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
711 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
712 |
res = "" |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
713 |
for i in range(0, len(s), 2): |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
714 |
res += chr(char_list.find(s[i]) * 16 + |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
715 |
char_list.find(s[i+1])) |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
716 |
return res |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
717 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
718 |
def config_temp_root(): |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
719 |
"""Examine the environment. If the environment has set TMPDIR, TEMP, |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
720 |
or TMP, return None. This tells tempfile to use the environment |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
721 |
settings when creating temporary files/directories. Otherwise, |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
722 |
return a path that the caller should pass to tempfile instead.""" |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
723 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
724 |
default_root = "/var/tmp" |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
725 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
726 |
# In Python's tempfile module, the default temp directory |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
727 |
# includes some paths that are suboptimal for holding large numbers |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
728 |
# of files. If the user hasn't set TMPDIR, TEMP, or TMP in the |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
729 |
# environment, override the default directory for creating a tempfile. |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
730 |
tmp_envs = [ "TMPDIR", "TEMP", "TMP" ] |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
731 |
for ev in tmp_envs: |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
732 |
env_val = os.getenv(ev) |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
733 |
if env_val: |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
734 |
return None |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
735 |
|
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
736 |
return default_root |
d1b30615bc99
9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents:
1974
diff
changeset
|
737 |
|
2028
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
738 |
def parse_uri(uri): |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
739 |
"""Parse the repository location provided and attempt to transform it |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
740 |
into a valid repository URI. |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
741 |
""" |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
742 |
|
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
743 |
if uri.find("://") == -1 and not uri.startswith("file:/"): |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
744 |
# Convert the file path to a URI. |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
745 |
uri = os.path.abspath(uri) |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
746 |
uri = urlparse.urlunparse(("file", "", |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
747 |
urllib.pathname2url(uri), "", "", "")) |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
748 |
|
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
749 |
scheme, netloc, path, params, query, fragment = \ |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
750 |
urlparse.urlparse(uri, "file", allow_fragments=0) |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
751 |
scheme = scheme.lower() |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
752 |
|
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
753 |
if scheme == "file": |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
754 |
# During urlunparsing below, ensure that the path starts with |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
755 |
# only one '/' character, if any are present. |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
756 |
if path.startswith("/"): |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
757 |
path = "/" + path.lstrip("/") |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
758 |
|
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
759 |
# Rebuild the URI with the sanitized components. |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
760 |
return urlparse.urlunparse((scheme, netloc, path, params, |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
761 |
query, fragment)) |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
762 |
|
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
763 |
|
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
764 |
def makedirs(pathname): |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
765 |
"""Create a directory at the specified location if it does not |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
766 |
already exist (including any parent directories) re-raising any |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
767 |
unexpected exceptions as ApiExceptions. |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
768 |
""" |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
769 |
|
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
770 |
try: |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
771 |
os.makedirs(pathname, PKG_DIR_MODE) |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
772 |
except EnvironmentError, e: |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
773 |
if e.filename == pathname and (e.errno == errno.EEXIST or |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
774 |
os.path.exists(e.filename)): |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
775 |
return |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
776 |
elif e.errno == errno.EACCES: |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
777 |
raise api_errors.PermissionsException( |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
778 |
e.filename) |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
779 |
elif e.errno == errno.EROFS: |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
780 |
raise api_errors.ReadOnlyFileSystemException( |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
781 |
e.filename) |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
782 |
elif e.errno != errno.EEXIST or e.filename != pathname: |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
783 |
raise |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
784 |
|
2043
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
785 |
class DummyLock(object): |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
786 |
"""This has the same external interface as threading.Lock, |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
787 |
but performs no locking. This is a placeholder object for situations |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
788 |
where we want to be able to do locking, but don't always need a |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
789 |
lock object present. The object has a held value, that is used |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
790 |
for _is_owned. This is informational and doesn't actually |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
791 |
provide mutual exclusion in any way whatsoever.""" |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
792 |
|
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
793 |
def __init__(self): |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
794 |
self.held = False |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
795 |
|
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
796 |
def acquire(self, blocking=1): |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
797 |
self.held = True |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
798 |
return True |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
799 |
|
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
800 |
def release(self): |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
801 |
self.held = False |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
802 |
return |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
803 |
|
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
804 |
def _is_owned(self): |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
805 |
return self.held |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
806 |
|
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
807 |
@property |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
808 |
def locked(self): |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
809 |
return self.held |
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
810 |
|
852501e586d0
14615 image-update claims failure for un-aquired lock and still succeeds
johansen <johansen@opensolaris.org>
parents:
2028
diff
changeset
|
811 |
|
1505
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
812 |
class Singleton(type): |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
813 |
"""Set __metaclass__ to Singleton to create a singleton. |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
814 |
See http://en.wikipedia.org/wiki/Singleton_pattern """ |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
815 |
|
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
816 |
def __init__(self, name, bases, dictionary): |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
817 |
super(Singleton, self).__init__(name, bases, dictionary) |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
818 |
self.instance = None |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
819 |
|
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
820 |
def __call__(self, *args, **kw): |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
821 |
if self.instance is None: |
2028
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
822 |
self.instance = super(Singleton, self).__call__(*args, |
b2c674e6ee28
16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents:
2026
diff
changeset
|
823 |
**kw) |
1505
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
824 |
|
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
825 |
return self.instance |
cc598d70bbbe
4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
1452
diff
changeset
|
826 |
|
838
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
827 |
EmptyDict = ImmutableDict() |
aafbe4737188
3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents:
835
diff
changeset
|
828 |
|
1026
d4aa3ac69dc0
7878 token_byte_offset file not correctly sorted
Brock Pytlik <bpytlik@sun.com>
parents:
1023
diff
changeset
|
829 |
# Setting the python file buffer size to 128k gives substantial performance |
d4aa3ac69dc0
7878 token_byte_offset file not correctly sorted
Brock Pytlik <bpytlik@sun.com>
parents:
1023
diff
changeset
|
830 |
# gains on certain files. |
d4aa3ac69dc0
7878 token_byte_offset file not correctly sorted
Brock Pytlik <bpytlik@sun.com>
parents:
1023
diff
changeset
|
831 |
PKG_FILE_BUFSIZ = 128 * 1024 |
1507
b956ea23d3a6
11735 pkg history data files should not be executable
Richard Lowe <richlowe@richlowe.net>
parents:
1505
diff
changeset
|
832 |
|
b956ea23d3a6
11735 pkg history data files should not be executable
Richard Lowe <richlowe@richlowe.net>
parents:
1505
diff
changeset
|
833 |
PKG_FILE_MODE = stat.S_IWUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH |
b956ea23d3a6
11735 pkg history data files should not be executable
Richard Lowe <richlowe@richlowe.net>
parents:
1505
diff
changeset
|
834 |
PKG_DIR_MODE = (stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | |
b956ea23d3a6
11735 pkg history data files should not be executable
Richard Lowe <richlowe@richlowe.net>
parents:
1505
diff
changeset
|
835 |
stat.S_IXOTH) |
b956ea23d3a6
11735 pkg history data files should not be executable
Richard Lowe <richlowe@richlowe.net>
parents:
1505
diff
changeset
|
836 |
PKG_RO_FILE_MODE = stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH |
2112
5e0694e53b38
17225 license files mia on image-update from 149 to 150
Shawn Walker <shawn.walker@oracle.com>
parents:
2097
diff
changeset
|
837 |
|
5e0694e53b38
17225 license files mia on image-update from 149 to 150
Shawn Walker <shawn.walker@oracle.com>
parents:
2097
diff
changeset
|
838 |
def relpath(path, start="."): |
5e0694e53b38
17225 license files mia on image-update from 149 to 150
Shawn Walker <shawn.walker@oracle.com>
parents:
2097
diff
changeset
|
839 |
"""Version of relpath to workaround python bug: |
5e0694e53b38
17225 license files mia on image-update from 149 to 150
Shawn Walker <shawn.walker@oracle.com>
parents:
2097
diff
changeset
|
840 |
http://bugs.python.org/issue5117 |
5e0694e53b38
17225 license files mia on image-update from 149 to 150
Shawn Walker <shawn.walker@oracle.com>
parents:
2097
diff
changeset
|
841 |
""" |
5e0694e53b38
17225 license files mia on image-update from 149 to 150
Shawn Walker <shawn.walker@oracle.com>
parents:
2097
diff
changeset
|
842 |
if path and start and start == "/" and path[0] == "/": |
5e0694e53b38
17225 license files mia on image-update from 149 to 150
Shawn Walker <shawn.walker@oracle.com>
parents:
2097
diff
changeset
|
843 |
return path.lstrip("/") |
5e0694e53b38
17225 license files mia on image-update from 149 to 150
Shawn Walker <shawn.walker@oracle.com>
parents:
2097
diff
changeset
|
844 |
return os.path.relpath(path, start=start) |