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