pkgplan.py revision 1003
#
# 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 errno
import itertools
import os
"""A package plan takes two package FMRIs and an Image, and produces the
set of actions required to take the Image from the origin FMRI to the
destination FMRI.
If the destination FMRI is None, the package is removed.
"""
self.origin_fmri = None
self.destination_fmri = None
self.__repair_actions = []
self.__legacy_info = {}
return s
self.origin_fmri = None
# Create a list of (src, dst) pairs for the actions to send to
# execute_repair. src is none in this case since we aren't
# upgrading, just repairing.
# Only install actions, no update or remove
raise RuntimeError, "already installed"
raise RuntimeError, "not installed"
def get_actions(self):
raise NotImplementedError()
def get_nactions(self):
""" updates a set of installed fmris to reflect
proposed new state"""
if self.origin_fmri:
if self.destination_fmri:
"""Determine the actions required to transition the package."""
# if origin unset, determine if we're dealing with an previously
# installed version or if we're dealing with the null package
#
# XXX Perhaps make the pkgplan creator make this explicit, so we
# don't have to check?
f = None
if not self.origin_fmri:
if f:
self.origin_fmri = f
self.__origin_mfst = \
# Assume that origin actions are unique, but make sure that
# destination ones are.
if ddups:
# figure out how many implicit directories disappear in this
# transition and add directory remove actions. These won't
# do anything unless no pkgs reference that directory in
# new state....
absent_dirs = \
for a in absent_dirs:
# Stash information needed by legacy actions.
# Add any repair actions to the update list
#
# We cross a point of no return here, and throw away the origin
# and destination manifests; we also delete them from the
# image cache.
self.__origin_mfst = None
self.__destination_mfst = None
if self.origin_fmri:
if self.destination_fmri:
def get_legacy_info(self):
""" Returns information needed by the legacy action to
populate the SVR4 packaging info. """
return self.__legacy_info
def get_xferstats(self):
if nf > 0:
return True
else:
return False
def get_xfername(self):
if self.destination_fmri:
if self.origin_fmri:
return None
def preexecute(self):
"""Perform actions required prior to installation or removal of
a package.
This method executes each action's preremove() or preinstall()
methods, as well as any package-wide steps that need to be taken
at such a time.
"""
if dest:
else:
"""Download data for any actions that need it."""
if dest:
def gen_install_actions(self):
def gen_removal_actions(self):
def gen_update_actions(self):
""" perform action for installation of package"""
try:
except Exception, e:
msg("Action install failed for '%s' (%s):\n %s: %s" % \
raise
""" handle action updates"""
try:
except Exception, e:
msg("Action upgrade failed for '%s' (%s):\n %s: %s" % \
raise
""" handle action removals"""
try:
except Exception, e:
msg("Action removal failed for '%s' (%s):\n %s: %s" % \
raise
def postexecute(self):
"""Perform actions required after install or remove of a pkg.
This method executes each action's postremove() or postinstall()
methods, as well as any package-wide steps that need to be taken
at such a time.
"""
# record that package states are consistent
if dest:
else:
# For an uninstall or an upgrade, remove the installation
# turds from the origin's directory.
# XXX should this just go in preexecute?
try:
except EnvironmentError, e:
raise
if self.destination_fmri != None:
# Save the filters we used to install the package, so
# they can be referenced later.
f.writelines([
myfilter + "\n"
])
f.close()