manifest.py revision 956
39N/A# The contents of this file are subject to the terms of the 39N/A# Common Development and Distribution License (the "License"). 39N/A# You may not use this file except in compliance with the License. 39N/A# See the License for the specific language governing permissions 39N/A# and limitations under the License. 39N/A# When distributing Covered Code, include this CDDL HEADER in each 39N/A# If applicable, add the following below this CDDL HEADER, with the 39N/A# fields enclosed by brackets "[]" replaced with your own identifying 39N/A# information: Portions Copyright [yyyy] [name of copyright owner] 39N/A# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 39N/A# Use is subject to license terms. 39N/A """A Manifest is the representation of the actions composing a specific 39N/A package version on both the client and the repository. Both purposes 39N/A utilize the same storage format. 39N/A The serialized structure of a manifest is an unordered list of actions. 48N/A The special action, "set", represents a package attribute. 48N/A The reserved attribute, "fmri", represents the package and version 48N/A described by this manifest. It is available as a string via the 429N/A attributes dictionary, and as an FMRI object from the fmri member. 48N/A The list of manifest-wide reserved attributes is 48N/A base_directory Default base directory, for non-user images. 39N/A isa Package is intended for a list of ISAs. 39N/A platform Package is intended for a list of platforms. 39N/A relocatable Suitable for User Image. 39N/A All non-prefixed attributes are reserved to the framework. Third 39N/A parties may prefix their attributes with a reversed domain name, domain 205N/A name, or stock symbol. An example might be 39N/A as an indicator that a specific package version is supported by the 39N/A vendor, example.com. 39N/A manifest.null is provided as the null manifest. Differences against the 39N/A null manifest result in the complete set of attributes and actions of 39N/A the non-null manifest, meaning that all operations can be viewed as 39N/A tranitions between the manifest being installed and the manifest already 39N/A present in the image (which may be the null manifest). 315N/A """Return three lists of action pairs representing origin and 315N/A destination actions. The first list contains the pairs 39N/A representing additions, the second list contains the pairs 315N/A representing updates, and the third list contains the pairs 315N/A represnting removals. All three lists are in the order in which 315N/A they should be executed.""" 315N/A # XXX Do we need to find some way to assert that the keys are 72N/A # XXX for now, we force license actions to always be 72N/A # different to insure that existing license files for 72N/A # new versions are always installed 72N/A # XXX Do changed actions need to be sorted at all? This is 72N/A # likely to be the largest list, so we might save significant 59N/A # time by not sorting. Should we sort above? Insert into a 307N/A # singlesort = lambda x: x[0] or x[1] 72N/A """Like the unix utility comm, except that this function 72N/A takes an arbitrary number of manifests and compares them, 59N/A returning a tuple consisting of each manifest's actions 72N/A that are not the same for all manifests, followed by a 72N/A list of actions that are the same in each manifest.""" 202N/A # construct list of dictionaries of actions in each 72N/A # manifest, indexed by unique keys 315N/A # construct list of key sets in each dict 72N/A # determine which common_keys have common actions 111N/A """Where difference() returns three lists, combined_difference() 111N/A returns a single list of the concatenation of the three.""" 111N/A """Output expects that self is newer than other. Use of sets 111N/A requires that we convert the action objects into some marshalled 111N/A form, otherwise set member identities are derived from the 111N/A object pointers, rather than the contents.""" 113N/A """Generate actions in manifest through ordered callable list""" 39N/A """Generate actions in the manifest of type "type" 307N/A through ordered callable list""" 39N/A """Generate the value of the key atrribute for each action 146N/A of type "type" in the manifest.""" 51N/A """Find actions in the manifest which are duplicates (i.e., 123N/A represent the same object) but which are not identical (i.e., 123N/A have all the same attributes).""" 307N/A """Return a key on which actions can be sorted.""" 429N/A """content is the text representation of the manifest""" 429N/A # sdict and odict in difference() above, and have that be our 429N/A # main datastore, rather than the simple list we have now. If 429N/A # we do that here, we can even assert that the "same" action 429N/A # can't be in a manifest twice. (The problem of having the same 429N/A # action more than once in packages that can be installed 429N/A # together has to be solved somewhere else, though.) 429N/A if not l
or l[
0] ==
"#":
429N/A # Add the FMRI to the exception and re-raise 429N/A # Translate old action to new. 342N/A # add any set actions to attributes 315N/A # append any variants and facets to manifest dict 205N/A """Fill attribute array w/ set action contents.""" """Store the manifest contents to disk.""" # We specifically avoid sorting manifests before writing # them to disk-- there's really no point in doing so, since # we'll sort actions globally during packaging operations. """Return the value for the package attribute 'key'.""" """Set the value for the package attribute 'key' to 'value'.""" """This class handles a cache of manifests for the client; it partitions the manifest into multiple files (one per action type) and also builds an on-disk cache of the directories explictly and implicitly referenced by the """get location for manifests, default publisher """Raises KeyError exception if cached manifest is not present and contents are None; delays reading of manifest until required if cache file # Do we have a cached copy? # we have no cached copy; save one # don't specify excludes so on-disk copy has # we have a cached copy of the manifest # have we computed the dircache? """Load all manifest contents from on-disk copy of manifest""" """Finish loading.... this part of initialization is common to multiple code paths""" # this needs to change; we should not modify on-disk manifest """ store the current action set; also create per-type # this allows us to try to cache new manifests # when non-root w/o failures """ create manifest.<typename> files to accelerate partial parsing of manifests. Separate from __storeback code to allow upgrade to reuse existing on disk manifests""" # create per-action type cache; use rename to avoid # corrupt files if ^C'd in the middle # XXX consider use of per-process tmp file names """ from a dictionary of paths, generate contents of dircache yield "dir path=%s %s\n" % \
(d,
" ".
join(
"%s=%s" % t \
""" create dictionary of all directories referenced by actions explicitly or implicitly from self.actions... include variants as values; collapse variants where possible""" # build a dictionary containing all directories tagged w/ # remove any tags if any entries are always installed (NULL) # could collapse dirs where all variants are present """ return a list of directories implicitly or explicitly referenced by this object""" # generate actions that contain directories # we have cached copy on disk; use it """ generate actions of the specified type; use already in-memory stuff if already loaded, otherwise use per-action types files""" if self.
loaded:
#if already loaded, use in-memory cached version # invoke subclass method to generate action by action # invoke subclass method to generate action by action # we have a cached copy - use it return # no such action in this manifest """Load attributes dictionary from cached set actions; this speeds up pkg info a lot""" """No assignments to cached manifests allowed.""" assert "CachedManifests are not dicts"