catalog.py revision 147
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
import os
import re
import sha
import shutil
import time
import urllib
"""A Catalog is the representation of the package FMRIs available to
this client or repository. Both purposes utilize the same storage
format.
The serialized structure of the repository is an unordered list of
available package versions, followed by an unordered list of
incorporation relationships between packages. This latter section
allows the graph to be topologically sorted by the client.
S Last-Modified: [timespec]
XXX A authority mirror-uri ...
XXX ...
V fmri
V fmri
...
C fmri
C fmri
...
I fmri fmri
I fmri fmri
...
"""
# XXX Mirroring records also need to be allowed from client
# configuration, and not just catalogs.
#
# XXX It would be nice to include available tags and package sizes,
# although this could also be calculated from the set of manifests.
#
# XXX self.pkgs should be a dictionary, accessed by fmri string (or
# package name). Current code is O(N_packages) O(M_versions), should be
# O(1) O(M_versions), and possibly O(1) O(1). Likely a similar need for
# critical_pkgs.
#
# XXX Initial estimates suggest that the Catalog could be composed of
# 1e5 - 1e7 lines. Catalogs across these magnitudes will need to be
# spread out into chunks, and may require a delta-oriented update
# interface.
self.authorities = {}
self.critical_pkgs = []
# each V line is an fmri
if m != None:
if m != None:
if m != None:
None))
return
#
# XXX This package is already in the catalog
# with some version set. Are we updating the
# version set or merging the two?
#
# Skip the append in the else clause
break
else:
if critical:
"""Iterate through the catalogs, looking for an exact fmri
match. XXX Returns a list of Package objects."""
"""Iterate through the catalogs, looking for a regular
expression match. Returns a sorted list of PkgFmri objects,
newest versions first."""
ret = []
if ret == []:
raise KeyError, "pattern '%s' not found in catalog" \
% regex
s = ""
s = s + p.get_catalog_entry()
for c in self.critical_pkgs:
s = s + "C %s\n" % p
s = s + "I %s\n" % r
return s
"""XXX -a to see all versions of all packages. Otherwise
default is to display latest version of packages."""
# XXX no access to image means that client use of this function
# limited to unsophisticated output...
print "pkg: catalog is empty"
return
print "%-50s" % p.fmri
for v in p.pversions:
print " %20s" % v.version
if __name__ == "__main__":
c = Catalog()
for f in [
]:
c.add_fmri(f)
print c
tps = [
"pkg:/test@1.0,5.10-1:20070101T120000Z",
"pkg:/test@1.0,5.11-1:20061231T120000Z",
"pkg:/test@1.0,5.11-2",
"pkg:/test@1.0,5.11-3"
]
print "matches for %s:" % tp
print " ", p
for p in c.get_regex_matching_fmris("test"):
print p
try:
l = c.get_regex_matching_fmris("flob")
except KeyError:
print "correctly determined no match for 'flob'"
for p in c.gen_package_versions():
print p