manifest.py revision 144
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# CDDL HEADER START
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# The contents of this file are subject to the terms of the
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# Common Development and Distribution License (the "License").
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# You may not use this file except in compliance with the License.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# See the License for the specific language governing permissions
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# and limitations under the License.
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# When distributing Covered Code, include this CDDL HEADER in each
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# If applicable, add the following below this CDDL HEADER, with the
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# fields enclosed by brackets "[]" replaced with your own identifying
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# information: Portions Copyright [yyyy] [name of copyright owner]
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# CDDL HEADER END
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# Use is subject to license terms.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# The type member is used for the ordering of actions.
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen """A Manifest is the representation of the actions composing a specific
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen package version on both the client and the repository. Both purposes
659fe5d24825b160cae512538088020d97a60239Timo Sirainen utilize the same storage format.
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen The serialized structure of a manifest is an unordered list of package
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen attributes, followed by an unordered list of actions (such as files to
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen The special action, "set", represents an attribute setting.
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen The reserved attribute, "fmri", represents the package and version
445f9e31c6c3aa6c0a72be8565da8f6e594d24fbTimo Sirainen described by this manifest. It is available as a string via the
445f9e31c6c3aa6c0a72be8565da8f6e594d24fbTimo Sirainen attributes dictionary, and as an FMRI object from the fmri member.
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen The list of manifest-wide reserved attributes is
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen base_directory Default base directory, for non-user images.
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen fmri Package FMRI.
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen isa Package is intended for a list of ISAs.
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen licenses Package contains software available under a list
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen of license terms.
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen platform Package is intended for a list of platforms.
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen relocatable Suitable for User Image.
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen All non-prefixed attributes are reserved to the framework. Third
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen parties may prefix their attributes with a reversed domain name, domain
9e59a1f3f095b3099478562cf3f3970a24736970Timo Sirainen name, or stock symbol. An example might be
178511b57faa7c3f8203dd8b7e4059d00cbfc23aTimo Sirainen com.example,supported
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen as an indicator that a specific package version is supported by the
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen vendor, example.com.
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen manifest.null is provided as the null manifest. Differences against the
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen null manifest result in the complete set of attributes and actions of
33d63688ed8b26dc333e3c2edbfb2fe6e412604dTimo Sirainen the non-null manifest, meaning that all operations can be viewed as
33d63688ed8b26dc333e3c2edbfb2fe6e412604dTimo Sirainen tranitions between the manifest being installed and the manifest already
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen present in the image (which may be the null manifest).
b9ac6179d3aee0d1641a4ee1d78da28628929c61Timo Sirainen r = r + "set %s = %s\n" % (att, self.attributes[att])
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen """Return a list of action pairs representing origin and
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen destination actions."""
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen # XXX Do we need to find some way to assert that the keys are
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen # all unique?
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen added = [(None, sdict[i]) for i in sset - oset]
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen removed = [(odict[i], None) for i in oset - sset]
7a6b45405fb1544ac476e6eb1402a70cc1ddcdcfTimo Sirainen # XXX Do changed actions need to be sorted at all? This is
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # likely to be the largest list, so we might save significant
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # time by not sorting. Should we sort above? Insert into a
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen # sorted list?
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen # singlesort = lambda x: x[0] or x[1]
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen """Output expects that self is newer than other. Use of sets
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen requires that we convert the action objects into some marshalled
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen form, otherwise set member identities are derived from the
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen object pointers, rather than the contents."""
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen """Filter out actions from the manifest based on filters."""
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen """Find actions in the manifest which are duplicates (i.e.,
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen represent the same object) but which are not identical (i.e.,
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen have all the same attributes)."""
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen """Return a key on which actions can be sorted."""
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen for k, g in groupby(sorted(self.actions, key = fun), fun):
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen return retrieve.get_datastream(img, fmri, action.hash)
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen """str is the text representation of the manifest"""
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen # So we could build up here the type/key_attr dictionaries like
a393d9d6dabdc46cf724f8cb004a652b4036d53dTimo Sirainen # sdict and odict in difference() above, and have that be our
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen # main datastore, rather than the simple list we have now. If
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # we do that here, we can even assert that the "same" action
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # can't be in a manifest twice. (The problem of having the same
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # action more than once in packages that can be installed
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # together has to be solved somewhere else, though.)
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen """Return the dictionary used for searching."""
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen """Pickle the indices of the manifest's actions to the 'file'.
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainenset com.sun,test=true
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainendepend type=require fmri=pkg:/library/libc
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainenfile fff555fff mode=0555 owner=sch group=staff path=/usr/bin/i386/sort isa=i386
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainenset com.sun,test=false
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenset com.sun,data=true
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainendepend type=require fmri=pkg:/library/libc
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenfile fff555ff9 mode=0555 owner=sch group=staff path=/usr/bin/i386/sort isa=i386
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenfile eeeaaaeee mode=0555 owner=sch group=staff path=/usr/bin/amd64/sort isa=amd64
4d25408732be27e91f0430f71e87242760c2517cTimo Sirainenfile ff555fff mode=0555 owner=root group=bin path=/kernel/drv/foo isa=i386
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenfile ff555ffe mode=0555 owner=root group=bin path=/kernel/drv/amd64/foo isa=amd64
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenfile ff555ffd mode=0644 owner=root group=bin path=/kernel/drv/foo.conf
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainendir mode=0755 owner=root group=sys path=/bin
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenfile 00000000 mode=0644 owner=root group=sys path=/bin/change
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenfile 00000001 mode=0644 owner=root group=sys path=/bin/nochange
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenfile 00000002 mode=0644 owner=root group=sys path=/bin/toberemoved
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenlink path=/bin/change-link target=change
33d63688ed8b26dc333e3c2edbfb2fe6e412604dTimo Sirainenlink path=/bin/nochange-link target=nochange
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenlink path=/bin/change-target target=target1
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenlink path=/bin/change-type target=random
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainendir mode=0755 owner=root group=sys path=/bin
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenfile 0000000f mode=0644 owner=root group=sys path=/bin/change
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainenfile 00000001 mode=0644 owner=root group=sys path=/bin/nochange
7a6b45405fb1544ac476e6eb1402a70cc1ddcdcfTimo Sirainenfile 00000003 mode=0644 owner=root group=sys path=/bin/wasadded
7a6b45405fb1544ac476e6eb1402a70cc1ddcdcfTimo Sirainenlink path=/bin/change-link target=change
b9ac6179d3aee0d1641a4ee1d78da28628929c61Timo Sirainenlink path=/bin/nochange-link target=nochange
b9ac6179d3aee0d1641a4ee1d78da28628929c61Timo Sirainenlink path=/bin/change-target target=target2
b9ac6179d3aee0d1641a4ee1d78da28628929c61Timo Sirainendir mode=0755 owner=root group=sys path=/bin/change-type
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen # Test the duplicate search. /bin shouldn't show up, since they're
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen # identical actions, but /usr should show up three times.
33d63688ed8b26dc333e3c2edbfb2fe6e412604dTimo Sirainendir mode=0755 owner=root group=sys path=/bin
33d63688ed8b26dc333e3c2edbfb2fe6e412604dTimo Sirainendir mode=0755 owner=root group=sys path=/bin
33d63688ed8b26dc333e3c2edbfb2fe6e412604dTimo Sirainendir mode=0755 owner=root group=sys path=/usr
33d63688ed8b26dc333e3c2edbfb2fe6e412604dTimo Sirainendir mode=0755 owner=root group=root path=/usr
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainendir mode=0755 owner=bin group=sys path=/usr
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen print " %s" % a