ó i'dWc@s}dZddlZddlZddlmZddlmZmZeƒZ defd„ƒYZ defd„ƒYZ dS( sLMechanism for providing a central store of in-memory data in the installer. iÿÿÿÿN(tetree(tDataObjectBaset DataObjecttDataObjectCacheChildcBsPeZdZd„Zd„Zed„ƒZed„ƒZd„Zd„Z RS(svObject to represent the sub-trees of the DataObjectCache Doesn't generate any XML or import any XML it-self. cCstt|ƒj|ƒdS(s7Initialization function for DataObjectCacheChild class.N(tsuperRt__init__(tselftname((scache.pyR1scCs"x|jD]}|jƒq WdS(stRecursively deletes an object Override to avoid deletion of DataObjectCacheChildren object itself. N(t _childrentdelete(Rtchild((scache.pyR 5scCstS(s:Children of DataObjectCache don't have XML representation.(tFalse(tclstxml_node((scache.pyt can_handle=scCsdS(s:Children of DataObjectCache don't have XML representation.N(tNone(R R ((scache.pytfrom_xmlBscCsdS(s:Children of DataObjectCache don't have XML representation.N(R(R((scache.pytto_xmlGscCs d|jS(NsDataObjectCacheChild: %s(R(R((scache.pyt__repr__Ks( t__name__t __module__t__doc__RR t classmethodRRRR(((scache.pyR+s   tDataObjectCachecBsæeZdZdZdZd„Zed„ƒZed„ƒZd„Z ed„ƒZ d„Z d „Z e d d „ƒZe d „ƒZe d „ƒZe d„ƒZed„Zd„Zd„Ze d„ƒZe d„ƒZRS(s9Primary access class for the Data Object Cache infrastructure. Usually accessed by the Engine singleton, but may be used independently of the Engine. Provides the following functionality: - Has two sub-trees: - persistent - will be written to disk if snapshot mechanism is used, and is overwritten if snapshots are loaded. - volatile - exists only in-memory and is not effected by snapshot loading or written when a snapshot is taken. - Snapshot and Roll-back - It is possible to write out data from the 'persistent' sub-tree to a file or file-like object. - It is possible to roll-back the 'persistent' sub-tree to the contents of a provided file or file-like object. - XML Manifest Import and Generation - Drives the import of an XML manifest into a DataObject based tree - Drives the generation of XML suitable for conversion in to an XML manifest via XSLT. Sub-classes DataObjectBase to ensure that its not possible to add or remove the "persistent" and "volatile" children. Consumsers of the Data Object Cache should not insert/delete children to/from the DataObjectCache object, but instead should insert/delete them to/from the 'persistent' or 'volatile' sub-trees. tvolatilet persistentcCsktt|ƒjdƒttjƒ|_ttjƒ|_|j|jg|_||j_ ||j_ dS(s2Initialization function for DataObjectCache class.RN( RRRRtPERSISTENT_LABELt_persistent_treetVOLATILE_LABELt_volatile_treeRt_parent(R((scache.pyRxs cCs|jS(s&Returns the persistent tree child_node(R(R((scache.pyR‡scCs|jS(s$Returns the volatile tree child_node(R(R((scache.pyRŒscCs8x|jD]}|jƒq Wd}|jj|ƒdS(sDelete all objects from the sub-trees. This will delete all objects from cache, except for the root, persistent and volatile nodes. sDataObjectCache cleared!N(Rtdelete_childrentloggertinfo(RR tmsg((scache.pytclear”scCs|jj o|jj S(s§Returns True if the contents of the cache is deemed empty. Empty is defined as the sub-nodes, 'persistent' and 'volatile' having no children. (Rt has_childrenR(R((scache.pytis_empty¡s cCs{t}t|tƒr-t|dƒ}t}n$t|dƒrE|}n tdƒ‚tj|j |ƒ|rw|j ƒndS(sXTakes a snapshot of the 'persistent' sub-tree. This method writes the contents of the 'persistent' sub-tree to the destination provided by 'file_obj'. 'file_obj' may be one of the following: a string - this is used as the path of a file to open for writing. an object - this object is required to have a 'write(str)' method that takes a single string as a parameter. It can thus be an open file object, a StringIO object, or any other custom object that meets this interface. Exceptions: ValueError - This will be thrown if wrong type is passed for 'file_obj' IOError - This will be thrown if there is a problem opening the specified file_obj path string. twbtwritesq'file_obj' should be either a file path string or object with write(string) methodN( R t isinstancetstrtopentTruethasattrt ValueErrortpickletdumpRtclose(Rtfile_objt close_at_endtoutfile((scache.pyt take_snapshot«s   cCs¦t}t|tƒr-t|dƒ}t}n3t|dƒrTt|dƒrT|}n tdƒ‚tj|ƒ}|r‚|j ƒn|j j ƒ|j j |j ƒdS(sXLoad a snapshot in to the 'persistent' sub-tree. This method load the contents of the 'persistent' sub-tree from the provide file_obj parameter. 'file_obj' may be one of the following: a string - this is used as the path of a file to open for reading. an object - This is a file_obj-like object for reading a data stream. The file_obj-like object must have two methods, a read() method that takes an integer argument, and a readline() method that requires no arguments. Both methods should return a string. This file-like object can be a file object opened for reading, a StringIO object, or any other custom object that meets this interface. Exceptions: ValueError - This will be thrown if wrong type is passed for 'file_obj' IOError - This will be thrown if there is a problem opening the specified file_obj path string. trbtreadtreadlinesv'file_obj' should be either a file path string or object with read and readline methodsN(R R(R)R*R+R,R-R.tloadR0RRtinsert_childrentchildren(RR1R2tinfiletnew_cache_peristent_tree((scache.pytload_from_snapshotÕs      i2cCs[|dks|dkr+td|ƒ‚nyt|ƒ|}Wntk r[|g}nXxø|D]ð}tj|ƒrg}x]tj|tjƒD]F\}}tj|ƒ|kr»q”nt|t ƒr”|j |ƒq”q”Wt |ƒdkrSt j ||ƒqSqct|t ƒr1tj|gƒj |ƒqctdt|ƒttƒfƒ‚qcWdS(sýRegister a class with the DataObjectCache for importing XML. Registers sub-classes of DataObject, which are then used when importing XML to find classes that support the handling of XML snippets by calling the 'can_handle()' and 'from_xml()' methods. 'new_class_obj' may be either any of: - a single class object or module - an iterable object containing class objects and/or modules Modules to be registered should contain classes that are sub-classes of DataObjectBase. The priority defines the order in which classes are checked, with lower numbers being checked first - the default is for all registered classes to be at priority 50. Exceptions: TypeError - thrown if class_obj is not a sub-class of DataObjectBase, a Module, or an iterable object containing either of them. ValueError - thrown if priority is not in the range 0-100 inclusive. iidsInvald priority value %ds#Class '%s' is not a sub-class of %sN(R-titert TypeErrortinspecttismodulet getmemberstisclasst getmodulet issubclassRtappendtlenRtregister_classt_CACHE_CLASS_REGISTRYt setdefaultR)R(R t new_class_objtpriorityt class_listt class_reft to_registerRtvalue((scache.pyRH s.      cCs†ddg}xWttjƒƒD]C}|jd|ƒx)t|D]}|jdt|ƒƒqAWqW|jddgƒdj|ƒS(s=Generates a string of all registered classes to standard out.s============================sRegistered Classes:s[Priority = %d]s %sts (tsortedRItkeysRFtreprtextendtjoin(R t string_listtprio((scache.pytget_registered_classes_strLs cCsIxBttjƒƒD].}x%t|D]}|j|ƒr$|Sq$WqWdS(s;Find a class that handles a node in the known_classes list.N(RRRIRSRR(R tnodeRX((scache.pytfind_class_to_handleXs  cCsn|}|j|ƒ}|rI|j|ƒ}|rI|j|ƒ|}qInx|D]}|j||ƒqPWdS(s@Given an XML tree, generates the contents of the DataObjectCacheN(R[RR9t%_DataObjectCache__create_doc_from_xml(R tparentRZt new_parentt found_classtobjR ((scache.pyt__create_doc_from_xmlbs   cCs@|r|j}n |j}x|D]}tj||ƒq"WdS(s(Imports the provided XML tree into the Data Object cache By default, because 'volatile' is False, the XML will be imported into the DataObjectCache.persistent sub-tree. Otherwise, if 'volatile' is True, then the XML will be imported into the DataObjectCache.volatile sub-tree. Exceptions: ParsingError - Because from_xml() is used to import the XML, it is possible that there could be some bad XML which will result in this exception being thrown. N(RRRR\(Rt dom_root_nodeRt import_baseR ((scache.pytimport_from_manifest_xmlrs    cCs |jƒS(s&Generates XML from the DataObjectCache(t get_xml_tree(R((scache.pytgenerate_xml_manifest‹scCs tjdƒS(s.Return the 'root' node of the DataObjectCache.troot(RtElement(R((scache.pyRscCstS(s8The DataObjectCache class doesn't import any XML itself.(R (R R ((scache.pyR•scCsdS(s8The DataObjectCache class doesn't import any XML itself.N(R(R R ((scache.pyRšs(RRRRRRtpropertyRRR#R%R4R=RRHRYR[R\R RdRfRRR(((scache.pyROs($   * 4B     ( RR@R.tlxmlRtsolaris_install.data_objectRRtdictRIRR(((scache.pyts   $