usr/src/lib/install_utils/DefValProc.py
author Sue Sohn <Susan.Sohn@Oracle.COM>
Fri, 20 Aug 2010 11:31:18 -0600
changeset 862 e9f31f2f2f2d
parent 649 ba353c37b287
child 947 29603af1b942
permissions -rw-r--r--
16423 Updates to AI schema should be made 15449 installadm add validates combined manifest against image-specific schema as well as schema in /usr/share/auto_install/ 6975043 separate criteria and ai manifest 6975686 installadm list shows value rather than range if lower bound is 0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     1
#
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     2
# CDDL HEADER START
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     3
#
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     4
# The contents of this file are subject to the terms of the
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     5
# Common Development and Distribution License (the "License").
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     6
# You may not use this file except in compliance with the License.
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     7
#
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     8
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     9
# or http://www.opensolaris.org/os/licensing.
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    10
# See the License for the specific language governing permissions
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    11
# and limitations under the License.
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    12
#
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    13
# When distributing Covered Code, include this CDDL HEADER in each
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    14
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    15
# If applicable, add the following below this CDDL HEADER, with the
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    16
# fields enclosed by brackets "[]" replaced with your own identifying
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    17
# information: Portions Copyright [yyyy] [name of copyright owner]
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    18
#
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    19
# CDDL HEADER END
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    20
#
862
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
    21
# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    22
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    23
# =============================================================================
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    24
# =============================================================================
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    25
"""
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    26
Module to validate defaults and contents info.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    27
"""
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    28
# =============================================================================
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    29
# =============================================================================
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    30
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    31
import sys
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    32
import subprocess
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    33
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    34
from osol_install.TreeAcc import TreeAcc
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    35
from osol_install.TreeAcc import TreeAccNode
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    36
from osol_install.TreeAcc import TreeAccError
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    37
from osol_install.install_utils import canaccess
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    38
from osol_install.install_utils import space_parse
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    39
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    40
# =============================================================================
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    41
# Constants
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    42
# =============================================================================
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    43
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    44
# Error status
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    45
GENERAL_ERR = 1
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    46
SUCCESS = 0
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    47
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    48
# XML validator program, run on XML docs to validate against a schema.
862
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
    49
XML_VALIDATOR = "/bin/xmllint"
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
    50
XML_RNG_SCHEMA = "--relaxng"
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
    51
XML_DTD_SCHEMA = "--dtdvalid"
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
    52
XML_DTD_DEFAULTS = "--dtdattr"
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    53
XML_REFORMAT_SW = "--format"
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    54
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    55
# Defaults and validation manifest doc and schema filenames.
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    56
DEFVAL_SCHEMA = "/usr/share/lib/xml/rng/defval-manifest.rng "
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    57
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    58
# Schema to validate manifest XML doc against.
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    59
MANIFEST_SCHEMA = "/usr/lib/python2.6/vendor-packages/osol_install/" + \
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    60
                  "distro_const/DC-manifest.rng "
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    61
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    62
# Default XML value if invert isn't specified in the defval-manifest.
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    63
DEFAULT_INVERT_VALUE_STR = "False"
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    64
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    65
# =============================================================================
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    66
# General module initializion code
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    67
# =============================================================================
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    68
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    69
DEFAULT_INVERT_VALUE = (DEFAULT_INVERT_VALUE_STR == "True")
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    70
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    71
# =============================================================================
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    72
# Error handling classes
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    73
# =============================================================================
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    74
class ManifestProcError(StandardError):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    75
    """Exception for manifest_proc errors"""
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    76
    pass
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    77
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    78
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    79
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    80
# =============================================================================
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    81
class _HelperDicts:
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    82
# =============================================================================
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    83
    """ Class of objects containing modules, methods and optionally invert
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    84
        statuses indexed by a reference (ref) string.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    85
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    86
    These objects contain dictionaries which allow a module, method and
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    87
    invert status combination to be referenced by a common string.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    88
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    89
    """
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    90
# =============================================================================
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    91
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    92
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    93
    def __init__(self, module_dict, method_dict, invert_dict=None):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    94
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    95
        """ Constructor
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    96
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    97
        Args:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    98
          module_dict: Dictionary of modules indexed by a ref string
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    99
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   100
          method_dict: Dictionary of methods indexed by a ref string
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   101
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   102
          invert_dict: Optional dictionary of boolean invert statuses
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   103
            indexed by a ref string
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   104
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   105
        Raises: None
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   106
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   107
        """
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   108
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   109
        self.modules = module_dict
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   110
        self.methods = method_dict
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   111
        self.inverts = invert_dict
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   112
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   113
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   114
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   115
    @staticmethod
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   116
    def new(defval_tree, nodepath):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   117
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   118
        """ Return a new helper object containing modules and methods
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   119
            indexed by a reference (ref) string.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   120
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   121
        Args:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   122
          defval_tree: Tree of defaults and validation nodes (TreeAccNodes)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   123
            containing the information.  This tree has been read in from the
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   124
            defval manifest and contains references to the validator and default
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   125
            setter methods and their host modules.  It is assumed that the
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   126
            methods are part of a class of the same name as their host module.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   127
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   128
          nodepath: Root of tree branch containing information on helper
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   129
            methods of interest.  For example, the part of the tree
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   130
            containing validator methods or the part containing
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   131
            methods filling in defaults.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   132
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   133
        Returns:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   134
          If information is found under "nodepath" in the defval_tree:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   135
            returns a new helper object containing dictionaries for
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   136
            module and method.  Both dictionaries are indexed by a
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   137
            ref string.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   138
          Otherwise returns an object with empty module and method dicts
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   139
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   140
        Raises:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   141
          ManifestProcError: Helper ref (index string) is not unique
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   142
          ManifestProcError: Invalid python helper module name
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   143
          ImportError: Helper module cannot be imported
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   144
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   145
        """
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   146
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   147
        modules = {}	# Dict of modules indexed by ref
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   148
        methods = {}	# Dict of methods indexed by ref
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   149
        inverts = {}	# Dict of boolean invert statuses indexed by ref
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   150
        class_names = {}	# Used for internal processing
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   151
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   152
        # Extract helpers from the tree.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   153
        helpers = defval_tree.find_node(nodepath)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   154
        if (len(helpers) == 0):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   155
            return _HelperDicts(modules, methods, None)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   156
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   157
        # Each helper element contains attributes for module, method
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   158
        # and ref.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   159
        for helper in helpers:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   160
            # Get list of attributes for current helper element.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   161
            helper_attrs = helper.get_attr_dict()
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   162
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   163
            # This is the ref string used to index into the
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   164
            # dictionaries for a given method in a given module.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   165
            ref = helper_attrs["ref"]
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   166
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   167
            # Make sure the helper ref is unique.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   168
            if ref in methods:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   169
                raise ManifestProcError, ("HelperDicts.new: helper ref " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   170
                                          ref + " is not unique")
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   171
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   172
            # Get and validate module name.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   173
            module_name = helper_attrs["module"]
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   174
            if not module_name.endswith(".py"):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   175
                raise ManifestProcError, ("HelperDicts.new: Invalid python " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   176
                                         "helper module name: " + module_name)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   177
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   178
            # Assume class is same name as the module it's in.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   179
            class_name = module_name[:-3]
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   180
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   181
            # Maintain a list of class names.  This list is used
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   182
            # to prevent multiple compilations of the same module.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   183
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   184
            # Search list of class names for a match.  If a match
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   185
            # is found, refer to the corresponding module instance
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   186
            # instead of creating a new one.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   187
            for key, name in class_names.items():
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   188
                if (class_name == name):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   189
                    modules[ref] = modules[key]
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   190
                    break
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   191
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   192
            # Note: in trouble if rename helper_module to
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   193
            # helpers.  (Maybe can use local_dicts?)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   194
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   195
            # Module not in list.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   196
            else:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   197
                # Add name to the list and compile the module.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   198
                class_names[ref] = class_name
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   199
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   200
                # Import the module.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   201
                # The ugly-looking rfind below strips all to
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   202
                # the left of the final dot (e.g package names).
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   203
                # __import__ returns package, not module, unless a method
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   204
                # name is given as fourth arg.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   205
                constr_name = class_name[(class_name.rfind(".") + 1):]
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   206
                module_imp = __import__(class_name, globals(), locals(),
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   207
                                        [constr_name], -1)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   208
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   209
                # Instantiate and save a module instance.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   210
                constr = getattr(module_imp,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   211
                                 class_name[(class_name.rfind(".") + 1):])
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   212
                modules[ref] = constr()
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   213
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   214
            # Save the method in the instance's methods dictionary.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   215
            methods[ref] = helper_attrs["method"]
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   216
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   217
            # Save invert status in instance's inverts dictionary.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   218
            # If not specified, assume DEFAULT_INVERT_VALUE_STR.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   219
            try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   220
                ivalue = helper_attrs["invert"]
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   221
            except KeyError:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   222
                ivalue = DEFAULT_INVERT_VALUE_STR
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   223
            inverts[ref] = (ivalue == "True")
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   224
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   225
        # If all inverts values are the default, it may be that this
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   226
        # HelperDict is not for validation and inverts aren't used.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   227
        # Optimize that if all invert values are the default, don't
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   228
        # store inverts in this _HelperDicts instance.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   229
        keep_inverts = False
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   230
        for ivalue in inverts.itervalues():
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   231
            if (ivalue != DEFAULT_INVERT_VALUE):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   232
                keep_inverts = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   233
                break
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   234
        if (not keep_inverts):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   235
            inverts = None
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   236
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   237
        return _HelperDicts(modules, methods, inverts)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   238
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   239
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   240
# =============================================================================
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   241
# Procedural functions, not part of a class
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   242
# =============================================================================
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   243
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   244
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
862
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
   245
