\c@spddlZddlZddlmZdgZejjZdefdYZ defdYZ dS(iN(tconstst InventorycBsqeZdZd d d d edZdZdZdZdZ dZ dZ dZ d d Z RS( s Inventory object can handle information about available hardware devices. It also informs the plugins about related hardware events. cCs|dk r||_ntj|_|dkr?tj}n|j|j|_|dkrltj}n|r|jj |n|dkrt }n||_ d|_ i|_ dS(N(tNonet _udev_contexttpyudevtContexttMonitort from_netlinkt _udev_monitorRtCFG_DEF_UDEV_BUFFER_SIZEtset_receive_buffer_sizet_MonitorObserverFactoryt_monitor_observer_factoryt_monitor_observert_subscriptions(tselft udev_contexttudev_monitor_clstmonitor_observer_factoryt buffer_sizeR ((s</usr/lib/python2.7/site-packages/tuned/hardware/inventory.pyt__init__s          cCsKytjj|j||SWn'tk rFtjj|j||SXdS(s9Get a pyudev.Device object for the sys_name (e.g. 'sda').N(RtDevicest from_nameRtAttributeErrortDevice(Rt subsystemtsys_name((s</usr/lib/python2.7/site-packages/tuned/hardware/inventory.pyt get_device%s cCs|jjd|S(s)Get list of devices on a given subsystem.R(Rt list_devices(RR((s</usr/lib/python2.7/site-packages/tuned/hardware/inventory.pyt get_devices-scCs|j|jkrdSxc|j|jD]Q\}}y|||Wq'tk rw}tjd|tj|q'Xq'WdS(Ns+Exception occured in event handler of '%s'.(RRt Exceptiontlogterrort exception(Rteventtdevicetplugintcallbackte((s</usr/lib/python2.7/site-packages/tuned/hardware/inventory.pyt_handle_udev_event1scCsztjd||f||f}||jkrI|j|j|n-|g|j|<|jj||jjdS(s7Register handler of device events on a given subsystem.sadding handler: %s (%s)N(RtdebugRtappendRt filter_bytstart(RR$RR%t callback_data((s</usr/lib/python2.7/site-packages/tuned/hardware/inventory.pyt subscribe<s cCsN|jdkrJtjd|jj|j|j|_|jjndS(Nsstarting monitor observer( R RRR(R tcreateRR'R+(R((s</usr/lib/python2.7/site-packages/tuned/hardware/inventory.pytstart_processing_eventsHs cCs9|jdk r5tjd|jjd|_ndS(Nsstopping monitor observer(R RRR(tstop(R((s</usr/lib/python2.7/site-packages/tuned/hardware/inventory.pytstop_processing_eventsNs  cCsbx[|j|D]L}|\}}||krtjd||f|j|j|qqWdS(Nsremoving handler: %s (%s)(RRR(tremove(RR$RR,t_pluginR%((s</usr/lib/python2.7/site-packages/tuned/hardware/inventory.pyt_unsubscribe_subsystemTs   cCsg}xe|jD]Z}|dks.||kr|j||t|j|dkrj|j|qjqqWx|D]}|j|=quWdS(s4Unregister handler registered with subscribe method.iN(RRR4tlenR)(RR$Rtempty_subsystemst _subsystem((s</usr/lib/python2.7/site-packages/tuned/hardware/inventory.pyt unsubscribe[s N(t__name__t __module__t__doc__RtTrueRRRR'R-R/R1R4R8(((s</usr/lib/python2.7/site-packages/tuned/hardware/inventory.pyR s     R cBseZdZRS(cOstj||S(N(RtMonitorObserver(Rtargstkwargs((s</usr/lib/python2.7/site-packages/tuned/hardware/inventory.pyR.hs(R9R:R.(((s</usr/lib/python2.7/site-packages/tuned/hardware/inventory.pyR gs( Rt tuned.logsttunedRt__all__tlogstgetRtobjectRR (((s</usr/lib/python2.7/site-packages/tuned/hardware/inventory.pyts   ^