__init__.py revision 1544
5c4c13ac875d79def115ce3d8443d4ec87b3252aJulian Kornberger# CDDL HEADER START
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase# The contents of this file are subject to the terms of the
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa# Common Development and Distribution License (the "License").
b66a6512eb6dea6cf5339eaa857a81d1b89cb4deJulian Kornberger# You may not use this file except in compliance with the License.
f4b865988759de2bcc51ffd55897191c74e53ba2Eugen Kuksa# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa# See the License for the specific language governing permissions
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa# and limitations under the License.
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa# When distributing Covered Code, include this CDDL HEADER in each
03dee28977299b4b40210d9b7842bf85c136ab7d=# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
03dee28977299b4b40210d9b7842bf85c136ab7d=# If applicable, add the following below this CDDL HEADER, with the
5c4c13ac875d79def115ce3d8443d4ec87b3252aJulian Kornberger# fields enclosed by brackets "[]" replaced with your own identifying
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa# information: Portions Copyright [yyyy] [name of copyright owner]
76f22aa7c18383199da116500929b79945677076Eugen Kuksa# CDDL HEADER END
5c4c13ac875d79def115ce3d8443d4ec87b3252aJulian Kornberger# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5c4c13ac875d79def115ce3d8443d4ec87b3252aJulian Kornberger# Use is subject to license terms.
5c4c13ac875d79def115ce3d8443d4ec87b3252aJulian Kornbergerpackage containing packaging action (file type) modules
532f6901b468d49af265ef939b52bbc6c8f1ab85Eugen KuksaThis package contains modules describing packaging actions, or file types. The
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksaactions are dynamically discovered, so that new modules can be placed in this
532f6901b468d49af265ef939b52bbc6c8f1ab85Eugen Kuksapackage directory and they'll just be picked up. The current package contents
532f6901b468d49af265ef939b52bbc6c8f1ab85Eugen Kuksacan be seen in the section "PACKAGE CONTENTS", below.
f4b865988759de2bcc51ffd55897191c74e53ba2Eugen KuksaThis package has one data member: "types". This is a dictionary which maps the
9e3e0144c09a30bdb6211168a35dacbf0cb130d8Eugen Kuksaaction names to the classes that represent them.
9e3e0144c09a30bdb6211168a35dacbf0cb130d8Eugen KuksaThis package also has one function: "fromstr", which creates an action instance
9e3e0144c09a30bdb6211168a35dacbf0cb130d8Eugen Kuksabased on a str() representation of an action.
9f9aab3a5e6a6beca675c7f90f9af56a3636f000Eugen Kuksa# All modules in this package (all python files except __init__.py with their
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa# extensions stripped off).
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa# A dictionary of all the types in this package, mapping to the classes that
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa# define them.
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa module = __import__("%s.%s" % (__name__, modname),
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa nvlist = inspect.getmembers(module, inspect.isclass)
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa # Pull the class objects out of nvlist, keeping only those that are
f4b865988759de2bcc51ffd55897191c74e53ba2Eugen Kuksa # actually defined in this package.
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa if '.'.join(c[1].__module__.split('.')[:-1]) == __name__
a847d9812b328c048773e705606b10875a929034Eugen Kuksa# Clean up after ourselves
a847d9812b328c048773e705606b10875a929034Eugen Kuksa """Base exception class for Action errors."""
8ec575832389c2588f0b5ca1f1dd2cc42d62eb12= # To workaround python issues 6108 and 2517, this provides a
8ec575832389c2588f0b5ca1f1dd2cc42d62eb12= # a standard wrapper for this class' exceptions so that they
8ec575832389c2588f0b5ca1f1dd2cc42d62eb12= # have a chance of being stringified correctly.
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa if hasattr(self, "fmri") and self.fmri is not None:
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa return _("unknown action type '%(type)s' in package "
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa "'%(fmri)s' in action '%(action)s'") % {
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa return _("unknown action type '%(type)s' in action "
039b6fe97fd37af689c6991e6fceef72bbd617fcEugen Kuksa if hasattr(self, "fmri") and self.fmri is not None:
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa return _("Malformed action in package '%(fmri)s' at "
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa "position: %(pos)d:\n %(action)s\n"
307902584a4a70170eae6dc80e17d87f680fe2b3Eugen Kuksa return _("Malformed action at position: %(pos)d:\n "
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa "%(action)s\n%(marker)s") % { "pos": self.position,
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa """Used to indicate that a file-related error occuring during action
a5a4e2f7ee10435dab96569b4514486f0eee6c09Eugen Kuksa initialization."""
307902584a4a70170eae6dc80e17d87f680fe2b3Eugen Kuksa """Used to indicate that attributes provided were invalid, or required
307902584a4a70170eae6dc80e17d87f680fe2b3Eugen Kuksa attributes were missing for an action."""
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa if hasattr(self, "fmri") and self.fmri is not None:
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa return _("invalid action in package %(fmri)s: "
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa "action": self.actionstr, "error": self.errorstr }
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa return _("invalid action, '%(action)s': %(error)s") % {
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa "action": self.actionstr, "error": self.errorstr }
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa """Create an attribute dict given a string w/ key=value pairs.
82943dcc7f878756736a3f21a8100b389b94ba46Eugen Kuksa Raises MalformedActionError if the attributes have syntactic problems.
039b6fe97fd37af689c6991e6fceef72bbd617fcEugen Kuksa """Create an action instance based on a str() representation of an
039b6fe97fd37af689c6991e6fceef72bbd617fcEugen Kuksa Raises UnknownActionError if the action type is unknown.
039b6fe97fd37af689c6991e6fceef72bbd617fcEugen Kuksa Raises MalformedActionError if the action has other syntactic problems.
2725ada6b2a776abaadd22b0006097eae9ba2b02Julian Kornberger action = types[atype](data=data, **attr_dict)
2725ada6b2a776abaadd22b0006097eae9ba2b02Julian Kornberger if ka is not None and (ka not in action.attrs or
2725ada6b2a776abaadd22b0006097eae9ba2b02Julian Kornberger raise InvalidActionError(string, _("required attribute '%s' "
2725ada6b2a776abaadd22b0006097eae9ba2b02Julian Kornbergerdef internalizelist(atype, args, ahash=None, basedirs=None):
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa """Create an action instance based on a sequence of "key=value" strings.
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa This function also translates external representations of actions with
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa payloads (like file and license which can use NOHASH or file paths to
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa point to the payload) to an internal representation which sets the
8154de978abb605f24405ee3c94bc148ebe4b28bEugen Kuksa data field of the action returned.
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa The "atype" parameter is the type of action to be built.
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa The "args" parameter is the sequence of "key=value" strings.
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa The "ahash" parameter is used to set the hash value for the action.
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa The "basedirs" parameter is the list of directories to look in to find
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa any payload for the action.
a2b3d5bb602a9a0d970b6640948f1d7d75ce78bfEugen Kuksa Raises MalformedActionError if the attribute strings are malformed.
data = None
attrs = {}
raise MalformedActionError(
if a not in attrs:
attrs[a] = v
except ValueError:
if ahash:
return action, None
if not payload:
if basedirs:
for d in basedirs:
return data