Ñò
ýÉªWc           @   s<   d  d k  i i Z d  d k l Z d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   ContentClassHandlert   ContentClassDifferc           B   sÂ   e  Z d  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z e d	 „  ƒ Z e d
 „  ƒ Z e d „  ƒ Z e d „  ƒ Z RS(   t   /c         C   sq   d } y t  i | d d d ƒ Wn. t j
 o" d GHt  i | d d d ƒ n Xt ƒ  } t i |  | | ƒ d S(   s%  
        contentClass
            |-attributes[]
            |-name
            |-description
            |-usage
            |-metadata
            |    |-attributes[]
            |    |-asset
            |        |-attributes[]
            |        |-fields[]
            |            |-attributes[]
            |            |-options[]
            |                |-option
            |                    |-displayName
            |                    |-value
            |-partners
                |-partner
                    |-name
        s   /tmp/contentClassTarget.xmli   t   admins   Retry compare content class...t	   admin1234N(   R    t
   exportByIdt	   Exceptiont   dictR   t   diffContentClassFiles(   t   srcContentClassFilet   targetContentClassFilet   result(    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/ContentClassDiffer.pyt   compareContentClasses   s    	c         C   s  t  } | d  j o t ƒ  } n t i |  ƒ } | i ƒ  } t i | ƒ } | i ƒ  } d } d }	 |	 | }
 d GHd GHd GHd |  GHd | GHd GHd GHd	 |
 GHd
 } t i | | | | ƒ x; | i ƒ  D]- \ } } d | GHd |
 | i	 d ƒ f GHqÉ Wd GH| o
 t
 } n | S(   Ni$   t    sn   ##############################################################################################################sn   #                                       Content Class Diff Report                                            #s   Source Content Class File: %ss   Target Content Class File: %ssn   --------------------------------------------------------------------------------------------------------------s   Tag Uris   %sDescriptiont    s   %ss   %s%ss   utf-8(   t   Falset   NoneR   t   ETt   parset   getrootR   t   diffContentClassElementt   itemst   encodet   True(   R	   R
   R   t	   differentt   srcContentClasst   srcRoott   targetContentClasst
   targetRoott   numberOfSpacet   spacet   indentt	   parentUrit   urit   description(    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/ContentClassDiffer.pyR   :   s8    
			 	
c         C   s  d } | d } d } |  i | i j o, d | | d |  i | d | i f GHn |  i d ƒ d j oP |  i d j o" | t i |  i d ƒ d } qÏ | t i |  i d ƒ } n | t i |  i } t i |  | | | ƒ t |  i ƒ  ƒ d j ou t | i ƒ  ƒ d j o\ |  i | i j oE | i	 h d	 t
 |  i ƒ d
 t
 | i ƒ d | t i d 6ƒ q‰n t i |  | | | ƒ d S(   sŠ  compare the element recursively 
        @param srcElement: The source element to compare
        @param targetElement: The target element to compare
        @param result: Where the compare result will be saved
        @param parentUri: The Uri of the parent of current compared element

        element
            |-tag
            |-attrib
            |-children
            |-text
        s       i	   sG   SoftwareError:%ssrcElement: %s and targetElement: %s are not comparableR   t   patht   fieldi   i    s   Value is different: src(s   ) vs target(t   )s   Value ModifiedN(   R   t   tagt   getR   t	   uriIndentt   diffElementAttributest   lent   getchildrent   textt   updatet   strt   diffElementChildren(   t
   srcElementt   targetElementR    R   t   tabR   t
   currentUri(    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/ContentClassDiffer.pyR   ^   s    
,"2Ic         C   sL  t  ƒ  } t i |  | | ƒ t  ƒ  } t i | | | ƒ | i ƒ  } | i ƒ  } t i | | ƒ \ } }	 }
 t i | | d | ƒ t i |	 | d | ƒ x® |
 D]¦ } | i d ƒ o, t i | i | ƒ | i | ƒ | | ƒ qž | i d ƒ o, t i	 | i | ƒ | i | ƒ | | ƒ qž t i
 | i | ƒ | i | ƒ | | ƒ qž Wd S(   s  compare the children element  
        @param srcElement: The source element to compare
        @param targetElement: The target element to compare
        @param result: Where the compare result will be saved
        @param currentUri: The Uri of current compared element
        s   New Children Founds   Children Not Founds   /optionss	   /partnersN(   R   R   t   getChildrenElementMapt   keyst   getDiffItemst   updateResultt   endswitht   diffOptionsTagR'   t   diffPartnersTagR   (   R0   R1   R   R3   t   srcElementChildrent   targetElementChildrent   srcElementChildrenKeyst   targetElementChildrenKeyst   new_childrent   deleted_childrent   share_childrent   item(    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/ContentClassDiffer.pyR/   ‡   s     			 ,,c         C   ss  | d j o t ƒ  } n xR|  i ƒ  D]D} | i d ƒ d j oP | i d j o" | t i | i d ƒ d } qW| t i | i d ƒ } nÅ | i d j oH | t i | i } t ƒ  } t i | | ƒ | i h | | 6ƒ q' n | i d j oH | t i | i } t	 ƒ  } t i
 | | ƒ | i h | | 6ƒ q' n | t i | i } | i h | | 6ƒ q' Wd S(   s   Get a map of <Uri, Child Element>
        @param parentElement: The element whose children will be elaborated into a map
        @param elementChildren:  The dict where the elaborated <Uri, Children Element> map will be saved
        @param currentUri: The Uri of current element
        R#   R$   i   t   optionst   partnersN(   R   R   R+   R'   R&   R   R(   t   getOptionsMapR-   t   listt   getPartnerList(   t   elementt   elementChildrenR3   t   cht   chUrit
   optionDictt   partnerList(    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/ContentClassDiffer.pyR4   ¦   s.     "		c   
      C   sä   |  i  ƒ  } | i  ƒ  } t i | | ƒ \ } } } t i | | d | ƒ t i | | d | ƒ x~ | D]v }	 |  i |	 ƒ | i |	 ƒ j oQ | i h d t |  i |	 ƒ ƒ d t | i |	 ƒ ƒ d | t i |	 6ƒ qf qf Wd S(   sV  Diff the attributes of the elements identified by the currentUri between soruce and target 
        @param srcElement: The source element to compare
        @param targetElement: The target element to compare
        @param result: Where the compare result will be saved
        @param currentUri: The Uri of current compared element
        s   New Attributes Founds   Attributes Not Founds"   attribute value is different: src(s   ) vs target(R%   N(   R5   R   R6   R7   R'   R-   R.   R(   (
   R0   R1   R   R3   t   srcAttributest   targetAttributest   new_attributest   deleted_attributest   share_attributesRB   (    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/ContentClassDiffer.pyR)   É   s     c         C   sŒ   x… | i  ƒ  D]w } d } d } xN | i  ƒ  D]@ } | i d j o | i } q, | i d j o | i } q, q, W|  i h | | 6ƒ q Wd S(   sÐ    Get the map of <displayName, value> of options
        @param optionDict: Where the map <displayName, value> will be saved
        @param element: The options element whose option will be retrieved 
        R   t   displayNamet   valueN(   R+   R&   R,   R-   (   t   optionsDictRH   RJ   RS   RT   t   grantCh(    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/ContentClassDiffer.pyRE   Ü   s      c   
      C   sä   |  i  ƒ  } | i  ƒ  } t i | | ƒ \ } } } t i | | d | ƒ t i | | d | ƒ x~ | D]v }	 |  i |	 ƒ | i |	 ƒ j oQ | i h d t |  i |	 ƒ ƒ d t | i |	 ƒ ƒ d | t i |	 6ƒ qf qf Wd S(   s*   Diff two options map <displayName, value>
        @param srcOptionDict: The source options map to compare
        @param targetOptionDict: The target options map to compare
        @param currentUri: The Uri used to save in the result
        @param result: The result where will be saved
        s   New Options Founds   Options Not Founds   option value is different: src(s   ) vs target(R%   N(   R5   R   R6   R7   R'   R-   R.   R(   (
   t   srcOptionDictt   targetOptionDictR3   R   t   srcDisplyNamest   targetDisplayNamest   new_optionst   deleted_optionst   share_optionsRB   (    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/ContentClassDiffer.pyR9   î   s     c         C   sb   x[ | i  ƒ  D]M } d } x1 | i  ƒ  D]# } | i d j o | i } q& q& W|  i | ƒ q Wd S(   sÎ    Get the lsit of <partner name> of partners
        @param partnerList: Where the partner name list will be saved
        @param element: The partners element whose partner names will be retrieved 
        R   t   nameN(   R+   R&   R,   t   append(   RM   RH   RJ   t   partnerNameRV   (    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/ContentClassDiffer.pyRG     s      c         C   sK   t  i |  | ƒ \ } } } t  i | | d | ƒ t  i | | d | ƒ d S(   s)   Diff two partner name list
        @param srcPartnerList: The source partner name list to compare
        @param targetPartnerList: The target partner name list to compare
        @param currentUri: The Uri used to save in the result
        @param result: The result where will be saved
        s   New Partners Founds   Partners Not FoundN(   R   R6   R7   (   t   srcPartnerListt   targetPartnerListR3   R   t   new_partnerst   deleted_partnerst   share_partner(    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/ContentClassDiffer.pyR:     s    c   	   	   C   s£   g  } | D] } | |  j o | | q q ~ } g  } |  D] } | | j o | | q= q= ~ } g  } |  D] } | | j o | | qo qo ~ } | | | f S(   s©   Get three diff item set new, deleted, shared items
        @param srcItems: The source items to compare
        @param targetItems: The target items to compare 
        (    (	   t   srcItemst   targetItemst   _[1]RB   t	   new_itemst   _[2]t   deleted_itemst   _[3]t   share_items(    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/ContentClassDiffer.pyR6     s    222c         C   sg   |  o\ d } x0 |  D]( } | d j o | n | d | } q W| i h | | t i | 6ƒ n d S(   s©  This method will be called to save the new or deleted items into the result
        @param items:  The new or deleted children items to be save into the diff result
        @param currentUri: Identify the element whose children items will be save into result
        @param indicatorMsg: Indicates New/Deleted items (Option, Attributes or general children items)
        @param result: The result where will be saved
        t   ,N(   R   R-   R   R(   (   R   R3   t   indicatorMsgR   t   descriptionStrRB   (    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/ContentClassDiffer.pyR7   )  s     &#(   t   __name__t
   __module__R(   t   staticmethodR   R   R   R/   R4   R)   RE   R9   RG   R:   R6   R7   (    (    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/ContentClassDiffer.pyR      s   #$)#(   t   xml.etree.ElementTreet   etreet   ElementTreeR   t   FileAssemblerR    t   objectR   (    (    (    sl   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/ContentClassDiffer.pyt   <module>   s   