catalog.py revision 174
23N/A# The contents of this file are subject to the terms of the 23N/A# Common Development and Distribution License (the "License"). 23N/A# You may not use this file except in compliance with the License. 23N/A# See the License for the specific language governing permissions 23N/A# and limitations under the License. 23N/A# When distributing Covered Code, include this CDDL HEADER in each 23N/A# If applicable, add the following below this CDDL HEADER, with the 23N/A# fields enclosed by brackets "[]" replaced with your own identifying 23N/A# information: Portions Copyright [yyyy] [name of copyright owner] 221N/A# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23N/A# Use is subject to license terms. 204N/A """A Catalog is the representation of the package FMRIs available to 157N/A this client or repository. Both purposes utilize the same storage 157N/A The serialized structure of the repository is an unordered list of 23N/A available package versions, followed by an unordered list of 258N/A incorporation relationships between packages. This latter section 258N/A allows the graph to be topologically sorted by the client. 258N/A S Last-Modified: [timespec] 34N/A XXX A authority mirror-uri ... 26N/A # XXX Mirroring records also need to be allowed from client 26N/A # configuration, and not just catalogs. 50N/A # XXX It would be nice to include available tags and package sizes, 50N/A # although this could also be calculated from the set of manifests. 26N/A # XXX Current code is O(N_packages) O(M_versions), should be 26N/A # O(1) O(M_versions), and possibly O(1) O(1). 270N/A # XXX Initial estimates suggest that the Catalog could be composed of 270N/A # 1e5 - 1e7 lines. Catalogs across these magnitudes will need to be 270N/A # spread out into chunks, and may require a delta-oriented update 59N/A """Create a catalog. If the path supplied does not exist, 37N/A this will create the required directory structure. 59N/A Otherwise, if the directories are already in place, the 59N/A existing catalog is opened""" 195N/A """Add a package, named by the fmri, to the catalog. 195N/A Throws an exception if an identical package is already 195N/A present. Throws an exception if package has no version.""" 157N/A "Unversioned FMRI not supported: %s" %
fmri 204N/A "Package is already in the catalog" 195N/A """Takes the list of in-memory attributes and returns 220N/A a list of strings, each string naming an attribute.""" 270N/A s =
"S %s: %s\n" % (k, v)
270N/A """Walk the on-disk package data and build (or rebuild) 270N/A the package catalog.""" 270N/A # XXX eschew os.walk in favor of another os.listdir here? 258N/A """Iterate through the catalog, looking for packages matching 258N/A 'pattern', based on the function in 'matcher' and the versioning 258N/A constraint described by 'constraint'. If 'matcher' is None, 258N/A uses fmri subset matching as the default. Returns a sorted list 258N/A of PkgFmri objects, newest versions first. If 'counthash' is a 258N/A dictionary, instead store the number of matched fmris for each 258N/A package name which was matched.""" 157N/A # 'pattern' may be a partially or fully decorated fmri; we want 157N/A # to extract its name and version to match separately against 157N/A # XXX "5.11" here needs to be saner 270N/A # Handle old two-column catalog file, mostly in 204N/A "patterns '%s' match no packages in catalog" % \
220N/A """A generator function that produces FMRIs as it 220N/A iterates over the contents of the catalog.""" 220N/A # Handle old two-column catalog file, mostly in 220N/A """Load attributes from the catalog file into the in-memory 220N/A attributes dictionary""" 204N/A """Returns the number of packages in the catalog.""" 204N/A """A class method that takes a file-like object and 204N/A a path. This is the other half of catalog.send(). It 204N/A reads a stream as an incoming catalog and lays it down 157N/A # XXX Need to be able to handle old and new 204N/A """Save attributes from the in-memory catalog to a file 204N/A specified by filenm.""" 204N/A """Send the contents of this catalog out to the filep 204N/A specified as an argument.""" 204N/A # Send attributes first. 264N/A # Missing catalog is fine; other errors need to be 204N/A# In order to avoid a fine from the Department of Redundancy Department, 204N/A# allow these methods to be invoked without explictly naming the Catalog class. 264N/A "pkg:/test@1.0,5.10-1:20070101T120000Z",
264N/A "pkg:/test@1.0,5.11-1:20061231T120000Z",
264N/A "pkg:/test@1.0,5.11-2",
204N/A print "correctly determined no match for 'flob'"