manifest.py revision 296
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# CDDL HEADER START
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# The contents of this file are subject to the terms of the
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# Common Development and Distribution License (the "License").
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# You may not use this file except in compliance with the License.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# See the License for the specific language governing permissions
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# and limitations under the License.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# When distributing Covered Code, include this CDDL HEADER in each
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# If applicable, add the following below this CDDL HEADER, with the
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# fields enclosed by brackets "[]" replaced with your own identifying
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# information: Portions Copyright [yyyy] [name of copyright owner]
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# CDDL HEADER END
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# Use is subject to license terms.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainenfrom pkg.actions.attribute import AttributeAction
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen# The type member is used for the ordering of actions.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen """A Manifest is the representation of the actions composing a specific
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen package version on both the client and the repository. Both purposes
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen utilize the same storage format.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen The serialized structure of a manifest is an unordered list of actions.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen The special action, "set", represents a package attribute.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen The reserved attribute, "fmri", represents the package and version
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen described by this manifest. It is available as a string via the
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen attributes dictionary, and as an FMRI object from the fmri member.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen The list of manifest-wide reserved attributes is
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen base_directory Default base directory, for non-user images.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen fmri Package FMRI.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen isa Package is intended for a list of ISAs.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen platform Package is intended for a list of platforms.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen relocatable Suitable for User Image.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen All non-prefixed attributes are reserved to the framework. Third
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen parties may prefix their attributes with a reversed domain name, domain
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen name, or stock symbol. An example might be
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen com.example,supported
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen as an indicator that a specific package version is supported by the
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen vendor, example.com.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen manifest.null is provided as the null manifest. Differences against the
b0be0bead3d6963149f7f2a9504b8ab5aced9af5Timo Sirainen null manifest result in the complete set of attributes and actions of
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen the non-null manifest, meaning that all operations can be viewed as
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen tranitions between the manifest being installed and the manifest already
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen present in the image (which may be the null manifest).
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen r = r + "set name=fmri value=%s\n" % self.fmri
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen """Return three lists of action pairs representing origin and
b0be0bead3d6963149f7f2a9504b8ab5aced9af5Timo Sirainen destination actions. The first list contains the pairs
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen representing additions, the second list contains the pairs
b0be0bead3d6963149f7f2a9504b8ab5aced9af5Timo Sirainen representing updates, and the third list contains the pairs
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen represnting removals. All three lists are in the order in which
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen they should be executed."""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # XXX Do we need to find some way to assert that the keys are
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # all unique?
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen added = [(None, sdict[i]) for i in sset - oset]
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen removed = [(odict[i], None) for i in oset - sset]
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # XXX for now, we force license actions to always be
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # different to insure that existing license files for
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen # new versions are always installed
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen if odict[i].different(sdict[i]) or i[0] == "license"
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # XXX Do changed actions need to be sorted at all? This is
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # likely to be the largest list, so we might save significant
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # time by not sorting. Should we sort above? Insert into a
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # sorted list?
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # singlesort = lambda x: x[0] or x[1]
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen """Where difference() returns three lists, combined_difference()
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen returns a single list of the concatenation of th three."""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen """Output expects that self is newer than other. Use of sets
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen requires that we convert the action objects into some marshalled
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen form, otherwise set member identities are derived from the
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen object pointers, rather than the contents."""
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen """Filter out actions from the manifest based on filters."""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen """Find actions in the manifest which are duplicates (i.e.,
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen represent the same object) but which are not identical (i.e.,
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen have all the same attributes)."""
2498b8003eb181001b0c4fd45763c462b45493d1Timo Sirainen """Return a key on which actions can be sorted."""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen for k, g in groupby(sorted(self.actions, key = fun), fun):
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen return retrieve.get_datastream(img, fmri, action.hash)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen """str is the text representation of the manifest"""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # So we could build up here the type/key_attr dictionaries like
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # sdict and odict in difference() above, and have that be our
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # main datastore, rather than the simple list we have now. If
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # we do that here, we can even assert that the "same" action
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # can't be in a manifest twice. (The problem of having the same
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # action more than once in packages that can be installed
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # together has to be solved somewhere else, though.)
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen """Return the dictionary used for searching."""
b0be0bead3d6963149f7f2a9504b8ab5aced9af5Timo Sirainen """Pickle the indices of the manifest's actions to the 'file'.
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen """Return the value for the package attribute 'key'. If
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen multiple attributes exist, return the first. Raises KeyError if
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen the attribute is not found."""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # This hides the fact that we had busted attribute
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # actions in the manifest, but that's probably not so
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen """Set the value for the package attribute 'key' to 'value'."""
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen if a.name == "set" and a.attrs["name"] == key:
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen new_attr = AttributeAction(None, name=key, value=value)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen if a.name == "set" and a.attrs["name"] == key: