MINI MINI MANI MO
ó
©=[c           @   sy   d  d l  j Z d d l m Z d  d l Z d  d l Z d  d l m Z m	 Z	 e j
 j ƒ  Z d e j
 f d „  ƒ  YZ d S(   iÿÿÿÿNi   (   t   base(   t   Popent   PIPEt   ScriptPluginc           B   sV   e  Z d  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 e
 d „ Z RS(   sO   
	Plugin for running custom scripts with profile activation and deactivation.
	c         C   s   i d  d 6S(   Nt   script(   t   None(   t   self(    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_script.pyt   _get_config_options   s    c         C   sa   t  | _ t | _ | j d d  k	 rT t | j d t ƒ sA t ‚ | j d | _	 n	 g  | _	 d  S(   NR   (
   t   Truet   _has_static_tuningt   Falset   _has_dynamic_tuningt   optionsR   t
   isinstancet   listt   AssertionErrort   _scripts(   R   t   instance(    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_script.pyt   _instance_init   s    		c         C   s   d  S(   N(    (   R   R   (    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_script.pyt   _instance_cleanup   s    c   	      C   sR  xK| D]C} t  j } | j |  j j ƒ  ƒ t j d | t | ƒ f ƒ t j d t t	 | j
 ƒ  ƒ ƒ ƒ yª t | g | d t d t d t
 d | d t
 d t  j j | ƒ ƒ} | j ƒ  \ } } t | ƒ rî t j d	 | | d
  f ƒ n  | j rt j d | | j f ƒ t SWq t t f k
 rI} t j d | | f ƒ t SXq Wt
 S(
   Ns'   calling script '%s' with arguments '%s's   using environment '%s't   stdoutt   stderrt	   close_fdst   envt   universal_newlinest   cwds   script '%s' error output: '%s'iÿÿÿÿs#   script '%s' returned error code: %ds   script '%s' error: %s(   t   ost   environt   updatet
   _variablest   get_envt   logt   infot   strt   debugR   t   itemsR   R   R   t   patht   dirnamet   communicatet   lent   errort
   returncodeR
   t   OSErrort   IOError(	   R   t   scriptst	   argumentsR   R   t   proct   outt   errt   e(    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_script.pyt
   _call_scripts!   s*    
	#		c         C   s0   t  t |  ƒ j | ƒ |  j | j d g ƒ d  S(   Nt   start(   t   superR   t   _instance_apply_staticR2   R   (   R   R   (    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_script.pyR5   8   s    c         C   s¥   t  } t t |  ƒ j | | ƒ t k r0 t } n  d g } | rO | d g 7} n  |  j | j | ƒ t  k r„ t j t	 j
 | j ƒ n t j t	 j | j ƒ t } | S(   Nt   verifyt   ignore_missing(
   R   R4   R   t   _instance_verify_staticR
   R2   R   R   R    t   constst   STR_VERIFY_PROFILE_OKR(   t   STR_VERIFY_PROFILE_FAIL(   R   R   R7   t   rett   args(    (    s?   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_script.pyR8   <