manifest.py revision 567
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
import os
import errno
# The type member is used for the ordering of actions.
ACTION_DIR = 10
ACTION_FILE = 20
ACTION_LINK = 50
ACTION_HARDLINK = 55
ACTION_DEVICE = 100
ACTION_USER = 200
ACTION_GROUP = 210
ACTION_SERVICE = 300
ACTION_RESTART = 310
ACTION_DEPEND = 400
DEPEND_REQUIRE = 0
DEPEND_OPTIONAL = 1
DEPEND_INCORPORATE = 10
DEPEND_OPTIONAL : "optional",
DEPEND_INCORPORATE : "incorporate"
}
"""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.
fmri Package FMRI.
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
com.example,supported
as an indicator that a specific package version is supported by the
vendor, example.com.
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).
"""
self.actions_bytype = {}
r = ""
r += "%s\n" % act
return r
def tostr_unsorted(self):
r = ""
r += "%s\n" % act
return r
"""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
represnting 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
# all unique?
)
)
# XXX for now, we force license actions to always be
# different to insure that existing license files for
# new versions are always installed
changed = [
]
# 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
# sorted list?
# singlesort = lambda x: x[0] or x[1]
addsort = lambda x: x[1]
remsort = lambda x: x[0]
"""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."""
out = ""
if not src:
elif not dest:
else:
return out
"""Generate actions in the manifest of type "type"."""
"""Filter out actions from the manifest based on filters."""
a
]
def duplicates(self):
"""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)."""
def fun(a):
"""Return a key on which actions can be sorted."""
alldups = []
if dups:
return alldups
"""str is the text representation of the manifest"""
# 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.)
for l in str.splitlines():
l = l.lstrip()
if not l or l[0] == "#":
continue
try:
except (KeyError, ValueError), e:
else:
return
def search_dict(self):
"""Return the dictionary used for searching."""
action_dict = {}
for k, v in a.generate_indices().iteritems():
# v is the token to be searched on. If the
# token is empty, it cannot be retrieved and
# it should not be placed in the dictionary.
if v == "":
continue
# Special handling of AttributeActions is
# needed inorder to place the correct values
# into the correct output columns. This is
# the pattern of which information changes
# on an item by item basis is differs for
# AttributeActions.
#
# The right solution is probably to reorganize
# this function and all the generate_indicies
# functions to allow the necessary flexibility.
if isinstance(a,
t = (a.name, k)
else:
tok_type = k
# The value might be a list if an indexed
# action attribute is multivalued, such as
# driver aliases.
if isinstance(v, list):
if tok_type in action_dict:
dict((i, [t]) for i in v))
else:
action_dict[tok_type] = \
dict((i, [t]) for i in v)
else:
if tok_type not in action_dict:
action_dict[tok_type] = \
{ v: [t] }
elif v not in action_dict[tok_type]:
action_dict[tok_type][v] = [t]
else:
assert action_dict[tok_type][v]
return action_dict
"""Store the manifest contents to disk."""
try:
except IOError:
try:
except OSError, e:
raise
#
# 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.
#
try:
except KeyError:
return default
"""Return the value for the package attribute 'key'. If
multiple attributes exist, return the first. Raises KeyError if
the attribute is not found."""
try:
values = [
a.attrs["value"]
]
except KeyError:
# This hides the fact that we had busted attribute
# actions in the manifest, but that's probably not so
# bad.
if values:
return values[0]
"""Set the value for the package attribute 'key' to 'value'."""
return
return True
return False