Ñò
ýÉªWc           @   s®   d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k l Z d  d k Z d  d k i	 i
 Z d d d „  ƒ  YZ d „  Z e d j o e ƒ  n d S(   iÿÿÿÿN(   t   pprintt   CheckVerc           B   sk   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   c         C   s	   d GHd  S(   Nt    (    (   t   self(    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/CheckVer.pyt   __init__   s    c         C   s^   t  i i d ƒ o t i d ƒ n d } x- | D]% } | d | d } t  i | ƒ q1 Wd  S(   Nt   opts	   rpm2cpio s   rpms/%ss    | cpio -idm --quiet(   t   ost   patht   existst   shutilt   rmtreet   system(   R   t   rpmst   RPMCMDt   rpmt
   extractRPM(    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/CheckVer.pyt   extractRpms   s     c         C   s    d } | | } t  i i | ƒ S(   Ns&   /opt/tandbergtv/cms/workflow/imported/(   R   R   t   isdir(   R   R   t	   workflows(    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/CheckVer.pyt   checkIfDirs'   s    
c         C   s0   t  d d } t i | | ƒ d  j o t St S(   Ns    - vs   \d+(   t   g_templateNamet   ret   matcht   Nonet   Truet   False(   R   t   templateNamet   reg(    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/CheckVer.pyt   templateFilter2   s    c         C   s˜   d } t  |  i t i | ƒ ƒ } | a t  |  i | ƒ } t | ƒ d j o d  S| i d t	 ƒ | i
 d ƒ } t i d | ƒ i d ƒ } t i | ƒ S(   Ns&   /opt/tandbergtv/cms/workflow/imported/i    t   reverses   (.+)(- v)(\d+)i   (   t   filterR   R   t   listdirR   R   t   lenR   t   sortR   t   popR   R   t   groupt   stringt   atoi(   R   R   R   t	   templatest   latestTemplatet   version(    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/CheckVer.pyt   getTemplateRunningVer>   s    c         C   s7   t  i | ƒ } | i ƒ  } | i d ƒ } t i | ƒ S(   NR(   (   t   ETt   parset   getroott   getR$   R%   (   R   t   plugint   treet   roott   pluginversion(    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/CheckVer.pyt
   getVersionU   s    c         C   sB   t  i | ƒ } | i ƒ  } | i d t | ƒ ƒ | i | ƒ d  S(   NR(   (   R*   R+   R,   t   sett   strt   write(   R   R.   R(   R/   R0   (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/CheckVer.pyt   setResourceVera   s    c         C   sC  d } t  ƒ  } t i | ƒ } d GH| GHd } t  ƒ  } x| D]ý } | d d !} | | } d | | d }	 t i i | ƒ p t i | ƒ n d | d } | |	 d | }
 t i |
 ƒ | | d | d	 } |  i | ƒ } |  i | ƒ } | d  j o3 | | j o" t
 | ƒ d
 t
 | ƒ | | <q;q> | d GHq> W| S(   Ns&   opt/tandbergtv/cms/workflow/templates/s"   Templates in the upgrade package: s
   unzip -oq i    iüÿÿÿs   "s    -d t   /s   .jpdlt   ,s    currently is not installed(   t   dictR   R   R   R   t   mkdirR   R2   R)   R   R4   (   R   t   basedirt   expectResourceVerR&   t   unzipCMDt   conflictTemplatest   templateR   t   tempalteFoldert   templatePart   CMDt   jpdlFilet   packageVersiont   runningVersion(    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/CheckVer.pyt   prepareTemplatesm   s2    		 
&c         C   s·   d } t  ƒ  } t i | ƒ } d GH| GHxˆ | D]€ } | | d } |  i | ƒ } t i i d | ƒ oF |  i d | ƒ } | | j o" t | ƒ d t | ƒ | | <q¯ q/ q/ W| S(   Ns/   opt/tandbergtv/cms/workflow/plugins/subsystems/s"   Resources in the upgrade package: s   /plugin.xmlR7   R8   (   R9   R   R   R2   R   R   R4   (   R   R;   t   conflictResourcest	   resourcest   resourcet
   pluginNamet
   packageVert
   runningVer(    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/CheckVer.pyt   prepareResources˜   s    	 *c         C   sj   d GHd } | i  ƒ  } xL | D]D } d | GH| | d } |  i | | | ƒ d t | | ƒ GHq Wd  S(   NR   s/   opt/tandbergtv/cms/workflow/plugins/subsystems/s   Installing resource: s   /plugin.xmls      -->updating plugin version to (   t   keysR6   R4   (   R   RH   R;   t   resourcesNameRI   RJ   (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/CheckVer.pyt   installRources²   s     	c         C   s‚  |  i  | ƒ |  i ƒ  } |  i ƒ  } t } t | ƒ oˆ t } d GHd GHd GH| i ƒ  } x[ | D]S } | | } | i d ƒ d } | i d ƒ d }	 d | d | d	 |	 d
 GHq` Wd GHn d GHt | ƒ oˆ t } d GHd GHd GH| i ƒ  }
 x[ |
 D]S } | | } | i d ƒ d } | i d ƒ d }	 d | d | d	 |	 d
 GHqú Wd GHn t i	 i
 d ƒ o t i d ƒ n | S(   Ns@   The following resources have lower verion than the running one: s?   ===============================================================s?   |    Resources         | Upgrade Version |   Running Version  |R8   i    i   s   | s             |      s         |      s         |R   s@   The following templates have lower verion than the running one: s@   ================================================================sA   |     Templates     |   Upgrade Version   |   Running Version   |s	     |      R   (   R   RM   RF   R   R    R   RN   t   splitR   R   R   R	   R
   (   R   R   RG   R>   t
   conflictedRH   RI   R(   t
   upgradeVerRL   R&   R?   (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/CheckVer.pyt   validateVersionsÉ   sD     
!	 
!	(   t   __name__t
   __module__R   R   R   R   R)   R2   R6   RF   RM   RP   RT   (    (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/CheckVer.pyR      s   								+		c          C   s&   d d g }  t  ƒ  } | i |  ƒ d  S(   Ns"   content-processing-workflows-*.rpms   envivio-adapter-*.rpm(   R   RT   (   R   t   checkVer(    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/CheckVer.pyt   main÷   s    	t   __main__(    (   R   t   syst   jsonR$   R	   R   R    t	   BaseClasst   xml.etree.ElementTreet   etreet   ElementTreeR*   R   RX   RU   (    (    (    sb   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/CheckVer.pyt   <module>   s   é	