manifest.py revision 1407
50N/A# The contents of this file are subject to the terms of the 50N/A# Common Development and Distribution License (the "License"). 50N/A# You may not use this file except in compliance with the License. 50N/A# See the License for the specific language governing permissions 50N/A# and limitations under the License. 50N/A# When distributing Covered Code, include this CDDL HEADER in each 50N/A# If applicable, add the following below this CDDL HEADER, with the 50N/A# fields enclosed by brackets "[]" replaced with your own identifying 50N/A# information: Portions Copyright [yyyy] [name of copyright owner] 50N/A# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 50N/A# Use is subject to license terms. 50N/A """A Manifest is the representation of the actions composing a specific 72N/A package version on both the client and the repository. Both purposes 72N/A utilize the same storage format. 50N/A The serialized structure of a manifest is an unordered list of actions. 50N/A The special action, "set", represents a package attribute. 50N/A The reserved attribute, "fmri", represents the package and version 235N/A described by this manifest. It is available as a string via the 235N/A attributes dictionary, and as an FMRI object from the fmri member. 242N/A The list of manifest-wide reserved attributes is 242N/A base_directory Default base directory, for non-user images. 72N/A isa Package is intended for a list of ISAs. 72N/A platform Package is intended for a list of platforms. 202N/A relocatable Suitable for User Image. 72N/A All non-prefixed attributes are reserved to the framework. Third 72N/A parties may prefix their attributes with a reversed domain name, domain 63N/A name, or stock symbol. An example might be 50N/A com.example,supported 50N/A as an indicator that a specific package version is supported by the 242N/A manifest.null is provided as the null manifest. Differences against the 50N/A null manifest result in the complete set of attributes and actions of 195N/A the non-null manifest, meaning that all operations can be viewed as 59N/A tranitions between the manifest being installed and the manifest already 59N/A present in the image (which may be the null manifest). 72N/A """A generator function that returns the unsorted manifest 258N/A contents as lines of text.""" 111N/A """Return three lists of action pairs representing origin and 111N/A destination actions. The first list contains the pairs 111N/A representing additions, the second list contains the pairs 135N/A representing updates, and the third list contains the pairs 111N/A representing removals. All three lists are in the order in 111N/A which they should be executed.""" 111N/A # XXX Do we need to find some way to assert that the keys are 111N/A # No origin was provided, so nothing has been changed or 111N/A # removed; only added. In addition, this doesn't need 111N/A # to be sorted since the caller likely already does 237N/A # XXX for now, we force license actions to always be 237N/A # different to insure that existing license files for 237N/A # new versions are always installed 235N/A # XXX Do changed actions need to be sorted at all? This is 235N/A # likely to be the largest list, so we might save significant 235N/A # time by not sorting. Should we sort above? Insert into a 235N/A # singlesort = lambda x: x[0] or x[1] 235N/A """Like the unix utility comm, except that this function 235N/A takes an arbitrary number of manifests and compares them, 235N/A returning a tuple consisting of each manifest's actions 235N/A that are not the same for all manifests, followed by a 235N/A list of actions that are the same in each manifest.""" 235N/A # construct list of dictionaries of actions in each 237N/A # manifest, indexed by unique keys 66N/A # construct list of key sets in each dict 195N/A # determine which common_keys have common actions 119N/A """Where difference() returns three lists, combined_difference() 235N/A returns a single list of the concatenation of the three.""" 119N/A """Output expects that self is newer than other. Use of sets 119N/A requires that we convert the action objects into some marshalled 119N/A form, otherwise set member identities are derived from the 119N/A object pointers, rather than the contents.""" 119N/A """Generate actions in manifest through ordered callable list""" 237N/A """Generate actions in the manifest of type "type" 237N/A through ordered callable list""" 237N/A """Generate the value of the key atrribute for each action 237N/A of type "type" in the manifest.""" 202N/A """Find actions in the manifest which are duplicates (i.e., 237N/A represent the same object) but which are not identical (i.e., 237N/A have all the same attributes).""" 237N/A """Return a key on which actions can be sorted.""" 66N/A """content is the text representation of the manifest""" 136N/A # sdict and odict in difference() above, and have that be our 66N/A # main datastore, rather than the simple list we have now. If 111N/A # we do that here, we can even assert that the "same" action 111N/A # can't be in a manifest twice. (The problem of having the same 66N/A # action more than once in packages that can be installed 66N/A # together has to be solved somewhere else, though.) 135N/A if not l
or l[
0] ==
"#":
135N/A # Add the FMRI to the exception and re-raise 195N/A # XXX handle legacy transition issues; not needed after 60N/A # 2009.06 release & republication are complete. 111N/A # Translate old action to new. # add any set actions to attributes # append any variants and facets to manifest dict """Fill attribute array w/ set action contents.""" except KeyError:
# ignore broken set actions """Produces the search dictionary for a specific manifest. A dictionary is constructed which maps a tuple of token, action type, key, and the value that matched the token to the byte offset into the manifest file. file_path is the path to the manifest file. excludes is the variants which should be allowed in this image. return_line is a debugging flag which makes the function map the information to the string of the line, rather than the byte offset to allow """Translates what actions.generate_indices produces into a dictionary mapping token, action_name, key, and the value that should be displayed for matching that token to byte offsets into the manifest file. The "lst" parameter is the data to be converted. The "cp" parameter is the byte offset into the file for the action which produced lst.""" log((_(
"%(fp)s:\n%(e)s") %
"""A dict structure of signature key and value pairs for the the contents of the Manifest. The keys are the names of each signature and the values are the signature.""" # NOTE: The logic here must be identical to that of store() so # that the signature properly reflects the on-disk data. """Verifies whether the signatures for the contents of the manifest match the specified signature data. Raises the 'BadManifestSignatures' exception on failure.""" """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 a dictionary mapping variant tags to their values.""" """Returns an integer representing the total size, in bytes, of the Manifest's data payload. 'excludes' is a list of variants which should be allowed when """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 """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""" """Unload manifest; used to reduce peak memory comsumption when downloading new manifests""" """Finish loading.... this part of initialization is common to multiple code paths""" # this needs to change; we should not modify on-disk manifest # This shouldn't be set unless available. """ store the current action set; also create per-type caches. Return True if data was saved, False if not""" # 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 """ 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" """Special class for pkgplan's need for a empty manifest; the regular null manifest doesn't support get_directories and making the cached manifest code handle this case is """Return three lists of action pairs representing origin and destination actions. The first list contains the pairs representing additions, the second list contains the pairs representing updates, and the third list contains the pairs representing removals. All three lists are in the order in which they should be executed.""" # The difference for this case is simply everything in the # origin has been removed. This is an optimization for