manifest.py revision 202
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# CDDL HEADER START
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# The contents of this file are subject to the terms of the
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# Common Development and Distribution License (the "License").
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# You may not use this file except in compliance with the License.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# See the License for the specific language governing permissions
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# and limitations under the License.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# When distributing Covered Code, include this CDDL HEADER in each
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# If applicable, add the following below this CDDL HEADER, with the
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# fields enclosed by brackets "[]" replaced with your own identifying
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# information: Portions Copyright [yyyy] [name of copyright owner]
ae46f6ba5bb9eee8900254d3042e89d490023be0Timo Sirainen# CDDL HEADER END
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
3f3ad16ff74d694796d22501250a9a29997c0729Timo Sirainen# Use is subject to license terms.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# The type member is used for the ordering of actions.
5801ce4da7d807ab85d02051ece5969e7175eebaTimo Sirainen """A Manifest is the representation of the actions composing a specific
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen package version on both the client and the repository. Both purposes
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen utilize the same storage format.
db693bf6fcae96d834567f1782257517b7207655Timo Sirainen The serialized structure of a manifest is an unordered list of package
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen attributes, followed by an unordered list of actions (such as files to
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen The special action, "set", represents an attribute setting.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen The reserved attribute, "fmri", represents the package and version
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen described by this manifest. It is available as a string via the
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen attributes dictionary, and as an FMRI object from the fmri member.
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen The list of manifest-wide reserved attributes is
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen base_directory Default base directory, for non-user images.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen fmri Package FMRI.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen isa Package is intended for a list of ISAs.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen licenses Package contains software available under a list
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen of license terms.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen platform Package is intended for a list of platforms.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen relocatable Suitable for User Image.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen All non-prefixed attributes are reserved to the framework. Third
db693bf6fcae96d834567f1782257517b7207655Timo Sirainen parties may prefix their attributes with a reversed domain name, domain
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen name, or stock symbol. An example might be
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen com.example,supported
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen as an indicator that a specific package version is supported by the
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen vendor, example.com.
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen manifest.null is provided as the null manifest. Differences against the
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen null manifest result in the complete set of attributes and actions of
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen the non-null manifest, meaning that all operations can be viewed as
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen tranitions between the manifest being installed and the manifest already
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen present in the image (which may be the null manifest).
fa87f0ef3636fa52ce42513533ee500c0bf29910Timo Sirainen r = r + "set %s = %s\n" % (att, self.attributes[att])
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen """Return a list of action pairs representing origin and
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen destination actions."""
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen # XXX Do we need to find some way to assert that the keys are
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen # all unique?
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen added = [(None, sdict[i]) for i in sset - oset]
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen removed = [(odict[i], None) for i in oset - sset]
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen # XXX Do changed actions need to be sorted at all? This is
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen # likely to be the largest list, so we might save significant
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen # time by not sorting. Should we sort above? Insert into a
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen # sorted list?
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen # singlesort = lambda x: x[0] or x[1]
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen """Output expects that self is newer than other. Use of sets
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainen requires that we convert the action objects into some marshalled
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainen form, otherwise set member identities are derived from the
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainen object pointers, rather than the contents."""
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen """Filter out actions from the manifest based on filters."""
412b772c337428b72149605c1410524c2353e5d4Timo Sirainen """Find actions in the manifest which are duplicates (i.e.,
0a53eb0283d7ec28c6105f61e118b96fce8ecb95Timo Sirainen represent the same object) but which are not identical (i.e.,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen have all the same attributes)."""
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen """Return a key on which actions can be sorted."""
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen for k, g in groupby(sorted(self.actions, key = fun), fun):
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return retrieve.get_datastream(img, fmri, action.hash)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen """str is the text representation of the manifest"""
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen # So we could build up here the type/key_attr dictionaries like
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen # sdict and odict in difference() above, and have that be our
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen # main datastore, rather than the simple list we have now. If
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen # we do that here, we can even assert that the "same" action
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen # can't be in a manifest twice. (The problem of having the same
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen # action more than once in packages that can be installed
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen # together has to be solved somewhere else, though.)
action_dict = {}
if k in action_dict:
action_dict[k] = \
if k in action_dict:
return action_dict