ó i'dWc@s“dZddlZddlmZddlZddlZddlmZddlm Z ddl m Z m Z de fd„ƒYZ d „ZdS( sManifestWriter CheckpointiÿÿÿÿN(tetree(t InstallEngine(tAbstractCheckpoint(t ManifestErrortvalidate_manifesttManifestWritercBs>eZdZdedd„Zd„Zd„Zed„ZRS(sø ManifestWriter - export, transform and validate 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 created and define what transformation and validation will be performed. execute() and parse() methods: When running in an InstallEngine context the execute() method performs the main tasks of exporting and, optionally, transforming and validating the manifest. When run outside the InstallEngine context, the write() method performs these same functions. The main difference between execute() and write() is from where the DataObjectCache (DOC) reference is obtained. execute() assumes an InstallEngine singleton exists and gets the DOC reference from it. With write(), a reference to an existing DOC instance must be passed in. If an error occurs during the execute() or write() 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. The output manifest file will be created as requested. 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 rmtjj |ƒ rmt d|ƒ‚n||_ ||_ |dk r±tjj |ƒ r±t d|ƒ‚n||_ dS(s‰ Class initializer method. Parameters: - name arg is required by AbstractCheckpoint. Not used. - manifest must be the path to a writable XML file - xslt_file defaults to None. Otherwise, it must be the path to a readable XSLT file which will be applied to the manifest XML data to transform it into the required format. Typically, this is used to structure the data according to the AI or DC schema. - validate_from_docinfo defaults to False. It is only relevant if, following XSL Transformation, the XML document contains a reference to a DTD. This will typically have been added by the XSLT file. If validate_from_docinfo is True, the XML document will be validated against its referenced DTD, if present. If validation fails, an error is raised. If validate_from_docinfo is False or no DTD is referenced, this validation is skipped. - dtd_file defaults to None. Otherwise, it must be the path to a DTD file against which the manifest XML will be validated before it is written out. If validation is attempted and fails, an error is raised. This validation is separate from that controlled by validate_from_docinfo. Returns: - Nothing Raises: - ManifestError is raised if invalid values are specified for any paramaters or if xslt_file or dtd_file are specified but do not exist. s^Initializing ManifestWriter (manifest=%s, xslt_file=%s, validate_from_docinfo=%s, dtd_file=%s)sXSLT file [%s] is not a filesDTD [%s] is not a fileN(tsuperRt__init__tloggertdebugt _manifesttNonetostpathtisfileRt _xslt_filet_validate_from_docinfot _dtd_file(tselftnametmanifestt xslt_filetvalidate_from_docinfotdtd_file((s writer.pyRXs$       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 writer.pytget_progress_estimate”s c Cse|jjd|ƒ|jjƒr6|jjdƒdS|jƒ}tj|ƒ}|jjtj ƒr‹|jjdtj |dt ƒƒn|j dk rwytj|j ƒ}Wn¦tk r}d|j }|jj|ƒ|jj|ƒt|d|ƒ‚nUtjk rX}d|j }|jj|ƒ|jj|ƒt|d|ƒ‚nXtj|ƒ}||ƒ}n|jjƒrš|jjdƒdS|jrã|jdk rã|jjdk rãt||jj|jƒqãn|jdk r t||j|jƒntj |dt ƒ}|jjƒrC|jjdƒdS|jjd |ƒd} tjjtjj|jƒƒsÕy tjtjj|jƒƒWqÕtk rÑ}d |j}t|d|ƒ‚qÕXnzoy&t|jd d ƒ} | j |ƒWnBtk rB}d |j}|jj|ƒt|d|ƒ‚nXWd| dk r`| j!ƒnXdS(sM 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 instance from which to export the manifest data. Returns: - Nothing On success, this method returns; on error it raises an exception. Raises: ManifestError is raised if: - xslt_file cannot be read or is not a valid XSLT file - output file cannot be created or written to or if validate_manifest raises an error. s#ManifestWriter.write(doc=%s) calledsCancel requested, returning.NsXML returned from DOC: %s t pretty_printsCannot access XSLT file [%s]torig_exceptions"XML syntax error in XSLT file [%s]sAbout to write out: %s s)Cannot create directory for Manifest [%s]tmodetws$Cannot write to output Manifest [%s]("RR t_cancel_requestedtis_settgenerate_xml_manifestRt ElementTreet isEnabledFortloggingtDEBUGttostringtTrueRR tparsetIOErrort exceptionRtXMLSyntaxErrortXSLTRtdocinfot system_urlRRR R texiststdirnameR tmakedirstopentwritetclose( Rtdoctxmlttreetxslt_docterrortmsgt transformttextt manifest_file((s writer.pyR1Ÿsr     !    cCs„|jjd|ƒtjƒ}|j}|dkrCtdƒ‚n|rstjj |j ƒrst |j ƒ|_ n|j |ƒdS(s Abstract method defined in AbstractCheckpoint class. Exports data from InstallEngine's DataObjectCache to the file named in self._manifest. Parameters: - dry_run is used to control what actions are taken if self._manifest already exists. If dry_run is False, the file will be overwritten if it exists. if dry_run is True, the output will be written to a similarly-named, but non-existing file. 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 write(). s)ManifestWriter.execute(dry_run=%s) calleds+Cannot get DOC reference from InstallEngineN( RR Rt get_instancetdata_object_cacheR RR R R-R t_create_unique_variantR1(Rtdry_runtengineR3((s writer.pytexecutes   N( t__name__t __module__t__doc__R tFalseRRR1RA(((s writer.pyR(s .; dcCs‘tjj|ƒ\}}tjj|ƒ\}}tjd|d|dd|ƒ\}}ytj|ƒWn!tk rŒtd|ƒ‚nX|S(s÷ Create a variant of the passed-in filename, which does not already exist. This uses the tempfile module to create a file whose name is based on orig_filename but with some random letters and numbers inserted. tsuffixtprefixt_tdirsCould not close temp file [%s]( R R tsplittsplitextttempfiletmkstempR2R'R(t orig_filenameR.tfilenameRGRFt file_desct new_filename((s writer.pyR>(s( (RDR"tlxmlRR RLtsolaris_install.engineRt!solaris_install.engine.checkpointRtsolaris_install.manifestRRRR>(((s writer.pyts   ÿ