ó
æ”\c           @   s   d  d l  m Z d d l Z d d l Z d d l Z d  d l Td d l Z d d l	 Td d l
 m Z e j j ƒ  Z d e j f d „  ƒ  YZ d S(   i   (   t   baseiÿÿÿÿN(   t   *(   t   commandst   SysfsPluginc           B   sb   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z	 d „  Z
 d „  Z d	 „  Z RS(
   sR   
	Plugin for applying custom sysfs options, using specific plugins is preferred.
	c         O   s2   t  t |  ƒ j | | Ž  t |  _ t ƒ  |  _ d  S(   N(   t   superR   t   __init__t   Truet   _has_dynamic_optionsR   t   _cmd(   t   selft   argst   kwargs(    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_sysfs.pyR      s    	c         C   sj   t  | _ t | _ t g  t | j j ƒ  ƒ D]& } t j	 j
 | d ƒ | d f ^ q+ ƒ | _ i  | _ d  S(   Ni    i   (   t   Falset   _has_dynamic_tuningR   t   _has_static_tuningt   dictt   listt   optionst   itemst   ost   patht   normpatht   _sysfst   _sysfs_original(   R	   t   instancet	   key_value(    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_sysfs.pyt   _instance_init   s    		Kc         C   s   d  S(   N(    (   R	   R   (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_sysfs.pyt   _instance_cleanup   s    c         C   sŸ   x˜ t  | j j ƒ  ƒ D] \ } } |  j j | ƒ } x` t j | ƒ D]O } |  j | ƒ r‚ |  j | ƒ | j	 | <|  j
 | | ƒ qD t j d | ƒ qD Wq Wd  S(   Ns)   rejecting write to '%s' (not inside /sys)(   R   R   R   t
   _variablest   expandt   globt   iglobt   _check_sysfst   _read_sysfsR   t   _write_sysfst   logt   error(   R	   R   t   keyt   valuet   vt   f(    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_sysfs.pyt   _instance_apply_static"   s    "c   
      C   s¤   t  } x— t | j j ƒ  ƒ D]€ \ } } |  j j | ƒ } x_ t j | ƒ D]N } |  j | ƒ rJ |  j	 | ƒ }	 |  j
 | | |	 | ƒ t k r˜ t } q˜ qJ qJ Wq W| S(   N(   R   R   R   R   R   R   R   R   R    R!   t   _verify_valueR   (
   R	   R   t   ignore_missingt   devicest   retR%   R&   R'   R(   t   curr_val(    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_sysfs.pyt   _instance_verify_static,   s    "c         C   s:   x3 t  | j j ƒ  ƒ D] \ } } |  j | | ƒ q Wd  S(   N(   R   R   R   R"   (   R	   R   t   full_rollbackR%   R&   (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_sysfs.pyt   _instance_unapply_static7   s    "c         C   s   t  j d | ƒ S(   Ns   ^/sys/.*(   t   ret   match(   R	   t
   sysfs_file(    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_sysfs.pyR    ;   s    c         C   sE   |  j  j | ƒ j ƒ  } t | ƒ d k r= |  j  j | t ƒ Sd  Sd  S(   Ni    (   R   t	   read_filet   stript   lent   get_active_optionR   t   None(   R	   R4   t   data(    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_sysfs.pyR!   >   s    c         C   s   |  j  j | | ƒ S(   N(   R   t   write_to_file(   R	   R4   R&   (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_sysfs.pyR"   E   s    (   t   __name__t
   __module__t   __doc__R   R   R   R)   R/   R   R1   R    R!   R"   (    (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_sysfs.pyR      s   				
			(   t    R    R   R2   t   os.pathR   t
   decoratorst
   tuned.logst   tunedt
   subprocesst   tuned.utils.commandsR   t   logst   getR#   t   PluginR   (    (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_sysfs.pyt   <module>   s   

