ó
æ”\c           @   sz   d  d l  m Z d  d l Td d l Z d d l m Z d d l Z d d l Z e j	 j
 ƒ  Z d e j f d „  ƒ  YZ d S(   i   (   t   base(   t   *iÿÿÿÿN(   t   commandst   VideoPluginc           B   s}   e  Z d  Z d „  Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z	 e
 d d e ƒd	 „  ƒ Z e d ƒ e d
 „ ƒ Z RS(   s?   
	Plugin for tuning powersave options for some graphic cards.
	c         C   sv   t  |  _ t ƒ  |  _ t ƒ  |  _ xB |  j j d ƒ j d ƒ j d d ƒ D] } |  j j	 | j
 ƒ qI Wt ƒ  |  _ d  S(   Nt   drms   card*t   DEVTYPEt	   drm_minor(   t   Truet   _devices_supportedt   sett   _free_devicest   _assigned_devicest   _hardware_inventoryt   get_devicest   match_sys_namet   match_propertyt   addt   sys_nameR   t   _cmd(   t   selft   device(    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_video.pyt   _init_devices   s    	.c         C   s&   g  | D] } |  j  j d | ƒ ^ q S(   NR   (   R   t
   get_device(   R   t   devicest   x(    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_video.pyt   _get_device_objects   s    c         C   s   i d  d 6S(   Nt   radeon_powersave(   t   None(   R   (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_video.pyt   _get_config_options   s    c         C   s   t  | _ t | _ d  S(   N(   t   Falset   _has_dynamic_tuningR   t   _has_static_tuning(   R   t   instance(    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_video.pyt   _instance_init#   s    	c         C   s   d  S(   N(    (   R   R    (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_video.pyt   _instance_cleanup'   s    c         C   s%   i d | d 6d | d 6d | d 6S(   Ns%   /sys/class/drm/%s/device/power_methodt   methods&   /sys/class/drm/%s/device/power_profilet   profiles(   /sys/class/drm/%s/device/power_dpm_statet	   dpm_state(    (   R   R   (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_video.pyt   _radeon_powersave_files*   s    R   t
   per_devicec         C   st  |  j  | ƒ } t t j d d | ƒ ƒ j ƒ  } t j j | d ƒ sd | sd t j	 d | ƒ d  Sn  x	| D]} | d k r¿ | sl|  j j | d d
 ƒ r¼ |  j j | d
 | ƒ r¼ | Sqlqk | d k rô | sl|  j j | d d ƒ rñ d Sqlqk | d k rR| sl| t d ƒ } |  j j | d d ƒ rO|  j j | d | ƒ rO| Sqlqk | sht j	 d ƒ n  d  Sqk Wd  S(   Ns#   (\s*:\s*)|(\s+)|(\s*;\s*)|(\s*,\s*)t    R#   s)   radeon_powersave is not supported on '%s't   defaultt   autot   lowt   midt   highR$   t   dynpms   dpm-batterys   dpm-balanceds   dpm-performances   dpm-t   dpmR%   s$   Invalid option for radeon_powersave.(   s   defaultR*   R+   R,   R-   (   s   dpm-batterys   dpm-balanceds   dpm-performance(   R&   t   strt   ret   subt   splitt   ost   patht   existst   logt   warnR   R   t   write_to_filet   len(   R   t   valueR   t   simt	   sys_filest   vat   vt   state(    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_video.pyt   _set_radeon_powersave1   s4    !


c         C   s™   |  j  | ƒ } |  j j | d d | ƒj ƒ  } | d k rW |  j j | d ƒ j ƒ  S| d k rg | S| d k r‘ d |  j j | d ƒ j ƒ  Sd  Sd  S(   NR#   t   no_errorR$   R.   R/   s   dpm-R%   (   R&   R   t	   read_filet   stripR   (   R   R   t   ignore_missingR=   R#   (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_video.pyt   _get_radeon_powersaveP   s    "(   t   __name__t
   __module__t   __doc__R   R   t   classmethodR   R!   R"   R&   t   command_setR   RA   t   command_getR   RF   (    (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_video.pyR   
   s   						(   t    R    t
   decoratorst
   tuned.logst   tunedt   tuned.utils.commandsR   R4   R1   t   logst   getR7   t   PluginR   (    (    (    s>   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_video.pyt   <module>   s   