def __validate_vs_schema(schema, in_xml_doc, out_xml_doc=None,
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
   246
                         dtd_schema=False):
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   247
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   248
    """ Validate an XML document against a schema.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   249
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   250
    Runs the command given by XML_VALIDATOR.  Schema must follow the
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   251
    XML_VALIDATOR string.  If out_xml_doc is specified, reformat the
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   252
    xml doc  using the XML_REFORMAT_SW passed to the validator.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   253
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   254
    Args:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   255
      schema: The schema to validate against.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   256
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   257
      in_xml_doc: The XML document to validate.
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
   258
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   259
      out_xml_doc: Reformatted XML doc
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   260
862
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
   261
      dtd_schema: Optional. Defaults to False.
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
   262
        If True, validate against DTD Schema file.  If False, use RNG.
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
   263
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   264
    Returns: N/A
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   265
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   266
    Raises:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   267
      OSError: Error starting or running shell
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   268
      ManifestProcError: The validator returned an error status or
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   269
        was terminated by a signal.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   270
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   271
    """
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   272
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   273
    schema = schema.strip()
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   274
    in_xml_doc = in_xml_doc.strip()
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
   275
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   276
    # Need to check file access explicitly since the XML
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   277
    # validator doesn't return proper errno if files not accessible.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   278
    # IOError exceptions (from canaccess()) require no special
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   279
    # handling here, except for closing outfile.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   280
    # Just let IOErrors get thrown and propagated.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   281
    canaccess(schema, "r")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   282
    canaccess(in_xml_doc, "r")
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   283
862
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
   284
    command_list = [XML_VALIDATOR]
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
   285
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
   286
    if dtd_schema:
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
   287
        command_list.append(XML_DTD_SCHEMA)
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
   288
        command_list.append(schema)
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
   289
        command_list.append(XML_DTD_DEFAULTS)
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
   290
    else:
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
   291
        command_list.append(XML_RNG_SCHEMA)
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
   292
        command_list.append(schema)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   293
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   294
    if (out_xml_doc is not None):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   295
        command_list.append(XML_REFORMAT_SW)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   296
        outfile = file(out_xml_doc.strip(), "w")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   297
    else:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   298
        outfile = file("/dev/null", "w")
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
   299
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   300
    command_list.append(in_xml_doc)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   301
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   302
    try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   303
        try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   304
            rval = subprocess.Popen(command_list, stdout=outfile).wait()
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   305
            if (rval < 0):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   306
                print >> sys.stderr, ("validate_vs_schema: " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   307
                                      "Validator terminated by signal" +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   308
                                      str(-rval))
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   309
            elif (rval > 0):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   310
                print >> sys.stderr, ("validate_vs_schema: " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   311
                                      "Validator terminated with status " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   312
                                      str(rval))
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   313
            if (rval != 0):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   314
                raise ManifestProcError, ("validate_vs_schema: " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   315
                                          "Validator terminated abnormally")
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   316
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   317
        # Print extra error message here for OSErrors as unexpected.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   318
        except OSError:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   319
            print >> sys.stderr, ("validate_vs_schema: " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   320
                                  "Error starting or running shell:")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   321
            print >> sys.stderr, "shell_list = " + str(command_list)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   322
            raise
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   323
    finally:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   324
        outfile.close()
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   325
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   326
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   327
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   328
def __generate_ancestor_nodes(tree, nodepath):
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   329
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   330
    """ Create ancestor nodes along given nodepath from root on down, as
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   331
        needed.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   332
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   333
    Nodes created will have no value, and all but the last node created
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   334
    will have one child, the next node in the created nodepath.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   335
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   336
    Nodepath is assumed to be from the tree root and deterministic at each
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   337
    piece.  Since created nodepath is to a soon-to-be non-leaf node, all
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   338
    nodepath items created will be elements.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   339
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   340
    Args:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   341
      tree: Tree in which the nodes are created.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   342
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   343
      nodepath: Path defining where nodes are created in the tree.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   344
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   345
    Returns:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   346
      The node created furthest from the root.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   347
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   348
    Raises:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   349
      ManifestProcError: non-deterministic nodepath specified.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   350
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   351
    """
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   352
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   353
    nodepath_pieces = nodepath.split("/")
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   354
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   355
    # Note current_node starts out and remains a one-item list.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   356
    ancestor_node = current_node = tree.find_node(nodepath_pieces[0])
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   357
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   358
    # Err out if the nodepath (from the defval manifest) doesn't jibe
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   359
    # with the project manifest.  At a minimum, the tops of the trees
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   360
    # should be the same.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   361
    if (len(ancestor_node) == 0):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   362
        raise ManifestProcError, ("generate_ancestor_nodes: " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   363
                                  "manifest and defval manifest " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   364
                                  "are incompatible")
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   365
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   366
    # Iterate from the top of the nodepath, filling in nodes which are
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   367
    # missing.  New nodes will have no value.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   368
    for i in range(1, len(nodepath_pieces)):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   369
        current_node = tree.find_node(nodepath_pieces[i],
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   370
                                      ancestor_node[0])
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   371
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   372
        # Add missing ancestor node.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   373
        if (len(current_node) == 0):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   374
            new_node = tree.add_node(nodepath_pieces[i], "",
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   375
                                     TreeAccNode.ELEMENT, ancestor_node[0])
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   376
            current_node = [new_node]
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   377
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   378
        elif (len(current_node) > 1):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   379
            raise ManifestProcError, ("generate_ancestor_nodes: " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   380
                                      "non-deterministic nodepath specified")
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   381
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   382
        ancestor_node = current_node
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   383
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   384
    return current_node
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   385
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   386
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   387
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   388
def __get_value_from_helper(method_ref, deflt_setter_dicts,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   389
                            parent_node, debug):
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   390
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   391
    """ Consult a helper method to calculate/retrieve a value.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   392
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   393
    Args:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   394
      method_ref: Nickname reference of the helper method to call.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   395
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   396
      deflt_setter_dicts: _HelperDicts object containing helper information
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   397
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   398
      parent_node: Parent node of the new node (for whose value the helper
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   399
        is being consulted).  The helper method will be called with
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   400
        this node, from which it can get a pointer to the tree as well
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   401
        as context to perform its calculation.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   402
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   403
      debug: Print tracing / debug messages when True
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
   404
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   405
    Returns:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   406
      A string representation of the value as returned by the helper method.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   407
          Convert any python boolean value strings to all-lowercase, to
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   408
        match how booleans are represented in XML documents.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   409
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   410
    Raises:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   411
      ManifestProcError: Helper method missing from defval manifest file
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   412
      AttributeError: Helper method is not in module
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   413
      StandardError: Helper method raised an exception
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   414
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   415
    """
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   416
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   417
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   418
    if ((method_ref not in deflt_setter_dicts.modules) or
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   419
        (method_ref not in deflt_setter_dicts.methods)):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   420
        raise ManifestProcError, ("get_value_from_helper: Helper method " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   421
                                  "ref %s missing from defval manifest file" %
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   422
                                  method_ref)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   423
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   424
    module = deflt_setter_dicts.modules[method_ref]
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   425
    method = deflt_setter_dicts.methods[method_ref]
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   426
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   427
    if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   428
        print ("Call helper method " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   429
               deflt_setter_dicts.methods[method_ref] + "()")
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   430
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   431
    # Note: methods calculating defaults take only the parent node as arg.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   432
    try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   433
        func = getattr(module, method)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   434
    except AttributeError:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   435
        print >> sys.stderr, ("get_value_from_helper: Helper method " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   436
                              "%s not in module %s" % (method, module))
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   437
        raise
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   438
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   439
    try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   440
        value = func(parent_node)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   441
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   442
    except StandardError:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   443
        print >> sys.stderr, ("get_value_from_helper: Helper method " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   444
                                  "%s raised an exception: " % method_ref)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   445
        raise
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   446
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   447
    # Convert all return values to strings.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   448
    #
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   449
    # Booleans are a special case.  Python boolean values (and their string
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   450
    # equivalents when converted) begin with capital letters.  However, XML
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   451
    # boolean string values are all in lower case.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   452
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   453
    if (isinstance(value, bool)):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   454
        retvalue = str(value).lower()
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   455
    else:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   456
        retvalue = str(value)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   457
    return retvalue
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   458
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   459
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   460
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
   461
