__init__.py revision 2843
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] 2639N/A# Copyright (c) 2007, 2012, 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 49N/Acan be seen in the section "PACKAGE CONTENTS", below. 2843N/AThis package has two data members: 2843N/A "types", a dictionary which maps the action names to the classes that 2843N/A "payload_types", a dictionary which maps action names that deliver payload 2843N/A to the classes that represent them. 51N/AThis package also has one function: "fromstr", which creates an action instance 51N/Abased on a str() representation of an action. 49N/A# All modules in this package (all python files except __init__.py with their 49N/A# extensions stripped off). 49N/A# A dictionary of all the types in this package, mapping to the classes that 2843N/A# A dictionary of the action names in this package that deliver payload, 2843N/A# according to the 'has_payload' member in each class. The dictionary is keyed 2843N/A# by the action name, and has the action class as its values. 49N/A # Pull the class objects out of nvlist, keeping only those that are 49N/A # actually defined in this package. 49N/A# Clean up after ourselves 873N/A """Base exception class for Action errors.""" 1540N/A # To workaround python issues 6108 and 2517, this provides a 1540N/A # a standard wrapper for this class' exceptions so that they 1540N/A # have a chance of being stringified correctly. 873N/A return _(
"unknown action type '%(type)s' in package " 873N/A "'%(fmri)s' in action '%(action)s'") % {
873N/A return _(
"unknown action type '%(type)s' in action " 873N/A return _(
"Malformed action in package '%(fmri)s' at " 2639N/A "position: %(pos)d: %(error)s:\n %(action)s\n" 2639N/A return _(
"Malformed action at position: %(pos)d: %(error)s:\n " 873N/A """Used to indicate that a file-related error occuring during action 873N/A """Used to indicate that attributes provided were invalid, or required 873N/A attributes were missing for an action.""" 873N/A return _(
"invalid action in package %(fmri)s: " 873N/A return _(
"invalid action, '%(action)s': %(error)s") % {
2639N/A """Used to indicate that an action's key attribute is missing.""" 2639N/A _(
"no value specified for key attribute '%s'") %
args[
1])
2639N/A """Used to indicate that an action's key attribute was specified 2639N/A multiple times for an action that expects it only once.""" 2639N/A _(
"%s attribute may only be specified once") %
args[
1])
2639N/A """Used to indicate that an action's path attribute value was either 2639N/A empty, '/', or not a string.""" 2639N/A _(
"Empty or invalid path attribute"))
2476N/A """Used to indicate that one or more action attributes were invalid.""" 1755N/A """'act' is an Action (object or string). 1755N/A 'errors' is a list of tuples of the form (name, error) where 1755N/A 'name' is the action attribute name, and 'error' is a string 1755N/A indicating what attribute is invalid and why. 1755N/A 'fmri' is an optional package FMRI (object or string) 1755N/A indicating what package contained the actions with invalid 1755N/A return _(
"The action '%(action)s' in package " 1755N/A "'%(fmri)s' has invalid attribute(s):\n" 1755N/A return _(
"The action '%(action)s' has invalid attribute(s):\n" 2639N/A# This must be imported *after* all of the exception classes are defined as 2639N/A# _actions module init needs the exception objects. 1292N/A """Create an attribute dict given a string w/ key=value pairs. 1292N/A Raises MalformedActionError if the attributes have syntactic problems. 279N/A """Create an action instance based on a sequence of "key=value" strings. 1500N/A This function also translates external representations of actions with 1500N/A payloads (like file and license which can use NOHASH or file paths to 1500N/A point to the payload) to an internal representation which sets the 1500N/A data field of the action returned. 1500N/A The "atype" parameter is the type of action to be built. 1500N/A The "args" parameter is the sequence of "key=value" strings. 1500N/A The "ahash" parameter is used to set the hash value for the action. 1500N/A The "basedirs" parameter is the list of directories to look in to find 1500N/A any payload for the action. 591N/A Raises MalformedActionError if the attribute strings are malformed. 305N/A # This is by far the common case-- an attribute with 305N/A # We're only here if the for: statement above throws a 591N/A # MalformedActionError. That can happen if split yields a 591N/A # single element, which is possible if e.g. an attribute lacks 1659N/A # keys called 'data' cause problems due to the named parameter being 1659N/A # passed to the action constructor below. Check for these. Note that 1659N/A # _fromstr also checks for this. 1500N/A """Create an action instance based on a sequence of strings. 1500N/A This function also translates external representations of actions with 1500N/A payloads (like file and license which can use NOHASH or file paths to 1500N/A point to the payload) to an internal representation which sets the 1500N/A data field of the action returned. 1500N/A In general, each string should be in the form of "key=value". The 1500N/A exception is a payload for certain actions which should be the first 1500N/A Raises MalformedActionError if the attribute strings are malformed. 1500N/A """Sets the data field of an action using the information in the 2456N/A payload and returns the actual path used to set the data and the 2456N/A source used to find the data (this may be a path or a bundle 1500N/A The "payload" parameter is the representation of the data to assign to 1500N/A the action's data field. It can either be NOHASH or a path to the file. 1500N/A The "action" parameter is the action to modify. 2456N/A The "basedirs" parameter contains the directories to examine to find the 2456N/A The "bundles" parameter contains a list of bundle objects to find the 2456N/A # Attempt to find directory or bundle containing source of file data. 2456N/A # look for file in specified dir 2456N/A "was not found in any of the provided locations:" 2456N/A "not found in any of the provided sources:" 2456N/A # Only if no explicit sources were provided should a 2456N/A # fallback to filepath be performed. 2456N/A # This relies on data having a value set by the code above so that an 2456N/A # ActionDataError will be raised if the file doesn't exist or is not