manifest.py revision 1516
"""A Manifest is the representation of the actions composing a specific package version on both the client and the repository. Both purposes utilize the same storage format. The serialized structure of a manifest is an unordered list of actions. The special action, "set", represents a package attribute. The reserved attribute, "fmri", represents the package and version described by this manifest. It is available as a string via the attributes dictionary, and as an FMRI object from the fmri member. The list of manifest-wide reserved attributes is base_directory Default base directory, for non-user images. isa Package is intended for a list of ISAs. platform Package is intended for a list of platforms. relocatable Suitable for User Image. All non-prefixed attributes are reserved to the framework. Third parties may prefix their attributes with a reversed domain name, domain name, or stock symbol. An example might be as an indicator that a specific package version is supported by the manifest.null is provided as the null manifest. Differences against the null manifest result in the complete set of attributes and actions of the non-null manifest, meaning that all operations can be viewed as tranitions between the manifest being installed and the manifest already present in the image (which may be the null manifest). r +=
"set name=pkg.fmri value=%s\n" %
self.
fmri """A generator function that returns the unsorted manifest contents as lines of text.""" yield "set name=pkg.fmri value=%s\n" %
self.
fmri """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.""" # XXX Do we need to find some way to assert that the keys are # No origin was provided, so nothing has been changed or # removed; only added. In addition, this doesn't need # to be sorted since the caller likely already does # XXX for now, we force license actions to always be # different to insure that existing license files for # new versions are always installed # XXX Do changed actions need to be sorted at all? This is # likely to be the largest list, so we might save significant # time by not sorting. Should we sort above? Insert into a # singlesort = lambda x: x[0] or x[1] """Like the unix utility comm, except that this function takes an arbitrary number of manifests and compares them, returning a tuple consisting of each manifest's actions that are not the same for all manifests, followed by a list of actions that are the same in each manifest.""" # construct list of dictionaries of actions in each # manifest, indexed by unique keys # construct list of key sets in each dict # determine which common_keys have common actions """Where difference() returns three lists, combined_difference() returns a single list of the concatenation of the three.""" """Output expects that self is newer than other. Use of sets requires that we convert the action objects into some marshalled form, otherwise set member identities are derived from the object pointers, rather than the contents.""" """Generate actions in manifest through ordered callable list""" """Generate actions in the manifest of type "type" through ordered callable list""" """Generate the value of the key atrribute for each action of type "type" in the manifest.""" """Find actions in the manifest which are duplicates (i.e., represent the same object) but which are not identical (i.e., have all the same attributes).""" """Return a key on which actions can be sorted.""" if l.
endswith(
"\\"):
# allow continuation chars if not l
or l[
0] ==
"#":
# ignore blank lines & comments # Add the FMRI to the exception and re-raise """content is the text representation of the manifest""" # So we could build up here the type/key_attr dictionaries like # sdict and odict in difference() above, and have that be our # main datastore, rather than the simple list we have now. If # we do that here, we can even assert that the "same" action # can't be in a manifest twice. (The problem of having the same # action more than once in packages that can be installed # together has to be solved somewhere else, though.) # Generate manifest signature based upon input # content, but only if signatures were """Performs any needed transformations on the action then adds The "action" parameter is the action object that should be The "excludes" parameter is the variants to exclude from the # XXX handle legacy transition issues; not needed after # 2009.06 release & republication are complete. # 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") %
"""This method takes a string representing the on-disk manifest content, and returns a hash value.""" """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 the boolean of the value of the attribute 'key'.""" raise ValueError(_(
"Attribute value '%s' not 'true' or " """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""" """ 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