def __do_skip_if_no_exist(attributes, manifest_tree, debug):
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   462
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   463
    """ Determines whether or not to skip processing of a node because an
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   464
        ancestral node to it doesn't exist.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   465
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   466
    Check if the "skip_if_no_exist" attribute exists in the attributes
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   467
    list passed in.  If it does, and if the (ancestral) node it refers to
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   468
    doesn't exist in manifest_tree, then return True, that it's OK to skip
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   469
    creating/processing.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   470
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   471
    Args:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   472
      attributes: Attributes list to check for skip_if_no_exist in.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   473
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   474
      manifest_tree: tree to search for the node identified by the
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   475
        skip_if_no_exist attribute.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   476
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   477
      debug: Print tracing / debug messages when True
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
   478
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   479
    Returns:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   480
      True: skip_if_no_exist attribute exists and identifies a node which
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   481
        doesn't exist.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   482
      False: otherwise
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   483
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   484
    Raises: None
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   485
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   486
    """
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   487
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   488
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   489
    skip_if_no_exist = attributes.get("skip_if_no_exist", "")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   490
    if (skip_if_no_exist != ""):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   491
        if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   492
            print ("Skip_if_no_exist = %s specified.  checking" %
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   493
                   skip_if_no_exist)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   494
        if (len(manifest_tree.find_node(skip_if_no_exist)) == 0):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   495
            if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   496
                print skip_if_no_exist + " node doesn't exist"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   497
            return True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   498
    return False
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   499
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   500
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   501
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
   502
