
ɪWc           @   s   d  d k  Z  d  d k Z d  d k l Z d  d k l Z d  d k l Z d  d k l Z d  d k l Z d  d k l Z d e f d	     YZ	 d
 e f d     YZ
 e d j o  e	   Z e i e i    n d S(   iN(   t   InstallComponent(   t   PrepackInstalledDecider(   t   InstallComponentBuilder(   t   InstallHelper(   t   ComponentSelectionConfig(   t   Commont   InstallComponentCollectorc           B   s+  e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z d  e
 g  d  Z d   Z d	   Z d
   Z d   Z e e
 d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z d   Z d   Z  d   Z! d   Z" d   Z# RS(!   s   component-selections.jsons   upgrade-components.jsonc         C   si   t    |  _ d  |  _ t i i |  i  o: t i	 t  i
 |  i   |  _ |  i i   i   |  _ n d  S(   N(   R   t   helpert   Nonet   decidert   ost   patht   existst   COMPONENT_SELECTION_CONFIGR   t   fromJsont   loadFromJsont   fullComponentSelectionConfigt   constructInstallComponentst   resolveLeavest   fullInstallComponents(   t   self(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyt   __init__   s
    	c         C   s   t  i   } |  i i   o t  i |  i i    } nR |  i   } | i   } | o | i | i	    } n |  i i
 | i   |  | S(   N(   R    t   createEmptyInstallComponentR   t   hasInstalledComponentst   fromJsonObjectt   loadInstalledComponentst   getPrepackInstalledDecidert   isAnyPrepackInstalledt#   getInstalledComponentsByPrepackNamet   getInstalledPrepackNamet*   saveNeccessaryInfoOnceLegacyPrepackDecidedt   toJsonObject(   R   t   installedComponentsR	   t   legacyPrepackInstalled(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyt   getInstalledComponents   s    c         C   s!   |  i  p t   |  _  n |  i  S(   N(   R	   R   (   R   (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR   #   s    
c         C   s  t  i   } | i   o | i   i   i |  i  } | i   i   i |  } |  i |  t i	 | |  i
  } t i   |  i d  t } xl | p` |  i | i | d t  d } t  i |  } t i   d GH|  i |  |  i i d  } q Wn | S(   NsC   You can remove the installed components if they are no longer used.s   Select %s to removei    s;   Please confirm your selection of components to be removed: sR   Type 'yes' to continue, type 'no' to reselect components to remove. Your input==> (   R    R   t   hasSubComponentExceptBaset   copyR   t	   substractR   t   printInstalledComponentsR   t   constructFromInstallComponentsR   R   t   printSeperateLinet   printSelectionInstructionst   Falset   promptForSelectiont   rootSelectiont!   createRootInstallComponentForListt   printInstallComponentsR   t   promptYesOrNo(   R   R    t   componentsToDeletet   installedDownsteamst   installedcomponentSelectiont
   toContinuet   componentList(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyt   getComponentsToDelete+   s$    
 
c         C   s   t  i   } |  i i   i |  } | i   o t i | |  i  } t	 i
   |  i d  t } x | p] |  i | i | d  d } t  i |  } t	 i
   d GH|  i |  |  i i d  } qf Wn t	 i
   |  i d  | S(   Ns.   Please select available components to install.s   Select %s to installi    s=   Please confirm your selection of components to be installed: sS   Type 'yes' to continue, type 'no' to reselect components to install. Your input==> s)   No other components available to install.(   R    R   R   R$   R%   R#   R   R'   R   R   R(   R)   R*   R+   R,   R-   R.   R   R/   (   R   R    t   componentsToInstallt   availableInstallComponentst   availableComponentSelectionR3   t   selectedComponents(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyt   getComponentsToInstallB   s$    
 

c         C   s  |  i    } t   i |  } t i   } t i   } t i   } | i d  o | i | i d   n t }	 |  i i	   oNt
 i   o@|  i i   }
 |
 d i d  } | o$ t d   |  } | |
 d d <n |
 d i d  } | o$ t d   |  } | |
 d d <n t i |
 d  } t i |
 d  } t i   | i   i   i |  } | i |  | i   i   i |  } | i |  d GH|  i | | |  |  i i d  } | }	 n | o t i |  } | i d  o) t d	   | i d   } | | d <n | i d  o) t d
   | i d   } | | d <n |  i | |  \ } } n | o) | o" |  i |  } |  i |  } n | i   i   i |  } | i d  } | oP | i   oC d GHd GHd GH|  i |  d GH|  i i d  } | p t Sn | i |  | i   i   i |  } | i |  | oD t i   d GH|  i | | |  |  i i d  } | p t Sn | i   p | i   n |  i | | | |	 f S(   Nt   DOWNSTREAMSt	   TO_DELETEt   subComponentsc         S   s   |  i  d   d j S(   t   componentNameR;   (   t   get(   t   x(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyt   <lambda>h   s    t
   TO_INSTALLc         S   s   |  i  d   d j S(   R>   R;   (   R?   (   R@   (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyRA   m   s    sr   The last installation failed with unexpected errors, however your selection have been saved, your last selections:s   Type 'yes' to continue with last selections, type 'no' to re-select components.
Please noted: To re-select components, system will roll back the partially installed components of your last selections before installing your new selections. Your input ==> c         S   s   |  i  d   S(   R;   (   t
   startswith(   R@   (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyRA      s    c         S   s   |  i  d   S(   R;   (   RC   (   R@   (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyRA      s    t    s^   Below downsteams are not licensed, System will remove the unlicensed downstremas automaticallysJ   Type 'yes' to continue, type 'no' to skip the installation. Your input==> s9   You have selected below components to remove or install: (    R"   R   t   buildInstallComponentsR    R   t   getInstallComponentByNamet   addSubComponentR*   R   t   hasTempSelectedComponentsR   t   isPatchModet   loadTempSelectedComponentsR?   t   filterR   R   R(   R$   R   R%   t   merget   printAllUserSelectionsR/   R   t!   loadSelectionFromPreConfigurationR5   R:   t   hasSubComponentR.   t   appendBaseComponentR   (   R   t   preConfiguredFilet   allowSelectt   licensed_downstreams_pathsR    t   licensedComponentsR0   R6   R1   t   reselectt   tempSelectedComponentst	   todeletest
   toinstallst   downsteamsToDeletet   downsteamToInstallt   preConfiguredSelectiont   to_installst   downstreamst   proceed(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyt   processToCollectAllSelectionsY   s    

	
	c         C   s:   h  } | i    | d <| i    | d <|  i i |  d S(   s   
            Save current user selection as temp, in case there is failure during the deployment, user would be allowed to rerun with the same selections again.
        RB   R<   N(   R   R   t   saveUserSelectionAsTemp(   R   R0   R6   t   saveSelections(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR`      s    c         C   s8   | i    i |  i |  } |  i i | i    d S(   sV   
            Save the current installed components after the deployment done.
        N(   R$   R%   RL   R   t   saveCurrentInstalledComponentsR   (   R   R    R0   R6   t   currentInstalledComponents(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyRb      s    c         C   s#  t    } t i   } t i   } | d } | d j o | i d  o, | i | d  i |  i  i |  } n | i d  o2 | i | d  i |  i  i |  i	   } qn` | i | d  } | i
   | i   i |  i  i |  } | i   i |  i  i |  } | | f S(   s   
            support two modes, DELTA mode should have install and delete items defined, FULL mode can have only install items defined, the items is all the user expect the system to have.
        t   modet   DELTARB   R<   (   R   R    R   t   has_keyRE   R   R   R%   t	   intersectt'   removeNonLeafComponentIfNoSubcomponentsRP   R$   (   R   R[   R    t   builderR0   R6   Rd   t   fullCurrentComponents(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyRN      s    	
,6
!!c         C   s   t  i | g  d  S(   N(   R   t   printHighlightMessage(   R   t   primaryMessage(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR)      s    c         C   s  g  } d } xo| D]g} | i |  }	 |	 oK| oC |  i | | g  \ }
 } | p t i   } n | i |
  n t |  } |	 i o d } x | d j o |  i |	 | | |  } |  i |  t	 t
 |	 i  d  j o d | f S|  i | |	  } |  i | | | t |  \ } } q Wx | D] } | i |  q0W| i   o | i |  qvqz| i |  q q W| | f S(   s:  
            prompt for selection recursively via the selection config.
            @param selectionItems            the    current selectionItems to handle, this is an array containing item names.
            @param componentSelectionConfig        the configuration that would be used to prompt selection
        i   N(   R   t   getSelectionConfigt-   getAvailableComponentsAndAutoSelectComponentsR    R   RL   t
   selectionst!   constructPromptMessageAndGetInputt   trimt   strt   lent   collectSelectItemsR+   t   TrueRG   RO   t   append(   R   t   selectionItemst   componentSelectionConfigt   selectMessaget   includeBackt   filterSelectionByDependencyt   installComponentst   allAvailalbeComponentst   selectionItemt   selectionConfigt   availableComponentst   autoSelectComponentst   installComponentRo   t	   userInputt   selectedItemst   childComponent(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR+      s8     
 )& c         C   s8  | | i  d } g  } d } xu | i D]j } | i |  }	 |	 o( |	 i o | i |  n |	 i  } n | t |  d | d } | d } q' W| o6 | t |  d |  i i   d } | i |  n t i	   | GHd }
 d } xD | d j p  |  i | t | i  |  o |  i i |
  } q W| S(   s  
            construct the prompt message with selections and get the value from user userInput.
            @param selectionConfig:    the current item to prompt for selection.
            @param componentSelectionConfig:    this full configuration that would be used to prompt selection.
            @param selectMessage            the customized message to prompt for selection.  
        s   :
i   s   . s   ; s   Enter the number of the item you want to select, and then press ENTER. For multiple items, separate them by spaces. For example: 1 3. If none of the components are needed, press ENTER directly. Your input ===>  N(   t   displayNameRo   Rm   t   singleSelectionRv   Rr   R   t   getBackDisplayNameR   t   printShortSeperateLineR   t   validateInputRs   R   t   getRawInput(   R   R   Rx   Ry   Rz   t   messaget   singleSelectioinIndexest   it	   selectiont   subSelectionConfigt   promptMessageR   (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyRp      s.    
 
%
 -c   
   	   C   s  g  } t  } x | i d  D] } |  i |  } | o d } y t |  } Wn t j
 o d | GHt  SX| | j o | i |  q | | d j p | d j o d | GHt  St } q q W| oC | o< d d i g  } | D] }	 | t |	  q ~  d GHt  St S(   Nt    i    s   [ERROR] Invalid index number: i   s1   [ERROR] You can not select other items when item s    or s    is selected. (	   R*   t   splitRq   t   intt
   ValueErrorRv   Ru   t   joinRr   (
   R   R   t   maxIndexR   t   singleSelectioinst   otherSelectedt   selectIndext   indext   _[1]t   a(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR     s,     		7c         C   s   g  } g  } xp | i  d  D]_ } |  i |  } | p q n | | j o/ | i | i t |  d  | i |  q q W| S(   NR   i   (   R   Rq   Rv   Ro   R   (   R   R   R   R   t   selectedIndexsR   (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyRt   -  s     c         C   sF   |  i  |  i i |  |  } |  i  |  i i |  |  } | | f S(   N(   t!   filterByCurerntAvailableSelectionR   t+   collectAutoSelectComponentsForSelectedItemst5   collectAvailableComponentsExcludeAutoSelectComponents(   R   Rx   R   t   allAutoSelectComponentst-   availableInstallComponentsExcludeAutoSelected(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyRn   :  s    c         C   s/   | i    } | i |  i  i |  i   | S(   N(   R   R   R   Rg   Rh   (   R   t
   componentst   currentSelectionConfigt   currentAvailableComponents(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR   ?  s    c         C   s$   |  i  | |  |  i | |  | S(   N(   t   resolveSingleSelectiont   resolveAvaliableComponents(   R   R    R7   (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyt*   resolveAvailalbeComponentsWithDependenciesD  s    c         C   s   x | i    D] } |  i i | i  } | oh | i o | o g  | _ qi n | o |  i |  n |  i | | o | i | i  n d   q q W| o | i
   n d  S(   N(   t   getSubComponentsR   Rm   R>   R   R=   t   removeSingleSelectionComponentsR   RF   R   Rh   (   R   R    R7   t   installedComponentR   (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR   I  s     
2c         C   sv   xo t  t d t | i      D]L } | i   | } |  i i | i  } | i o | i   i |  q" q" Wd  S(   Ni    (	   t   reversedt   rangeRs   R   R   Rm   R>   R   t   remove(   R   R7   R   t   subComponentR   (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR   W  s    " 
c         C   s   d  } x | i   D] } |  i i | i  } | o^ | i p
 | i o4 | p t i   } n | i	 |  i i
 |   n |  i | |  } q q W| o  | i |  i  i |  i   S| Sd  S(   N(   R   R   R   Rm   R>   R   t   unAvailableComponentsR    R   RL   t   _collectAvailableComponentsR   R   R   Rg   Rh   (   R   R    R7   t)   availableComponentsForInstalledComponentsR   R   (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR   ^  s      c         C   s   | i  d  S(   Ns   
	 (   t   strip(   R   t   string(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyRq   m  s    c         C   s    t  i   d GH|  i |  d S(   s{   
        print the installed components
        @param installedComponents:        installedComponents json file. 
        s7   Below Components has been installed on current system: N(   R   R(   R.   (   R   R    (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR&   p  s    
c         C   s   t  i d  |  i |  d GHt  i d  |  i |  d GHt  i d  |  i | i   i |  i  i |   d GHt  i d  |  i | i   i |  i  i |  i |   d GHt  i   d  S(   Ns   Components to delete: RD   s   Components to install: s   Components to keeps:   After the installation, system will have below components:(	   R   Rk   R.   R$   R   R   R%   RL   R(   (   R   R0   R6   R    (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyRM   y  s    (1RD   c         C   s   | i    o | i   o	 d GHn | i    o7 | i   o) | d } | |  i i | i  i GHn x$ | i   D] } |  i | |  qv Wd  S(   Ns       No Component is selecteds   --|-(	   t   isRootRO   t   isBaseR   Rm   R>   R   R   R.   (   R   R   t   intentR   (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR.     s    	
 c         C   sN   t  i | |  |  i } t i i |  o |  i |  S|  i | |  Sd S(   s   
            decide all upgrade components in current upgrade folder. either by looping the folder structure or have an config file for it.
        N(   t   ComponentPathBuildert   getComponentsPathPrefixt   UPGRADE_COMPONENTS_FILE_NAMER
   R   R   t(   collectAllUpgradeComponentsViaConfigFilet)   collectAllUpgradeComponentsViaDirectories(   R   t
   pathPrefixt   upgradePatht   upgradeComponentsFilePath(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyt   collectAllUpgradeComponents  s    c         C   s   t  i |  } t   i |  S(   N(   R   R   R   RE   (   R   R   t   upgradeComponents(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR     s    c         C   s6   |  i  |  i   | |  } | p t i   } n | S(   N(   t2   collectAllUpgradeComponentsViaDirectoryRecursivelyR"   R    R   (   R   R   R   t   availableUpgradeComponents(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR     s    c         C   s   t  | i  } | i   oH xE | i   D]3 } |  i | | |  } | o | i |  q) q) Wn | i   o |  i | | |  o d  S| Sd  S(   N(   R    R>   RO   R   R   RG   t   checkComponentExistsR   (   R   R   R   R   t   availableUpgradeComponentt   subInstallComponentt   availableSubUpgradeComponent(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR     s     %c         C   s*   t  i i t i | |  | i   d  S(   Ns   config.json(   R
   R   R   R   R   t   getConfigLocation(   R   R   R   t	   component(    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR     s    N($   t   __name__t
   __module__R   R   R   R"   R   R5   R:   R   Ru   R_   R`   Rb   RN   R)   R*   R+   Rp   R   Rt   Rn   R   R   R   R   R   Rq   R&   RM   R.   R   R   R   R   R   (    (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR   
   s>   					P					"															
			R   c           B   s   e  Z d  Z e d    Z RS(   R   c         C   sL   |  o |  t  i }  n d }  | o |  | t  i }  n |  t i t  i S(   NRD   (   R
   t   sepR   t   COMPONENTS_FOLDER(   R   R   (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR     s    (   R   R   R   t   staticmethodR   (    (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyR     s   t   __main__(   R
   R$   R    R   R   R   R   R   t   objectR   R   R   t	   collectorR.   R"   (    (    (    ss   /home/jenkins/workspace/prepack-aio-release-4.2/prepack-aio/src/main/resources/scripts/InstallComponentCollector.pyt   <module>   s    	