__init__.py revision 3339
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, 2016, 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. 51N/AThis package has two data members: 51N/A "types", a dictionary which maps the action names to the classes that 51N/A "payload_types", a dictionary which maps action names that deliver payload 49N/A 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. 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 49N/A# A dictionary of the action names in this package that deliver payload, 49N/A# according to the 'has_payload' member in each class. The dictionary is keyed 49N/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. 591N/A """Base exception class for Action errors.""" 873N/A return _(
"Need to try installing {action} again").
format(
591N/A return _(
"unknown action type '{type}' in package " 2639N/A return _(
"unknown action type '{type}' in action " 1544N/A return _(
"Malformed action in package '{fmri}' at " 1755N/A "position: {pos:d}: {error}:\n {action}\n" 873N/A return _(
"Malformed action at position: {pos:d}: {error}:\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 591N/A attributes were missing for an action.""" 2639N/A return _(
"invalid action in package {fmri}: " 2639N/A """Used to indicate that an action's key attribute is missing.""" 2639N/A """Used to indicate that an action's key attribute was specified 1755N/A multiple times for an action that expects it only once.""" 1755N/A """Used to indicate that an action's path attribute value was either 1755N/A empty, '/', or not a string.""" 1755N/A _(
"Empty or invalid path attribute"))
1755N/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 1292N/A return _(
"The action '{action}' in package " 2639N/A "'{fmri}' has invalid attribute(s):\n" 279N/A return _(
"The action '{action}' has invalid attribute(s):\n" 1500N/A# This must be imported *after* all of the exception classes are defined as 1500N/A# _actions module init needs the exception objects. 1500N/A """Create an attribute dict given a string w/ key=value pairs. 1500N/A Raises MalformedActionError if the attributes have syntactic problems. 305N/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 873N/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. 305N/A The "ahash" parameter is used to set the hash value for the action. 305N/A The "basedirs" parameter is the list of directories to look in to find 305N/A any payload for the action. 591N/A Raises MalformedActionError if the attribute strings are malformed. 305N/A # list comprehension in Python 3 doesn't leak loop control 305N/A # variable to surrounding variable, so use a regular loop 1659N/A # This is by far the common case-- an attribute with 1500N/A # We're only here if the for: statement above throws a 2456N/A # MalformedActionError. That can happen if split yields a 2456N/A # single element, which is possible if e.g. an attribute lacks 1500N/A # keys called 'data' cause problems due to the named parameter being 1500N/A # passed to the action constructor below. Check for these. Note that 1500N/A # _fromstr also checks for this. 2456N/A """Create an action instance based on a sequence of strings. 1500N/A This function also translates external representations of actions with 2456N/A payloads (like file and license which can use NOHASH or file paths to 2456N/A point to the payload) to an internal representation which sets the 2456N/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 1500N/A payload and returns the actual path used to set the data and the 1500N/A source used to find the data (this may be a path or a bundle 2456N/A The "payload" parameter is the representation of the data to assign to 2456N/A the action's data field. It can either be NOHASH or a path to the file. 2456N/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 "was not found in any of the provided locations:" "not found in any of the provided sources:" # Only if no explicit sources were provided should a # fallback to filepath be performed. # This relies on data having a value set by the code above so that an # ActionDataError will be raised if the file doesn't exist or is not