Ñò
ýÉªWc        
   @   s¡   d  d k  Z  d  d k Z d  d k Z d  d k l Z d  d k l Z d  d k i i Z d  d k l Z d e	 f d „  ƒ  YZ
 d „  Z e d j o e ƒ  n d S(	   iÿÿÿÿN(   t   MeSubsProfile(   t   Rulesets(   t   ElementTreet   EnhancementRulesetc           B   sY   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   c         C   s   d  S(   N(    (   t   self(    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/EnhancementRuleset.pyt   __init__   s    c         C   sƒ   t  } xv | i d ƒ D]e } | i d ƒ } | i d ƒ } | o: | o3 | d i d j o | d i d j o t } Pq q W| S(   Ns&   rules/rule/actions/action/params/paramt   namet   valuei    t	   fieldTypet   ENHANCEMENT(   t   Falset   findallt   textt   True(   R   t   ruleSett   isMeRulesett   paramt   nameElementt   valueElement(    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/EnhancementRuleset.pyt    __isMetadataEnhancementRuleset__   s     "	c         C   sx   t  i i | ƒ p g  St i | ƒ } | i ƒ  } g  } x8 | i d ƒ D]' } |  i | ƒ o | i | ƒ qI qI W| S(   Ns   ruleSets/ruleSet(	   t   ost   patht   existst   ETt   parset   getrootR   R   t   append(   R   t   filePatht   treet   roott   ruleSetsR   (    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/EnhancementRuleset.pyt"   __getMetadataEnhancementRulesets__    s     c         C   sQ   | i  ƒ  } g  } x8 | i d ƒ D]' } |  i | ƒ o | i | ƒ q" q" W| S(   Ns   ruleSets/ruleSet(   R   R   R   R   (   R   R   R   R   R   (    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/EnhancementRuleset.pyt(   __getMetadataEnhancementRulesetsInTree__.   s     c         C   sd   |  i  | ƒ } g  } xH | D]@ } | i d ƒ } | d j	 o | i o | i | i ƒ q q W| S(   sž   
 	 	Description: find the uuids of the me rule set in the specified xml
 	 	
 	 	@param filePath: the rule set xml which may contains multiple rule sets
 	 	t   uuidN(   R   t   findt   NoneR   R   (   R   R   t
   meRuleSetst   uuidsR   t   uuidElement(    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/EnhancementRuleset.pyt   __getUuidOfMeRulesets__8   s     c         C   sf   t  i i | ƒ p t St i | ƒ } | i ƒ  } x, | i d ƒ D] } |  i | ƒ o t	 SqC Wd  S(   Ns   ruleSets/ruleSet(
   R   R   R   R
   R   R   R   R   R   R   (   R   R   R   R   R   (    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/EnhancementRuleset.pyt   hasMetadataEnhancementRulesetH   s     c   	      C   s‰   d } |  i  | ƒ } t | ƒ oc t t i | ƒ ƒ } | i ƒ  } | i d ƒ } x | D] } | i | ƒ qY W| i | d ƒ t	 St
 S(   sŸ   
		Description: extract the ME ruleset from the xml file and save to a new file.
					
		@param xmlPathOfRuleset: the xml file which contains many rule sets
		so   <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ruleSetsListing><ruleSets></ruleSets></ruleSetsListing>R   s   UTF-8(   R   t   lenR   R   t
   fromstringR   R"   R   t   writeR   R
   (	   R   t   xmlPathOfRulesett
   newXmlPatht   xmlTemplateStringt
   meRulesetsR   R   t   rulesetsElementt   ruleset(    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/EnhancementRuleset.pyt!   extractMetadataEnhancementRulesetS   s     c         C   s©  t  i i | ƒ p t St i | ƒ } | i ƒ  } t ƒ  } t } xE|  i | ƒ D]4} x+| i	 d ƒ D]} | i
 d ƒ } | d j	 oø t }	 xï | i	 d ƒ D]Ú }
 |
 i	 d ƒ } |
 i	 d ƒ } | o9 | o2 | d i d j o | d i d j o
 t }	 n | oo | oh | d i d	 j oT |	 oM | d i } | i t | ƒ ƒ } | o | | d _ t } qzd
 | GHq  q  Wqh qh WqR W| o | i | d ƒ n d S(   sh   
 		Description:
 			Replace all the profile ids in the @filePath with the actual 
 			profile name.
 		s   rules/rule/actions/actiont   paramsR   R   R   i    R   R	   t   sectionTypesG   [Warning]EnhancementRuleset:replaceWithProfileName: unknown profile Id s   UTF-8N(   R   R   R   R
   R   R   R   R    R    R   R"   R#   R   R   t   getProfileNameByIdt   intR+   (   R   R   R   R   t	   meProfilet   changedR   t   actionR3   t   isMetaDataEnhancementR   R   R   t	   profileIdt   profileName(    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/EnhancementRuleset.pyt   replaceWithProfileNamek   s<    	   "
"
c         C   s©  t  i i | ƒ p t St i | ƒ } | i ƒ  } t ƒ  } t } xE|  i | ƒ D]4} x+| i	 d ƒ D]} | i
 d ƒ } | d j	 oø t }	 xï | i	 d ƒ D]Ú }
 |
 i	 d ƒ } |
 i	 d ƒ } | o9 | o2 | d i d j o | d i d j o
 t }	 n | oo | oh | d i d	 j oT |	 oM | d i } | i | ƒ } | o t | ƒ | d _ t } qzd
 | GHq  q  Wqh qh WqR W| o | i | d ƒ n d S(   sh   
 		Description:
 			Replace all the profile names in the @filePath with the actual 
 			profile id.
 		s   rules/rule/actions/actionR3   R   R   R   i    R   R	   R4   sG   [Warning]EnhancementRuleset:replaceWithProfileId: unknown profile name s   UTF-8N(   R   R   R   R
   R   R   R   R    R    R   R"   R#   R   R   t   getProfileIdByNamet   strR+   (   R   R   R   R   R7   R8   R   R9   R3   R:   R   R   R   R<   R;   (    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/EnhancementRuleset.pyt   replaceWithProfileId–   s<    	   "
"
(   t   __name__t
   __module__R   R   R   R    R'   R(   R2   R=   R@   (    (    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/EnhancementRuleset.pyR      s   				
				+c          C   s9   t  ƒ  }  |  i d ƒ GH|  i d ƒ GH|  i d d ƒ d  S(   Ns'   C:\Users\elichon\Desktop\MD_RuleSet.xmls'   C:\Users\elichon\Desktop\ME_Ruleset.xml(   R   R(   R'   R2   (   t   enhance(    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/EnhancementRuleset.pyt   mainÁ   s    	t   __main__(   t   reR   t   xmlR    R   t   xml.etree.ElementTreet   etreeR   R   t   objectR   RD   RA   (    (    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/EnhancementRuleset.pyt   <module>   s   µ	