Ñò
ýÉª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 l Z d e  i  f d „  ƒ  YZ d „  Z e	 d j o e ƒ  n d S(	   iÿÿÿÿN(   t   ElementTree(   t   HttpRequestDecorator(   t   CMSVersionDeploymentPolicyt   Rulesetsc           B   s˜   e  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d „  Z e e d d d „ ƒ Z RS(   s?   https://localhost:8443/rulesservices/restful-services/rulesutilt   adminc         C   sQ   t  i  i |  ƒ | |  _ | |  _ d |  _ d |  _ |  i ƒ  |  i d 7_ d  S(   Nt   RULENAMEt   TRE_RULESETs    WHERE ENABLED=1(   t	   BaseClasst   __init__t   usernamet   passwordt   columnst   tablet   setSelectStatementt   selectStatement(   t   selfR	   R
   (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyR      s    				
c         C   sO   | d } |  i  i d | ƒ |  i  i ƒ  } t | ƒ o | d d St Sd  S(   Ni    s5   SELECT RULESETID FROM TRE_RULESET WHERE RULENAME='%s'(   t   cursort   executet   fetchallt   lent   False(   R   t   datat   ruleNamet   rows(    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyt   checkExistence   s    
c         C   s<   |  i  i d ƒ y |  i  i ƒ  d d d SWn d SXd  S(   Ns&   SELECT MAX(RULESETID) FROM TRE_RULESETi    i   (   R   R   R   (   R   (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyt	   getNextId!   s
    c         C   se   |  i  | ƒ t Sy) d } | GH|  i i | ƒ |  i ƒ  Wn$ t j
 o } | GH|  i ƒ  n Xd  S(   Nt    (   t   enableR   R   R   t   committ	   Exceptiont   rollback(   R   t   id_R   t	   statementt   e(    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyt   insert(   s    c         C   sO   | d } y- d | } | GH|  i  i | ƒ |  i ƒ  Wn |  i ƒ  n Xd  S(   Ni    s4   UPDATE TRE_RULESET SET ENABLED=1 WHERE RULENAME='%s'(   R   R   R   R   (   R   R   R   R    (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyR   6   s    

c         C   sw   t  | d ƒ i ƒ  d } xW | D]O } t d „  t d | i d ƒ ƒ ƒ } t d „  | ƒ } |  i t | ƒ ƒ q  Wd S(   s\   
		tdf=Tab Delimited File
		First line, which has the header for the columns, is ignored.
		t   ri   c         S   s
   |  i  ƒ  S(    (   t   strip(   t   s(    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyt   <lambda>H   s    s   	c         S   s   d  |  g |  d j S(   R   t   null(    (   R%   (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyR&   I   s    N(   t   filet	   readlinest   mapt   filtert   Nonet   splitR   t   tuple(   R   t   tdft   linest   linet   fields(    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyt   importFromFileA   s     $c         G   s]   |  i  d |  i d |  i } t i | d ƒ } | d d d j o | GHt d ƒ n d  S(   Ns   /deleteallrulesets/?username=s
   &password=t   POSTi    t   statust   200i   (   t   RULE_SERVICE_LOCATIONR	   R
   R   t   requestt   exit(   R   R   t
   requestUrlt   resp(    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyt   deleteM   s    c         C   sA   t  } | o0 x- | D]! } |  i | ƒ } | p Pq q Wn | S(   s€   
		This method is intend to delete the ruleSet specified by the uuids
			uuids: an array containing all the uuids of rulesets
		(   t   Truet   deleteByuuid(   R   t   uuidst   successt   uuid(    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyt   deleteRulSetsByUuidW   s     c         C   sb   |  i  d |  i d |  i d | } t i | d d  d  ƒ } | d d d j o
 | GHt St S(   Ns   /deleterulesets/?username=s
   &password=s   &ruleSetIds=%sR4   i    R5   R6   (   R7   R	   R
   R   R8   R,   R   R=   (   R   t   idt   urlR;   (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyt
   deleteByIdf   s    'c         C   sb   |  i  d |  i d |  i d | } t i | d d  d  ƒ } | d d d j o
 | GHt St S(   Ns   /deleterulesetbyuuid/?username=s
   &password=s   &uuid=%sR4   i    R5   R6   (   R7   R	   R
   R   R8   R,   R   R=   (   R   RA   RD   R;   (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyR>   n   s    'c         C   sn   t  ƒ  } | i | ƒ | i ƒ  i d ƒ i d ƒ } g  } x- | D]% } | i d ƒ i } | i | ƒ qA W| S(   sh   
		This method is intend to delete the ruleset by the UUID
			path: the file path of the ruleset xml 
		t   ruleSetst   ruleSetRA   (   R    t   parset   getroott   findt   getiteratort   textt   append(   R   t   patht   treeRF   t   uuIdsRG   RA   (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyt   getUuidsFromXmlv   s    	 c         C   s…   | oz t  i d } h d d 6} d |  i |  i d i | ƒ f } t i | d | d | ƒ} | d d	 d
 j o
 | GHt Sn t S(   Ns   /sortrulesetss!   application/x-www-form-urlencodeds   content-types    username=%s&password=%s&uuids=%st   ,R4   t   headersi    R5   R6   (	   R   R7   R	   R
   t   joinR   R8   R   R=   (   R   R?   R:   t   headert	   form_dataR;   (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyt   sortByUuids†   s    "	i   i<   c         C   sµ   | } x• |  o | d j o€ yO t  i t i d d ƒ } | d d d j o
 d GHt Sd t | ƒ d GHWn t j
 o n Xt i | ƒ | | } q	 Wd	 t | ƒ d
 GHt	 S(   Ni    s   /deleterulesetbyuuidt   GETR5   t   405s   Rule Service is ups%   Rule Service is not up yet, wait for s    seconds to check again.s#   Rule Service is still not up after s#    seconds. Please check the network.(
   R   R8   R   R7   R=   t   strR   t   timet   sleepR   (   t	   waitForUpt   intervalt   timeoutt
   timeToWaitR;   (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyt    checkAndWaitRullServiceAvailable‘   s     (   t   __name__t
   __module__R7   R   R   R   R"   R   R3   R<   RB   RE   R>   RQ   RW   t   staticmethodR=   Ra   (    (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyR   	   s   							
					c           C   s   d t  _ t  i ƒ  d  S(   NsA   https://10.116.5.99:8443/rulesservices/restful-services/rulesutil(   R   R7   Ra   (    (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyt   main£   s    	t   __main__(
   R   R[   t   base64t   xml.etree.ElementTreeR    R   R   R   Re   Rb   (    (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/Rulesets.pyt   <module>   s   š	