manifest.py revision 2054
81a6387a4ab56a24194ecbabd6609c6bcca568b7Tim Reddehase# CDDL HEADER START
81a6387a4ab56a24194ecbabd6609c6bcca568b7Tim Reddehase# The contents of this file are subject to the terms of the
a847d9812b328c048773e705606b10875a929034Eugen Kuksa# Common Development and Distribution License (the "License").
81a6387a4ab56a24194ecbabd6609c6bcca568b7Tim Reddehase# You may not use this file except in compliance with the License.
a847d9812b328c048773e705606b10875a929034Eugen Kuksa# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a847d9812b328c048773e705606b10875a929034Eugen Kuksa# See the License for the specific language governing permissions
a847d9812b328c048773e705606b10875a929034Eugen Kuksa# and limitations under the License.
a847d9812b328c048773e705606b10875a929034Eugen Kuksa# When distributing Covered Code, include this CDDL HEADER in each
c4f318dca9446ec8beb46dc5695d4435f1c12d5bTim Reddehase# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c4f318dca9446ec8beb46dc5695d4435f1c12d5bTim Reddehase# If applicable, add the following below this CDDL HEADER, with the
c4f318dca9446ec8beb46dc5695d4435f1c12d5bTim Reddehase# fields enclosed by brackets "[]" replaced with your own identifying
c4f318dca9446ec8beb46dc5695d4435f1c12d5bTim Reddehase# information: Portions Copyright [yyyy] [name of copyright owner]
a847d9812b328c048773e705606b10875a929034Eugen Kuksa# CDDL HEADER END
a847d9812b328c048773e705606b10875a929034Eugen Kuksa# Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
a847d9812b328c048773e705606b10875a929034Eugen Kuksafrom pkg.misc import EmptyDict, EmptyI, expanddirs, PKG_FILE_MODE, PKG_DIR_MODE
a847d9812b328c048773e705606b10875a929034Eugen Kuksafrom pkg.actions.attribute import AttributeAction
a847d9812b328c048773e705606b10875a929034Eugen KuksaManifestDifference = namedtuple("ManifestDifference", "added changed removed")
a847d9812b328c048773e705606b10875a929034Eugen Kuksa """A Manifest is the representation of the actions composing a specific
a847d9812b328c048773e705606b10875a929034Eugen Kuksa package version on both the client and the repository. Both purposes
a847d9812b328c048773e705606b10875a929034Eugen Kuksa utilize the same storage format.
d51cee8257d50d1f2d7c0818d968b32096f6b795Tim Reddehase The serialized structure of a manifest is an unordered list of actions.
d51cee8257d50d1f2d7c0818d968b32096f6b795Tim Reddehase The special action, "set", represents a package attribute.
d51cee8257d50d1f2d7c0818d968b32096f6b795Tim Reddehase The reserved attribute, "fmri", represents the package and version
d51cee8257d50d1f2d7c0818d968b32096f6b795Tim Reddehase described by this manifest. It is available as a string via the
0abeb43875687e94f2d551053ad09eebeff1f7c9Tim Reddehase attributes dictionary, and as an FMRI object from the fmri member.
03ec1d0391beb40e0ae66a73cf99554e1ca6fa15Tim Reddehase The list of manifest-wide reserved attributes is
c4cb6bccad9d72c8b284075f716fc9095b3f3be2Tim Reddehase base_directory Default base directory, for non-user images.
c4cb6bccad9d72c8b284075f716fc9095b3f3be2Tim Reddehase fmri Package FMRI.
d51cee8257d50d1f2d7c0818d968b32096f6b795Tim Reddehase isa Package is intended for a list of ISAs.
0abeb43875687e94f2d551053ad09eebeff1f7c9Tim Reddehase platform Package is intended for a list of platforms.
0abeb43875687e94f2d551053ad09eebeff1f7c9Tim Reddehase relocatable Suitable for User Image.
d51cee8257d50d1f2d7c0818d968b32096f6b795Tim Reddehase All non-prefixed attributes are reserved to the framework. Third
d51cee8257d50d1f2d7c0818d968b32096f6b795Tim Reddehase parties may prefix their attributes with a reversed domain name, domain
d51cee8257d50d1f2d7c0818d968b32096f6b795Tim Reddehase name, or stock symbol. An example might be
c4f318dca9446ec8beb46dc5695d4435f1c12d5bTim Reddehase com.example,supported
0abeb43875687e94f2d551053ad09eebeff1f7c9Tim Reddehase as an indicator that a specific package version is supported by the
0abeb43875687e94f2d551053ad09eebeff1f7c9Tim Reddehase vendor, example.com.
0abeb43875687e94f2d551053ad09eebeff1f7c9Tim Reddehase manifest.null is provided as the null manifest. Differences against the
a847d9812b328c048773e705606b10875a929034Eugen Kuksa null manifest result in the complete set of attributes and actions of
81a6387a4ab56a24194ecbabd6609c6bcca568b7Tim Reddehase the non-null manifest, meaning that all operations can be viewed as
81a6387a4ab56a24194ecbabd6609c6bcca568b7Tim Reddehase tranitions between the manifest being installed and the manifest already
81a6387a4ab56a24194ecbabd6609c6bcca568b7Tim Reddehase present in the image (which may be the null manifest).
4949048bda09e116ee3627383e831455954cbe41Tim Reddehase self.attributes = {} # package-wide attributes
4949048bda09e116ee3627383e831455954cbe41Tim Reddehase if "pkg.fmri" not in self.attributes and self.fmri != None:
4949048bda09e116ee3627383e831455954cbe41Tim Reddehase r += "set name=pkg.fmri value=%s\n" % self.fmri
03ec1d0391beb40e0ae66a73cf99554e1ca6fa15Tim Reddehase """A generator function that returns the unsorted manifest
a847d9812b328c048773e705606b10875a929034Eugen Kuksa contents as lines of text."""
a847d9812b328c048773e705606b10875a929034Eugen Kuksa if "pkg.fmri" not in self.attributes and self.fmri != None:
a847d9812b328c048773e705606b10875a929034Eugen Kuksa yield "set name=pkg.fmri value=%s\n" % self.fmri
419f986abb76f6fce54b71e17f52a1deaa06dbd6Tim Reddehase def difference(self, origin, origin_exclude=EmptyI,
419f986abb76f6fce54b71e17f52a1deaa06dbd6Tim Reddehase """Return three lists of action pairs representing origin and
03ec1d0391beb40e0ae66a73cf99554e1ca6fa15Tim Reddehase destination actions. The first list contains the pairs
03ec1d0391beb40e0ae66a73cf99554e1ca6fa15Tim Reddehase representing additions, the second list contains the pairs
419f986abb76f6fce54b71e17f52a1deaa06dbd6Tim Reddehase representing updates, and the third list contains the pairs
419f986abb76f6fce54b71e17f52a1deaa06dbd6Tim Reddehase representing removals. All three lists are in the order in
419f986abb76f6fce54b71e17f52a1deaa06dbd6Tim Reddehase which they should be executed."""
419f986abb76f6fce54b71e17f52a1deaa06dbd6Tim Reddehase # XXX Do we need to find some way to assert that the keys are
d9a3935fa80ce492e782d17ec22825d1708dea97Tim Reddehase # all unique?
d9a3935fa80ce492e782d17ec22825d1708dea97Tim Reddehase # No origin was provided, so nothing has been changed or
d9a3935fa80ce492e782d17ec22825d1708dea97Tim Reddehase # removed; only added. In addition, this doesn't need
d9a3935fa80ce492e782d17ec22825d1708dea97Tim Reddehase # to be sorted since the caller likely already does
80021fb6bde14c39046950cdbaaadf767d173f94Tim Reddehase [(None, a) for a in self.gen_actions(self_exclude)],
d9a3935fa80ce492e782d17ec22825d1708dea97Tim Reddehase added = [(None, sdict[i]) for i in sset - oset]
d9a3935fa80ce492e782d17ec22825d1708dea97Tim Reddehase removed = [(odict[i], None) for i in oset - sset]
d9a3935fa80ce492e782d17ec22825d1708dea97Tim Reddehase # XXX for now, we force license actions to always be
d9a3935fa80ce492e782d17ec22825d1708dea97Tim Reddehase # different to insure that existing license files for
changed = [
m_dicts = [
dict(
for a in m.actions)
for m in compare_m
m_sets = [
for m in m_dicts
return tuple(
if not src:
elif not dest:
return out
for c in excludes:
for c in excludes:
def fun(a):
alldups = []
if dups:
return alldups
errors = []
l = l.lstrip()
elif accumulate:
l = accumulate + l
if errors:
if signatures:
log=None):
if log is None:
log = lambda x: None
action_dict = {}
if full_value is None:
if full_value is None:
if full_value is None:
for t in tok
], cp)
while line:
except KeyError, k:
if return_line:
arg = l
return action_dict
except EnvironmentError, e:
e.filename)
e.filename)
except EnvironmentError, e:
e.filename)
e.filename)
except EnvironmentError, e:
e.filename)
e.filename)
return variants
return [variants]
except KeyError:
return default
return True
return False
return size
if not contents:
elif excludes:
elif excludes:
f.close()
return True
return False
f.close()
f.write(s)
f.close()
for d in dirs:
for v in dirs[d]:
for t in v.iteritems()))
dirs = {}
v, f = a.get_varcet_keys()
if d not in dirs:
for d in dirs:
if {} in dirs[d]:
dirs[d] = [{}]
return dirs
except EnvironmentError, e:
except EnvironmentError, e:
alist = [
f.close()
s = set([
for a in alist
return list(s)
excludes):
excludes):
f.close()
return False
f.close()
return True
except KeyError:
return default
return ManifestDifference([], [],