ó
Öà^c           @   sÛ   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z e a	 e a
 e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z e d
 k r× e e j d ƒ n  d S(   iÿÿÿÿNc         C   s§   | s t  r |  GH| r t Sn  t j |  ƒ } y% t j | d t j d t j ƒ} Wn! t k
 ru } t	 j
 | ƒ d  SX| j ƒ  d | j f } | d d k r£ d  S| S(   Nt   stderrt   stdouti    i   (   t   verboset   Truet   shlext   splitt
   subprocesst   Popent   STDOUTt   PIPEt	   Exceptiont   loggingt   criticalt   communicatet
   returncodet   None(   t   cmdt   drt   argst   outt   et   t(    (    s   lustrecfg.pyt   exec_local_cmd   s    c   	      C   ss  t  d |  ƒ } | s d  S| d j d ƒ } i  } x9| D]1} t j d d k r€ | j d d ƒ } t | ƒ d k rÀ q: qÀ n@ | j d d ƒ } t | ƒ d k s: t | d ƒ d k rÀ q: n  | d j ƒ  d  } | d j ƒ  } | d	 k r'| | k r'| j d
 d ƒ } | d | | | d <q: | d	 k ra| j d
 d ƒ } i | d | d 6| | <q: | | | <q: W| S(   Ns   modinfo i    s   
i   t   maxspliti   t    iÿÿÿÿt   parmt   :(   R   R   R   t   syst   version_infot   lent   strip(	   t   modulet   rct   infot   infodR   t   desct   keyt   valuet   tmp(    (    s   lustrecfg.pyt   grab_mod_info-   s.    	(c         C   s˜   t  j j |  ƒ s( d |  GHt d ƒ n  t  j j | ƒ rd t  j j | ƒ rd d | GHt d ƒ n  t |  d d | ƒ } | s” d GHt d ƒ n  d  S(   Ns   build script '%s' missingi   s   Lustre source '%s' missingR   s   -v -ss   failed to build lustre source(   t   ost   patht   isfilet   exitt   isdirR   (   t   scriptt   srcR    (    (    s   lustrecfg.pyt   build_lustreK   s    		c         C   s	   d GHd  S(   Ns-   This functionality is currently not supported(    (   t   params(    (    s   lustrecfg.pyt   config_lustreY   s    c         G   s1   t  } x$ | D] } |  | k r t } Pq q W| S(   N(   t   FalseR   (   R$   R%   t   listst   foundt   l(    (    s   lustrecfg.pyt   is_param_valid\   s    c   	      C   s(  t  } t  } t d ƒ } t d ƒ } t d ƒ } | sH d GHt d ƒ n  | s` d GHt d ƒ n  | sx d GHt d ƒ n  d |  k rÃ t } x6 |  d D]' } d	 | k s³ d
 | k r• d GHd  Sq• Wn  d |  k r$t } xL |  d D]= \ } } t | | | d | d | d ƒ sà d | GHd  Sqà Wn  d  S(   Nt   lnett   ksocklndt   ko2iblnds   lnet is not installedi   s   ksocklnd is not installeds   ko2iblnd is not installedt   netss   net typet
   interfacess   malformed lnet configurationt   tunablesR   s   unrecognized parameter: '%s'(   R2   R'   R+   R   R6   (	   R0   R:   R<   R7   t   socklndt   o2iblndR   t   kt   v(    (    s   lustrecfg.pyt   config_lnetf   s6    $	c         C   s9  t  j j |  ƒ s( d |  GHt d ƒ n  t |  d ƒ F } y t j | d t j ƒ} Wn  d  } d |  GHt d ƒ n XWd  QXd | k r¡ d |  GHt d ƒ n  y{| d d d	 k rTd
 | d k sØ d | d k rê d GHt d ƒ n  t	 | d d | d d
 ƒ d | d k r,t
 | d d ƒ n  d | d k rt | d d ƒ qnÇ | d d d k rŸd
 | d k rŠd GHt d ƒ n  t	 | d d
 ƒ n| | d d d k r d | d k rØt
 | d d ƒ n  d | d k rt | d d ƒ qn d | d d GHt d ƒ Wn d GHt d ƒ n Xd  S(   Ns   %s not foundi   t   rt   Loaders   couldn't parse %st   lustres   malformed configuration %st	   operationt   allt	   build_srct   build_scripts&   build source or script are not definedR7   t   builds   build source is not definedt   configs   operation '%s' not recognizeds   operation not defined(   R(   R)   R*   R+   t   opent   yamlt   loadt
   FullLoaderR   R/   RA   R1   (   RJ   t   ft   cfg_y(    (    s   lustrecfg.pyt   process_configŠ   sP    			c         C   s1  d } y+ t  j  |  d d d d d g ƒ \ } } Wn! t  j k
 rT t j d ƒ n Xt |  ƒ d k  r} d	 t GHt j ƒ  n  d } xu | D]m \ } } | d
 k r¸ d	 t GHt j ƒ  qŠ | d k rÍ | } qŠ | d k râ t a qŠ | d k rŠ t a qŠ qŠ Wt | ƒ d k r#d	 t GHt j ƒ  n  t	 | ƒ d  S(   Nt    s   hdvc:t   helpR   s   dry-runs   cfg=i   i   s5   python %s [--dry-run] --cfg=<YAML configuration file>s   -hs   -cs   --cfgs   -ds	   --dry-runs   -vs	   --verbosei    (   s   -cs   --cfg(   s   -ds	   --dry-run(   s   -vs	   --verbose(
   t   getoptt   GetoptErrorR   R+   R   t   __file__R   t   dry_runR   RQ   (   t   argvt	   intf_listt   optsR   RJ   t   optt   arg(    (    s   lustrecfg.pyt   main¸   s.    +					t   __main__i   (   R   R   R   R   RT   t   reR(   RL   R2   R   RW   R   R'   R/   R1   R6   RA   RQ   R]   t   __name__RX   (    (    (    s   lustrecfg.pyt   <module>   s   $0				
	$	.	 