def add_defaults(manifest_tree, defval_tree, debug=False):
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   503
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   504
    """ Add defaults to manifest_tree, based on defval_tree specifications.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   505
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   506
    This method processes defval_tree nodes with the nodepath "default",
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   507
    each of which specifies a new default.  This method is a noop if
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   508
    defval_tree has no "default" nodes.  "default" nodes have the following
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   509
    attributes:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   510
    - nodepath: The nodepath of the node for which the default is specified.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   511
    - type: type of node (TreeAccNode): must be "attribute" or "element"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   512
    - from: how to derive the default: must be either "value" or "helper".
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   513
        Node's value is a helper method reference when from = "helper"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   514
        Node's value is the default value when from = "value"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   515
    - missing_parent: (optional) What to do if a node whose nodepath matches
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   516
        the nodepath of an immediate parent node (the nodepath less the
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   517
        item beyond the final /) is missing.  When specified, must be
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   518
        one of the following:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   519
        - "create": Create a new empty parent node and then create a
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   520
            new node with the specified nodepath and default value.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   521
            Parent node to create must be deterministic from
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   522
            nodepath.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   523
        - "skip": Do nothing.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   524
        - "error": Err out.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   525
        - default if not specified = "error"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   526
    - empty_str: (optional) What to do when an empty string is encountered.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   527
        An empty string is defined here as a zero length string, or ""
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   528
        or '' to handled quote-enveloped empty strings.  When specified,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   529
        must be one of the following:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   530
        - "set_default": Determine the default as if no node was
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   531
            present, then change the value of any matching
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   532
            empty-string nodes to the default value.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   533
        - "valid": Accept the empty string as a valid value.  Do
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   534
            nothing.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   535
        - "error": Flag the empty string as an error.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   536
        Note that all matching nodes with empty strings will have their
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   537
        default value calculated and plugged.
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   538
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   539
    - skip_if_no_exist: (optional) The nodepath of an ancestor node.  If the
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   540
        ancestor node is missing, skip processing.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   541
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   542
    Args:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   543
      manifest_tree: The tree to which default nodes are added.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   544
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   545
      defval_tree: The tree containing "default" nodes defined as above.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   546
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   547
      debug: Turn on debug / tracing messages when True
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
   548
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   549
    Returns: N/A
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   550
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   551
    Raises:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   552
      KeyError: A required attribute of a "default" node is missing.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   553
      ManifestProcError: Error getting helper methods
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   554
      ManifestProcError: Parent for node at a given nodepath does not exist,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   555
        and the missing_parent attribute is either missing or set to
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   556
        "error"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   557
      ManifestProcError: non-deterministic nodepath specified (for parent
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   558
        when creating parents of default nodes).
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   559
      ManifestProcError: Invalid missing_parent attribute value specified
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   560
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   561
    """
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   562
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   563
    errors = False
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   564
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   565
    # Fetch dictionaries used to reference the helper methods and modules.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   566
    try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   567
        deflt_setters = _HelperDicts.new(defval_tree, "helpers/deflt_setter")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   568
    except ManifestProcError, err:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   569
        print >> sys.stderr, ("add_defaults: Error getting default setter " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   570
                              "methods from defval XML file")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   571
        print >> sys.stderr, str(err)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   572
        raise
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   573
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   574
    # Get a list of all defaults to process.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   575
    defaults = defval_tree.find_node("default")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   576
    if (len(defaults) == 0):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   577
        return
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   578
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   579
    for curr_def in defaults:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   580
        attributes = curr_def.get_attr_dict()
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   581
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   582
        manifest_nodepath = attributes["nodepath"]
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   583
        if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   584
            print "Checking defaults for " + manifest_nodepath
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   585
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   586
        if __do_skip_if_no_exist(attributes, manifest_tree, debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   587
            if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   588
                print "Ancestor doesn't exist.  Skipping..."
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   589
            continue
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   590
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   591
        value_from_xml = curr_def.get_value()
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   592
        type_str = attributes["type"]
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   593
        via = attributes["from"]
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   594
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   595
        if (type_str == "element"):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   596
            node_type = TreeAccNode.ELEMENT
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   597
        else:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   598
            node_type = TreeAccNode.ATTRIBUTE
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   599
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   600
        # Nodepaths which are direct children of the root are special cases
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   601
        try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   602
            (parent_nodepath, child_nodepath) = manifest_nodepath.rsplit("/",
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   603
                                                                         1)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   604
        except ValueError:	# No slashes present in nodepath
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   605
            parent_nodepath = ""
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   606
            child_nodepath = manifest_nodepath
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   607
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   608
        # Fetch the parent nodes.  We cannot just search for the
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   609
        # children directly because we want to guarantee that every
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   610
        # viable parent has at least one child which matches the default
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   611
        # nodepath.  We need to correlate every element containing a
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   612
        # default nodepath to its parent.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   613
        parent_nodes = manifest_tree.find_node(parent_nodepath)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   614
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   615
        # Missing parent nodes anywhere along the tree are errors
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   616
        # if they are those nodes are required.  This is not always the
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   617
        # case though...
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   618
        #
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   619
        # When a node is a parent to an as-yet-unspecified element to
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   620
        # be filled in with a default, just create it if it is missing.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   621
        #
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   622
        # When a parent is itself an optional item, and it is being
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   623
        # sought so that it can be filled in with default attributes or
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   624
        # children elements if it exists, do nothing if it is not there.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   625
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   626
        # A parent somewhere in the chain back to the root is missing.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   627
        if (len(parent_nodes) == 0):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   628
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   629
            # Treat no "missing_parent" attribute for this nodepath
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   630
            # as missing_parent = "error"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   631
            no_parent_handling = attributes.get("missing_parent", "error")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   632
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   633
            if (no_parent_handling == "error"):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   634
                print >> sys.stderr, ("add_defaults: " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   635
                                      "Parent for node at nodepath " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   636
                                      manifest_nodepath + " does not exist")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   637
                errors = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   638
                continue
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   639
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   640
            elif (no_parent_handling == "create"):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   641
                try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   642
                    parent_nodes = __generate_ancestor_nodes(manifest_tree,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   643
                                                             parent_nodepath)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   644
                except ManifestProcError, err:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   645
                    print str(err)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   646
                    print >> sys.stderr, ("add_defaults: Cannot create " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   647
                                          "ancestor nodes for node at " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   648
                                          "nodepath " + manifest_nodepath)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   649
                    errors = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   650
                    continue
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   651
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   652
            elif (no_parent_handling == "skip"):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   653
                continue
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   654
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   655
            else:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   656
                # Shouldn't get here if defaults / validation
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   657
                # manifest passed schema validation.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   658
                print >> sys.stderr, ("add_defaults: Invalid missing_parent " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   659
                                      "attribute value specified: " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   660
                                      no_parent_handling)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   661
                errors = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   662
                continue
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   663
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   664
        # Check how to handle an empty string.  Sometimes an empty
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   665
        # string is a valid value.  Other times it may be as valid as a
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   666
        # missing value, and a default should be set in its place.  The
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   667
        # latter case may prove useful for documentation purposes: as a
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   668
        # placeholder in the XML file for something which can be filled
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   669
        # in later by defaults processing.  Additionally, an empty
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   670
        # string can be an error.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   671
        empty_str = attributes.get("empty_str", "set_default")
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   672
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   673
        if ((empty_str != "set_default") and (empty_str != "valid") and
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   674
            (empty_str != "error")):
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   675
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   676
            # Shouldn't get here if defaults / validation manifest
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   677
            # passed schema validation.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   678
            print >> sys.stderr, ("add_defaults: Invalid \"empty_str\" " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   679
                                  "attribute = " + empty_str)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   680
            errors = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   681
            continue
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   682
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   683
        # Check each parent node for children.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   684
        for parent_node in parent_nodes:
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   685
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   686
            # Assume each parent must have at least one child
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   687
            # (element or attribute) which matches the nodepath of
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   688
            # the default.  If a parent has no such child, give it
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   689
            # one with the default value.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   690
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   691
            # Handle any values present as empty strings.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   692
            nodes = manifest_tree.find_node(child_nodepath, parent_node)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   693
            if nodes:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   694
                for node in nodes:
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   695
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   696
                    # Zero length strings and "" and ''
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   697
                    # are considered empty here.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   698
                    node_value = node.get_value()
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   699
                    if (node_value and not
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   700
                        ((len(node_value) == 2) and
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   701
                        ((node_value == '""') or (node_value == "''")))):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   702
                        continue
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   703
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   704
                    elif (empty_str == "valid"):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   705
                        if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   706
                            print "Valid empty string found"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   707
                        continue
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   708
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   709
                    elif (empty_str != "set_default"):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   710
                        print >> sys.stderr, ("add_defaults: Unpermitted " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   711
                                              "empty string found for " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   712
                                              "nodepath " + manifest_nodepath)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   713
                        errors = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   714
                        continue
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   715
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   716
                    # Install default.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   717
                    try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   718
                        default_value = __get_default(via, value_from_xml,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   719
                                                      deflt_setters,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   720
                                                      parent_node, debug)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   721
                    except ManifestProcError:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   722
                        errors = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   723
                        continue
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   724
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   725
                    if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   726
                        print ("Replacing %s value at %s with %s..." %
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   727
                               (type_str, manifest_nodepath, default_value))
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   728
                    manifest_tree.replace_value(child_nodepath, default_value,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   729
                                                parent_node)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   730
                continue
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   731
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   732
            # No value is present.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   733
            # A new node w/a default value is needed.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   734
            try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   735
                default_value = __get_default(via, value_from_xml,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   736
                                              deflt_setters, parent_node,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   737
                                              debug)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   738
            except ManifestProcError:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   739
                errors = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   740
                continue
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   741
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   742
            if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   743
                print ("Adding %s value at %s with %s..." %
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   744
                       (type_str, manifest_nodepath, default_value))
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   745
            manifest_tree.add_node(child_nodepath, default_value,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   746
                                   node_type, parent_node)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   747
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   748
    if errors:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   749
        raise ManifestProcError, ("One or more errors occured while " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   750
                                  "setting defaults")
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   751
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   752
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   753
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   754
def __get_default(via, value_from_xml, deflt_setters, parent_node, debug):
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   755
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   756
    """ Get or calculate a default value.
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   757
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   758
    Args:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   759
      via: "from" field of the relevant default entry in the defval XML doc:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   760
        set to either "helper" or "value"
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   761
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   762
      value_from_xml: "value" of a default entry in the default XML doc
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   763
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   764
      deflt_setters: dictionary of default setter helper methods.
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   765
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   766
      parent_node: Parent node of the nodes receiving defaults
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   767
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   768
      debug: Turn on debug / tracing messages when True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   769
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   770
    Returns: String value of the sought default
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   771
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   772
    Raises:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   773
      ManifestProcError: exceptions from __get_value_from_helper
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   774
      ManifestProcError: Invalid "from" attribute
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   775
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   776
    """
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   777
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   778
    # Call helper method to determine the value.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   779
    if (via == "helper"):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   780
        try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   781
            default_value = __get_value_from_helper(value_from_xml,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   782
                                                    deflt_setters, parent_node,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   783
                                                    debug)
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   784
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   785
        # Skip and muddle along as best we can on error
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   786
        except StandardError, err:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   787
            print >> sys.stderr, str(err)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   788
            print >> sys.stderr, ("add_defaults: Error getting " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   789
                                  "default value from helper method for " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   790
                                  value_from_xml)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   791
            raise ManifestProcError, str(err)
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   792
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   793
    # Get the value from the defaults / validation manifest.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   794
    elif (via == "value"):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   795
        default_value = value_from_xml
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   796
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   797
    # Shouldn't get here if defaults / validation manifest
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   798
    # passed schema validation.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   799
    else:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   800
        raise ManifestProcError, ("add_defaults: " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   801
                          'Invalid "from" attribute = ' + via)
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   802
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   803
    return default_value
265
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   804
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   805
3686c98a3917 3356 ManifestServ need to be stopped and it's socket file cleaned up
Jack Schwartz <Jack.A.Schwartz@Sun.COM>
parents: 203
diff changeset
   806
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
   807
def __validate_node(validator_ref, validator_dicts, node, debug):
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   808
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   809
    """ Perform semantic validation on a given node.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   810
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   811
    Args:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   812
      method_ref: Nickname reference of the helper method to call.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   813
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   814
      validator_dicts: _HelperDicts object containing helper information.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   815
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   816
      node: The TreeAccNode to validate.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   817
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   818
      debug: Print debug / tracing messages when True
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   819
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   820
    Returns:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   821
        True: The given node has a valid value.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   822
        False: The given node has an invalid value or there was
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   823
            a problem calling the validator helper method.
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
   824
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   825
    Raises:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   826
      ManifestProcError: Validator missing from the defval manifest file.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   827
      AttributeError: Helper method not in module.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   828
      StandardError: Validator method threw an exception.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   829
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   830
    """
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   831
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   832
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   833
    # Get the module and method to call.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   834
    module = validator_dicts.modules.get(validator_ref)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   835
    method = validator_dicts.methods.get(validator_ref)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   836
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   837
    if ((module is None) or (method is None)):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   838
        raise ManifestProcError, ("validate_node: Validator ref " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   839
                                  validator_ref +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   840
                                  " missing from defval manifest file")
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   841
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   842
    if (validator_dicts.inverts is not None):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   843
        invert = validator_dicts.inverts.get(validator_ref,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   844
                                             DEFAULT_INVERT_VALUE)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   845
    else:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   846
        invert = DEFAULT_INVERT_VALUE
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   847
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   848
    if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   849
        print "    call validator method " + method + "()"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   850
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   851
    valid = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   852
    try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   853
        func = getattr(module, method)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   854
    except AttributeError:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   855
        print >> sys.stderr, ("validate_node: Helper method " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   856
                              "%s not in module %s" % (method, module))
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   857
        raise
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   858
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   859
    try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   860
        # Note: methods doing validation return True if valid
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   861
        is_valid = func(node) ^ invert
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   862
        if (not is_valid):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   863
            print >> sys.stderr, ("validate_node: Content \"" +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   864
                                  node.get_value() + "\" at " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   865
                                  node.get_path() + " did not validate")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   866
            valid = False
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   867
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   868
    except StandardError, err:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   869
        print >> sys.stderr, "Validator method threw an exception:"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   870
        print >> sys.stderr, str(err)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   871
        print >> sys.stderr, ("validate_node: Error validating content \"" +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   872
                              node.get_value() + "\" at " + node.get_path() +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   873
                              " using validator " + validator_ref)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   874
        raise
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   875
    return valid
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   876
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   877
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   878
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
   879
def validate_content(manifest_tree, defval_tree, debug=False):
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   880
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   881
    """ Validate nodes of manifest_tree, based on defval_tree specifications.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   882
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   883
    This method processes defval_tree nodes with the nodepath "validate",
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   884
    each of which specifies one or more nodes in the manifest_tree, and a
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   885
    helper method called to do the validation.  This method is a noop if
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   886
    defval_tree has no "validate" nodes.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   887
    There are different kinds of "validate" nodes.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   888
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   889
    - "validate nodepath=" nodes have the following characteristics:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   890
        - "nodepath" attribute: The nodepath of the node(s) to validate.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   891
        - "missing" attribute: (optional) What to do if a node which
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   892
            would match the given nodepath is missing.  When
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   893
            specified, must be one of the following:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   894
            - "ok_if_no_parent": The missing node is acceptable only
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   895
                if it's parent node is also missing.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   896
            - "ok": The missing node is always acceptable.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   897
            - "error": The missing node is not acceptable.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   898
            Defaults to "error" if "missing" attribute not specified
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   899
        - skip_if_no_exist: (optional) The nodepath of an ancestor node.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   900
            If the ancestor node is missing, skip processing.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   901
        - The value of the node is a comma-separated list of one or more
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   902
            helper methods called to do the validation.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   903
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   904
    - "validate group=" nodes have the following characteristics:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   905
        - "group" attribute: The name of a helper method to call to do
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   906
            the validation.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   907
        - The value of the node is a comma-separated list of one or
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   908
            more nodepaths, whose matching manifest_tree nodes are
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   909
            to be validated.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   910
        - There is no error handling for missing nodes.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   911
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   912
    - "validate exclude=" nodes have the following characteristics:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   913
        - "exclude" attribute: The name of a helper method to call to
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   914
            do the validation.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   915
        - The value of the node is a comma-separated list of one or
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   916
            more nodepaths, whose matching manifest_tree nodes are
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   917
            to be EXCLUDED from validation.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   918
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   919
    Args:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   920
      manifest_tree: The tree containing nodes to validate.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   921
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   922
      defval_tree: The tree containing "validate" nodes defined as above.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   923
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   924
      debug: When true, prints debug / tracing messages
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   925
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   926
    Returns: N/A
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   927
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   928
    Raises:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   929
      KeyError: A required attribute of a "validate" node is missing.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   930
      ManifestProcError: Error getting helper methods
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   931
      ManifestProcError: One or more validation errors found.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   932
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   933
    """
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   934
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   935
    group_validate = []
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   936
    singles_validate = []
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   937
    exclude_validate = []
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   938
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   939
    # Fetch dictionaries used to reference the helper methods, modules and
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   940
    # invert statuses.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   941
    try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   942
        validator_dicts = _HelperDicts.new(defval_tree, "helpers/validator")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   943
    except ManifestProcError, err:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   944
        print >> sys.stderr, ("validate_content: Error getting validator " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   945
                              "methods from defval XML file")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   946
        print >> sys.stderr, str(err)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   947
        raise
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   948
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   949
    # Fetch all "validate" nodes from the defval tree.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   950
    to_validate = defval_tree.find_node("validate")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   951
    if not to_validate:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   952
        return
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   953
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   954
    # Create separate lists of the different kinds of "validate" nodes.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   955
    for validateme in to_validate:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   956
        attributes = validateme.get_attr_dict()
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   957
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   958
        # Do specific nodes specified with "nodepath" attribute, for
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   959
        # this pass.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   960
        if ("nodepath" in attributes):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   961
            if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   962
                print ("Checking skip_if_no_exist for " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   963
                       "validate nodepath=" + attributes["nodepath"])
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   964
            if __do_skip_if_no_exist(attributes, manifest_tree, debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   965
                if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   966
                    print "Node doesn't exist.  Skipping..."
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   967
                continue
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   968
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   969
            singles_validate.append(validateme)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   970
            continue
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   971
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   972
        if ("group" in attributes):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   973
            group_validate.append(validateme)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   974
            continue
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   975
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   976
        if ("exclude" in attributes):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   977
            exclude_validate.append(validateme)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   978
            continue
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   979
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   980
        # Schema should protect from ever getting here...
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   981
        print >> sys.stderr, ("Nodepath, group or exclude attribute " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   982
                              "missing from \"validate\" entry")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   983
        raise
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   984
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   985
    if (len(singles_validate) > 0):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   986
        if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   987
            print "Processing singles validation"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   988
        __validate_singles(singles_validate, validator_dicts,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   989
                           manifest_tree, debug)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   990
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   991
    if (len(group_validate) > 0):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   992
        if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   993
            print "Processing group validation"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   994
        __validate_group(group_validate, validator_dicts,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   995
                         manifest_tree, debug)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
   996
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   997
    if (len(exclude_validate) > 0):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   998
        if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
   999
            print "Processing global validation"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1000
        __validate_exclude(exclude_validate, validator_dicts,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1001
                           manifest_tree, debug)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1002
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1003
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1004
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
  1005
def __validate_singles(to_validate, validator_dicts, manifest_tree, debug):
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1006
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1007
    """ Process a list of "validate nodepath=" nodes.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1008
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1009
    Args:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1010
      to_validate: List of items to validate.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1011
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1012
      validator_dicts: _HelperDicts object containing validator method
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1013
         information.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1014
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1015
      manifest_tree: Tree containing nodes to validate.
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
  1016
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1017
      debug: When true, prints debug / tracing messages
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1018
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1019
    Returns: N/A
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1020
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1021
    Raises:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1022
      ManifestProcError: One or more validation errors found.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1023
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1024
    """
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1025
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1026
    errors = False
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1027
    for validateme in to_validate:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1028
        attributes = validateme.get_attr_dict()
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1029
        manifest_nodepath = attributes["nodepath"]
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1030
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1031
        if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1032
            print "Validating node(s) at nodepath " + manifest_nodepath
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1033
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1034
        validator_list = space_parse(validateme.get_value())
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1035
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1036
        # Nodepaths which are direct children of the root are special cases
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1037
        try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1038
            (parent_nodepath, child_nodepath) = manifest_nodepath.rsplit("/",
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1039
                                                                         1)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1040
        except ValueError:	# No slashes present in nodepath
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1041
            parent_nodepath = ""
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1042
            child_nodepath = manifest_nodepath
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1043
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1044
        # Treat no "missing" attribute for this nodepath
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1045
        # as missing_parent = "error"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1046
        missing_handling = attributes.get("missing", "error")
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1047
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1048
        # Try to get the parent nodes which match the nodepath less the
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1049
        # final branch.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1050
        parent_nodes = manifest_tree.find_node(parent_nodepath)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1051
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1052
        # An ancestor somewhere in the chain back to the root is missing
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1053
        if (len(parent_nodes) == 0):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1054
            # If parent doesn't exist, the item sought can't either.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1055
            if (missing_handling == "error"):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1056
                print >> sys.stderr, ("validate_content: Parent for node at " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1057
                                      "nodepath " + manifest_nodepath +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1058
                                      " does not exist")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1059
                errors = True
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1060
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1061
            # Shouldn't get here if defaults / validation
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1062
            # manifest passed schema validation.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1063
            elif ((missing_handling != "ok") and
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1064
                  (missing_handling != "ok_if_no_parent")):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1065
                print >> sys.stderr, ("validate_content: Invalid " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1066
                                      "missing_handling attribute value " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1067
                                      "specified: " + missing_handling)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1068
                errors = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1069
            continue
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1070
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1071
        # Check each parent node for children.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1072
        for parent_node in parent_nodes:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1073
            if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1074
                print "  Processing new parent node"
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1075
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1076
            # Each parent must have at least one child
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1077
            # (element or attribute) which matches the nodepath to
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1078
            # validate, unless missing_handling = "ok".
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1079
            nodes = manifest_tree.find_node(child_nodepath, parent_node)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1080
            if (len(nodes) == 0):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1081
                if (missing_handling != "ok"):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1082
                    print >> sys.stderr, ("validate_content: node with " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1083
                                          "nodepath " + manifest_nodepath +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1084
                                          " does not exist")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1085
                    errors = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1086
                continue
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1087
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1088
            # At this point at least one node to validate exists
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1089
            # for each parent node.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1090
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1091
            # Loop through each child.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1092
            for node in nodes:
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1093
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1094
                # Call helper methods to do the validation.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1095
                for validator in validator_list:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1096
                    validator_ref = validator.strip()
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1097
                    try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1098
                        if (not __validate_node(validator_ref,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1099
                            validator_dicts, node, debug)):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1100
                            errors = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1101
                    except StandardError, err:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1102
                        print >> sys.stderr, ("Exception while validating " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1103
                                              "node " + node.get_path())
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1104
                        print >> sys.stderr, str(err)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1105
                        errors = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1106
    if errors:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1107
        raise ManifestProcError, ("validate_singles: One or more validation " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1108
                                  "errors found.")
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1109
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1110
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1111
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
  1112
def __validate_group(to_validate, validator_dicts, manifest_tree, debug):
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1113
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1114
    """ Process a list of "validate group=" nodes.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1115
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1116
    Args:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1117
      to_validate: List of items to validate.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1118
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1119
      validator_dicts: _HelperDicts object containing validator method
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1120
         information.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1121
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1122
      manifest_tree: Tree containing nodes to validate.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1123
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1124
      debug: Print tracing / debug messages when True
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
  1125
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1126
    Returns: N/A
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1127
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1128
    Raises:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1129
      ManifestProcError: One or more validation errors found.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1130
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1131
    """
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1132
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1133
    errors = False
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1134
    for validateme in to_validate:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1135
        attributes = validateme.get_attr_dict()
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1136
        validator_ref = attributes["group"].strip()
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1137
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1138
        if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1139
            print "  Processing group validated by " + validator_ref + "()"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1140
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1141
        # Get the list of nodepaths of nodes to validate as a string,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1142
        # then break into individual strings.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1143
        nodepaths = space_parse(validateme.get_value())
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1144
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1145
        for raw_nodepath in nodepaths:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1146
            nodepath = raw_nodepath.strip()
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1147
            if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1148
                print "  Validating nodes matching nodepath " + nodepath
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1149
            nodes = manifest_tree.find_node(nodepath)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1150
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1151
            if (len(nodes) == 0):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1152
                if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1153
                    print "    ... No matching nodes"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1154
                continue
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1155
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1156
            # Check each node.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1157
            for node in nodes:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1158
                value = node.get_value()
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1159
                if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1160
                    print "new_node: value = " + value
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1161
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1162
                try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1163
                    if (not __validate_node(validator_ref,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1164
                        validator_dicts, node, debug)):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1165
                        errors = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1166
                except StandardError, err:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1167
                    print >> sys.stderr, ("Exception while validating node " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1168
                                          node.get_path())
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1169
                    print >> sys.stderr, str(err)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1170
                    errors = True
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1171
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1172
    if errors:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1173
        raise ManifestProcError, ("validate_group: One or more validation " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1174
                                  "errors found.")
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1175
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1176
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1177
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
  1178
def __validate_exclude(to_exclude, validator_dicts, manifest_tree, debug):
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
  1179
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1180
    """ Process a list of "validate exclude=" nodes.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1181
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1182
    Args:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1183
      to_validate: List of items to validate.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1184
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1185
      validator_dicts: _HelperDicts object containing validator method
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1186
         information.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1187
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1188
      manifest_tree: Tree containing nodes to validate.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1189
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1190
      debug: Print tracing / debug messages when True
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
  1191
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1192
    Returns: N/A
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1193
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1194
    Raises:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1195
      ManifestProcError: One or more validation errors found.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1196
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1197
    """
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1198
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1199
    errors = False
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1200
    for excludeme in to_exclude:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1201
        attributes = excludeme.get_attr_dict()
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1202
        validator_ref = attributes["exclude"].strip()
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1203
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1204
        if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1205
            print ("  Processing unexcluded nodes validated by " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1206
                   validator_ref + "()")
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1207
        nodepaths = space_parse(excludeme.get_value())
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1208
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1209
        # For every node in the tree do
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1210
        walker = manifest_tree.get_tree_walker()
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1211
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1212
        # Get an element and its attributes as a list of nodes
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1213
        # (TreeAccNodes)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1214
        curr_list = manifest_tree.walk_tree(walker)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1215
        while (curr_list is not None):
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1216
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1217
            # Cycle through all returned nodes.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1218
            for node in curr_list:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1219
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1220
                if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1221
                    print "Checking current node: " + node.get_path()
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1222
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1223
                # Check through the list of nodepaths to be
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1224
                # inhibited.  Note if the path of the current
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1225
                # node is in the list.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1226
                inhibit = False
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1227
                for raw_nodepath in nodepaths:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1228
                    nodepath = raw_nodepath.strip()
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1229
                    if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1230
                        print "%s vs %s" % (nodepath, node.get_path())
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1231
                    if (nodepath == node.get_path()):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1232
                        inhibit = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1233
                        break
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1234
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1235
                if (not inhibit):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1236
                    if (debug):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1237
                        print "Not inbibited.  Checking node"
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1238
                    try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1239
                        if (not __validate_node(validator_ref,
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1240
                            validator_dicts, node, debug)):
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1241
                            errors = True
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1242
                    except StandardError, err:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1243
                        print >> sys.stderr, ("Exception while validating " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1244
                                              "node " + node.get_path())
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1245
                        print >> sys.stderr, str(err)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1246
                        errors = True
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1247
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1248
            curr_list = manifest_tree.walk_tree(walker)
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1249
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1250
    if errors:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1251
        raise ManifestProcError, ("validate_exclude: One or more validation " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1252
                                  "errors found.")
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1253
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1254
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1255
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
  1256
def init_defval_tree(defval_xml):
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1257
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1258
    """ Prepare the defaults / validation tree.  Must be called before any
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1259
        other method in this module.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1260
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1261
    Validates the default / validation manifest against its schema, then
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1262
    reads it in, and creates and returns the tree (in-memory representation)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1263
    used by other methods in this module.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1264
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1265
    Args:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1266
      defval_xml: Name of the Defaults and Content Validation XML spec.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1267
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1268
    Returns:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1269
      Tree of nodes (TreeAccNodes) that represents the defaults and
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1270
        validation requests specified in the
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1271
        default / validation manifest.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1272
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1273
    Raises:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1274
      ManifestProcError: Schema validation failed for default and content
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1275
        validation manifest.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1276
      ManifestProcError: Error creating tree for default and content
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1277
        validation manifest.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1278
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1279
    """
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1280
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1281
    # Validate XML file used for defaults and contents validation.
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1282
    try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1283
        schema_validate(DEFVAL_SCHEMA, defval_xml)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1284
    except StandardError, err:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1285
        print >> sys.stderr, ("init_defval_tree: Schema validation " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1286
                              "failed for default and content " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1287
                              "validation manifest:" + str(err))
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1288
        raise
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1289
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1290
    try:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1291
        defval_tree = TreeAcc(defval_xml)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1292
    except TreeAccError, err:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1293
        raise ManifestProcError, ("init_defval_tree: " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1294
                                  "Error creating tree for default " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1295
                                  "and content validation manifest " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1296
                                  defval_xml + ":" + str(err))
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1297
    return defval_tree
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1298
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1299
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1300
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
862
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
  1301
def schema_validate(schema_file, in_dc_manifest, out_dc_manifest=None,
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
  1302
                    dtd_schema=False):
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1303
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1304
    """ Validate a DC-manifest against its schema.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1305
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1306
    Args:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1307
      schema_file: Schema to validate the manifest against.
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
  1308
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1309
      in_dc_manifest: Manifest to validate against the MANIFEST_SCHEMA.
203
e6ded3a1e82f 3038 Augment finalizer to support multiple common script arguments
schwartz@strongheart
parents: 197
diff changeset
  1310
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1311
      out_dc_manifest: Name of reformatted file of in_dc_manifest.
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1312
862
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
  1313
      dtd_schema: Optional. Defaults to False.
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
  1314
        If True, validate against DTD Schema file.  If False, use RNG.
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
  1315
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1316
    Returns: N/A
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1317
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1318
    Raises:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1319
      ManifestProcError: Schema validation failed for DC manifest
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1320
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1321
    """
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
  1322
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1323
    try:
862
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
  1324
        __validate_vs_schema(schema_file, in_dc_manifest, out_dc_manifest,
e9f31f2f2f2d 16423 Updates to AI schema should be made
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 649
diff changeset
  1325
                             dtd_schema=dtd_schema)
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1326
    except StandardError, err:
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1327
        print >> sys.stderr, str(err)
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1328
        raise ManifestProcError, ("schema_validate: Schema validation " +
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
  1329
                                  "failed for DC manifest " + in_dc_manifest)