ó i'dWc@sêdZddlZddlZddlmZddlZddlZddlZddlm Z m Z ddl m Z m Z ddlmZddlmZddlmZmZd Zd efd „ƒYZd e fd „ƒYZdS(sManifestParser CheckpointiÿÿÿÿN(tetree(tcheck_file_for_security_datatSECURITY_XML_TAGS(t ParsingErrort DataObject(t InstallEngine(tAbstractCheckpoint(t ManifestErrortvalidate_manifesttmanifest_parser_datatManifestParsercBsneZdZdddeed„Zd„Zd„Zdd„Z ed„Z eed„Z e d„ƒZ RS( sÊ ManifestParser - parse, validate and import an XML manifest. Summary: This class implements the AbstractCheckpoint abstract base class which allows it to be executed from within the InstallEngine. It also provides an additional API that allow it to be run outside of the InstallEngine context. Initializer method: The parameters of the initializer method give the location of the XML manifest to be parsed and define what validation and other optional operations will be performed. execute() and parse() methods: When running in an InstallEngine context the execute() method performs the main tasks of parsing and, optionally, validating the manifest. When run outside the InstallEngine context, the parse() method performs these same functions. The main difference between execute() and parse() is whether or not the manifest data is imported into a DataObjectCache (DOC) instance and from where the reference to the DOC is obtained. execute() assumes an InstallEngine singleton exists and gets the DOC reference from it. With parse(), importing to the DOC is optional and if required, a reference to an existing DOC instance must be passed in. If an error occurs during the execute() or parse() methods, including XML syntax errors or failure to validate the manifest, a ManifestError exception is raised. If no errors occur, the methods simply return, with no return value. If importing to a DOC has been requested, the data will be available in the DOC for retrieval by other system components. Other public methods: The get_progress_estimate() method is required by the parent AbstractCheckpoint class. The cancel() method defined in AbstractCheckpoint is not overridden in ManifestParser. cCs˜tt|ƒj|ƒ|jjd|||||ƒ||_||_|dk rytj j |ƒ ryt d|ƒ‚n||_ ||_ ||_dS(s Class initializer method. Parameters: - name arg is required by AbstractCheckpoint. Not used. - manifest, if passed, must be the path to a readable XML file. The manifest value can be set when the object is instantiated by passing in a value for this param, or setting can be deferred until later by not passing in any value here. In this case, before the 1st attempt to access the manifest, there must be a valid manifest value stored in the DataObjectCache at the location specified by MANIFEST_PARSER_DATA. - validate_from_docinfo controls whether the manifest is validated against the DTD in the file's XML headers, if any. The default value is None. This parameter can have 3 values: None: validate against the DTD, if present; if DTD URI is not present, no error is raised True: attempt to validate against the DTD on-the-fly as it is loaded. If DTD is not specified, raise an error False: whether or not a DTD is specified, do not attempt to validate against it If validation is attempted and fails, an error is raised. - dtd_file specifes the path to a DTD against which the manifest will be validated. This validation may be performed instead of, or as well as, the validation controlled by validate_from_docinfo, or it may be skipped by leaving dtd_file as None (the default). If validation is attempted and fails, an error is raised. Note: default attribute values (see below) cannot be loaded during this form of validation - they can only be loaded if the manifest directly references a DTD in its headers. - load_defaults must be either True or False. The default value is True. load_defaults is only relevant when the manifest references a DTD. If True, default attribute values from the DTD are loaded when the manifest is parsed. If the manifest does not reference a DTD, no defaults are loaded and no error is raised. (Note: Defaults can be loaded even if validate_from_docinfo is False.) - call_xinclude must be either True or False and controls whether XInclude statements in the manifest will be processed or not. It defaults to False Note: Currently, the on-the-fly validation performed if validate_from_docinfo=True occurs *before* XInclude statements are processed and validation triggered when validate_from_docinfo=None or when dtd_file is specified occurs *after* XInclude processing. XInclude processing may affect whether validation succeeds or not, so this ordering may need to be considered. Returns: - Nothing Raises: - ManifestError is raised if invalid values are specified for any paramaters or if manifest and/or dtd_file are specified but are not actual files stInitializing ManifestParser (manifest=%s, validate_from_docinfo=%s, dtd_file=%s, load_defaults=%s, call_xinclude=%s)sDTD [%s] is not a fileN(tsuperR t__init__tloggertdebugt _manifestt_validate_from_docinfotNonetostpathtisfileRt _dtd_filet_load_defaultst_call_xinclude(tselftnametmanifesttvalidate_from_docinfotdtd_filet load_defaultst call_xinclude((s parser.pyR as<        cCsUd}tjƒj}|dk r9|jjdtƒ}n|dk rQ|j}n|S(sŽ Read the location of the manifest to be parsed from Data Object Cache from the element MANIFEST_PARSER_DATA. RN(RRt get_instancetdata_object_cachetvolatiletget_first_childtMANIFEST_PARSER_DATAR(Rt ret_manifesttdoctpm((s parser.pytget_manifest_from_doc·s   cCsdS(sÐ The parent class requires that this method be implemented in sub-classes. This returns an estimate of how long the execute() method will take to run. i((R((s parser.pytget_progress_estimateÉs cCs«|jjd|ƒ|jjƒr6|jjdƒdS|jjd|jƒ|jd|jd|jƒ}|jjƒr|jjdƒdS|jdkrÜ|jdk rÜ|jj dk rÜt ||jj |jƒqÜn|j dk rt ||j |jƒn|jjƒr'|jjdƒdS|dk r§y|j |j ƒdtƒWq§tk r£}d}|jj|ƒ|jjtjƒƒt|d |ƒ‚q§XndS( s This API method is not part of the AbstractCheckpoint spec. It can be used to access the ManifestParser functionality outside the InstallEngine context. This method is also used as a convenience function within this class to do most of the work of the execute() method. Parameters: - doc, a reference to the DataObjectCache in which to store the manifest data. If None, the manifest data will not be stored anywhere, in which case this method only serves to confirm whether the manifest can be parsed and, optionally, validated. Returns: - Nothing On success, this method returns; on error it raises an exception. Raises: - ManifestError is raised if an error occurs in _load_manifest() or validate_manifest() or if DataObjectCache.import_from_manifest_xml() raises a ParsingError exception. s#ManifestParser.parse(doc=%s) calledsCancel requested, returning.Ns$loading manifest (dtd_validation=%s)tdtd_validationtattribute_defaultsR!sUnable to import manifesttorig_exception(R Rt_cancel_requestedtis_setRt_load_manifestRRtdocinfot system_urlRRtimport_from_manifest_xmltgetroottTrueRt tracebackt format_excR(RR%ttreeterrortmsg((s parser.pytparseÔs8    cCsW|jjd|ƒtjƒ}|j}|dkrCtdƒ‚n|jd|ƒdS(s\ Abstract method defined in AbstractCheckpoint class. Loads the specified Manifest and does the requested validation. Imports resulting data into DOC. Parameters: - the dry_run keyword paramater, specified in AbstractCheckpoint, is ignored in this method. Returns: - Nothing On success, this method returns; on error it raises an exception. Raises: - ManifestError is raised if unable to fetch DOC reference or if an error occurs in parse(). s)ManifestParser.execute(dry_run=%s) calleds+Cannot get DOC reference from InstallEngineR%N(R RRRR RRR9(Rtdry_runtengineR%((s parser.pytexecutes    cCsWtjdtd|d|ƒ}ytj|j|ƒ}Wn¦tk r‹}d|j}|jj|ƒ|jj|ƒt|d|ƒ‚nUtj k rß}d|j}|jj|ƒ|jj|ƒt|d|ƒ‚nX|j rR|j ƒt j dƒ}xM|jƒjƒD]6}x-|jD]"} |j| ƒr%|j| =q%q%WqWn|jjtjƒrS|} t|jdd |ƒr(tj|ƒ} x‘g| jd d ƒD] } | ^qªD]g} | jd } xQtD]I}x@g| jd |ƒD] }|^qðD]}d | |f|_qWqÔWqºWn|jjdtj| dtddƒƒn|S(s4 Loads the manifest contained in property self.manifest. Parameters: - dtd_validation must be True or False. Default is False. If True, then the document will also be validated on-the-fly as it is loaded. - attribute_defaults must be True or False. Default is True. Only relevant if the manifest references a DTD. If True, then default values for XML attributes given in the DTD will be loaded as the document is parsed. Returns: - an etree.ElementTree object Raises: - ManifestError is raised if the manifest file cannot be accessed or if XMLSyntaxError is raised while parsing and, optionally, validating it. tremove_blank_textR)R*s Cannot access Manifest file [%s]R+s!XML syntax error in manifest [%s]s ^{.*}base$txmltxml_treettagt publisherRs%s in-lined %ssParsed XML document: %st pretty_printtmethod(Rt XMLParserR3R9RtIOErrorR t exceptionRtXMLSyntaxErrorRtxincludetretcompileR2titertattribtmatcht isEnabledFortloggingtDEBUGRtcopytdeepcopyRttextRttostring(RR)R*tparserR6R7R8t base_attribtelementt attrib_namet tree_to_printtptpubRAR@ttttmp((s parser.pyR.4sH      ,  ," cCsq|jdkr!|jƒ|_n|jdkr?tdƒ‚ntjj|jƒsjtd|jƒ‚n|jS(s¨ Instance accessor for the manifest to be parsed The use of a property here is to ensure _manifest has a valid value, either passed in as an argument to __init__() or via reading the DOC where the location to the manifest to be parsed is stored by another consumer. If manifest to be parsed is passed in as an __init__() argument then self._manifest will already be set, and there's not need to read the DOC. Constructor argument takes precedence over DOC. Raise ManifestError exception if manifest is not available or manifest file does not exist. sNo manifest specifiedsManifest [%s] is not a fileN(RRR'RRRR(R((s parser.pyR~sN(t__name__t __module__t__doc__RR3tFalseR R'R(R9R<R.tpropertyR(((s parser.pyR .s1U  B JtManifestParserDatacBsAeZdZdd„Zd„Zed„ƒZed„ƒZRS(sq Parser Manifest DataObject class for storage of manifest to be parsed in Data Object Cache. cCs#tt|ƒj|ƒ||_dS(s' Class constructor N(R RcR R(RRR((s parser.pyR ¡scCsdS(s3 Convert DataObject DOM to XML N(R(R((s parser.pytto_xml¨scCstS(sI can_handle notification method for ai_instance tags (Ra(tclsRW((s parser.pyt can_handle¯scCsdS(sE Convert from xml for DOM for DataObject storage N(R(ReRW((s parser.pytfrom_xml·sN( R^R_R`RR Rdt classmethodRfRg(((s parser.pyRcœs   (R`RQROtlxmlRRRIR4tsolaris_installRRtsolaris_install.data_objectRRtsolaris_install.engineRt!solaris_install.engine.checkpointRtsolaris_install.manifestRRR#R Rc(((s parser.pyts     ÿo