pkgplan.py revision 94
#
# 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 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
import errno
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
return s
fmri.get_dir_path())):
raise RuntimeError, "already installed"
raise RuntimeError, "not installed"
if self.origin_fmri == None:
return True
return False
return False
return True
def get_actions(self):
return []
"""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:
try:
self.origin_fmri = f
except LookupError:
pass
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.
"""
# retrieval step
if self.destination_fmri == None:
if dest:
else:
"""Perform actions for installation or removal of a package.
This method executes each action's remove() or install()
methods.
"""
# record that we are in an intermediate state
# It might be nice to have a single action.execute() method, but
# I can't think of an example where it would make especially
# good sense (i.e., where "remove" is as similar to "upgrade" as
# is "install").
if dest:
try:
except Exception, e:
print "Action install failed for '%s' (%s):\n %s: %s" % \
raise
else:
def postexecute(self):
"""Perform actions required after installation or removal of a package.
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:
# XXX should this just go in preexecute?
if self.destination_fmri != None:
def make_indices(self):
"""Create the reverse index databases for a particular package.
These are the databases mapping packaging object attribute
values back to their corresponding packages, allowing the
packaging system to look up a package based on, say, the
basename of a file that was installed.
XXX Need a method to remove what we put down here.
"""
# XXX bail out, for now.
if self.destination_fmri == None:
return
gen = (
(k, v)
if dest
)
try:
except OSError, e:
raise
for v in val:
try:
except OSError, e:
raise
# If the value has slashes in it, link will be
# that many directories further down, so we need
# to add suffcient parent dirs to get back up to
# the right level.