__init__.py revision 1908
49N/A# The contents of this file are subject to the terms of the 49N/A# Common Development and Distribution License (the "License"). 49N/A# You may not use this file except in compliance with the License. 49N/A# See the License for the specific language governing permissions 49N/A# and limitations under the License. 49N/A# When distributing Covered Code, include this CDDL HEADER in each 49N/A# If applicable, add the following below this CDDL HEADER, with the 49N/A# fields enclosed by brackets "[]" replaced with your own identifying 49N/A# information: Portions Copyright [yyyy] [name of copyright owner] 409N/A# Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. 49N/Apackage containing packaging action (file type) modules 49N/AThis package contains modules describing packaging actions, or file types. The 49N/Aactions are dynamically discovered, so that new modules can be placed in this 49N/Apackage directory and they'll just be picked up. The current package contents 96N/Acan be seen in the section "PACKAGE CONTENTS", below. 49N/AThis package has one data member: "types". This is a dictionary which maps the 49N/Aaction names to the classes that represent them. 49N/AThis package also has one function: "fromstr", which creates an action instance 49N/Abased on a str() representation of an action. 237N/A# All modules in this package (all python files except __init__.py with their 237N/A# extensions stripped off). 237N/A# A dictionary of all the types in this package, mapping to the classes that 583N/A # Pull the class objects out of nvlist, keeping only those that are 136N/A # actually defined in this package. 462N/A# Clean up after ourselves 462N/A """Base exception class for Action errors.""" 96N/A # To workaround python issues 6108 and 2517, this provides a 222N/A # a standard wrapper for this class' exceptions so that they 237N/A # have a chance of being stringified correctly. 237N/A return _(
"unknown action type '%(type)s' in package " 583N/A "'%(fmri)s' in action '%(action)s'") % {
583N/A return _(
"unknown action type '%(type)s' in action " return _(
"Malformed action in package '%(fmri)s' at " "position: %(pos)d:\n %(action)s\n" return _(
"Malformed action at position: %(pos)d:\n " """Used to indicate that a file-related error occuring during action """Used to indicate that attributes provided were invalid, or required attributes were missing for an action.""" return _(
"invalid action in package %(fmri)s: " "%(action)s: %(error)s") % {
"fmri":
self.
fmri,
return _(
"invalid action, '%(action)s': %(error)s") % {
"""Used to indicate that one more action attributes were invalid.""" """'act' is an Action (object or string). 'errors' is a list of tuples of the form (name, error) where 'name' is the action attribute name, and 'error' is a string indicating what attribute is invalid and why. 'fmri' is an optional package FMRI (object or string) indicating what package contained the actions with invalid return _(
"The action '%(action)s' in package " "'%(fmri)s' has invalid attribute(s):\n" return _(
"The action '%(action)s' has invalid attribute(s):\n" """Create an attribute dict given a string w/ key=value pairs. Raises MalformedActionError if the attributes have syntactic problems. """Create an action instance based on a str() representation of an Raises UnknownActionError if the action type is unknown. Raises MalformedActionError if the action has other syntactic problems. "was not provided.") %
ka)
"""Create an action instance based on a sequence of "key=value" strings. This function also translates external representations of actions with payloads (like file and license which can use NOHASH or file paths to point to the payload) to an internal representation which sets the data field of the action returned. The "atype" parameter is the type of action to be built. The "args" parameter is the sequence of "key=value" strings. The "ahash" parameter is used to set the hash value for the action. The "basedirs" parameter is the list of directories to look in to find any payload for the action. Raises MalformedActionError if the attribute strings are malformed. if atype in (
"file",
"license"):
# This is by far the common case-- an attribute with # We're only here if the for: statement above throws a # MalformedActionError. That can happen if split yields a # single element, which is possible if e.g. an attribute lacks len(
p1) +
2,
"attribute '%s'" %
kv)
# keys called 'data' cause problems due to the named parameter being # passed to the action constructor below. Check for these. Note that # _fromstr also checks for this. "%s action cannot have a 'data' attribute" %
atype)
"'%s', was not provided.") %
ka)
"""Create an action instance based on a sequence of strings. This function also translates external representations of actions with payloads (like file and license which can use NOHASH or file paths to point to the payload) to an internal representation which sets the data field of the action returned. In general, each string should be in the form of "key=value". The exception is a payload for certain actions which should be the first Raises MalformedActionError if the attribute strings are malformed. """Sets the data field of an action using the information in the payload and returns the actual path used to set the data and the basedir used to find the path to the data. The "payload" parameter is the representation of the data to assign to the action's data field. It can either be NOHASH or a path to the file. The "action" parameter is the action to modify. The "basedirs" parameter contains the directories to examine to find # look for file in specified dirs