o cm@sdZddlZddlZddlmZmZddlmZddlm Z ddl m Z m Z ddl mZddlmZdd lmZmZgd ZGd d d eZdd dZdddZdddZdS)z%Deployment code for the sysinfo tool.N) getLogger Formatter)RotatingFileHandler) namedClass)Deferred maybeDeferred)VERSION)BaseConfiguration)SysInfoPluginRegistryformat_sysinfo)LoadDiskMemory Temperature Processes LoggedInUsersNetworkcsjeZdZdZeZdZedkreej df7ZdZ dZ fddZ fd d Zd d Zd dZZS)SysInfoConfigurationz9Specialized configuration for the Landscape sysinfo tool.)z/etc/landscape/client.confrz~/.landscape/sysinfo.confz/var/lib/landscape/client/sysinfocstt|d|jd<dS)Nconfig)superr__init___command_line_defaults)self __class__>/usr/lib/python3/dist-packages/landscape/sysinfo/deployment.pyr szSysInfoConfiguration.__init__csBtt|}|jdddd|jddddddt|_|S) zg Specialize L{Configuration.make_parser}, adding any sysinfo-specific options. z--sysinfo-plugins PLUGIN_LISTzNComma-delimited list of sysinfo plugins to use. Default is to use all plugins.)metavarhelpz--exclude-sysinfo-pluginszhComma-delimited list of sysinfo plugins to NOT use. This always take precedence over plugins to include.zDefault plugins: %sz, )rr make_parser add_optionjoin ALL_PLUGINSepilog)rparserrrrr!%sz SysInfoConfiguration.make_parsercCsdd|dDS)NcSsg|]}|qSr)strip.0xrrr 9sz9SysInfoConfiguration.get_plugin_names..,)split)r plugin_specrrrget_plugin_names8sz%SysInfoConfiguration.get_plugin_namescsX|jdurt}n||j}|jdurgn||jfdd|D}dd|DS)Ncsg|]}|vr|qSrrr(excluderrr+Dsz4SysInfoConfiguration.get_plugins..cSs"g|] }td||fqS)zlandscape.sysinfo.%s.%s)rlower)r) plugin_namerrrr+Es   )sysinfo_pluginsr$r/exclude_sysinfo_plugins)rincludepluginsrr0r get_plugins;s    z SysInfoConfiguration.get_plugins)__name__ __module__ __qualname____doc__rversiondefault_config_filenamesosgetuidpath expanduserdefault_data_dirconfig_sectionrr!r/r8 __classcell__rrrrrs    rcCs,|durtdkrd}|Stjd}|S)zs Work out the correct path to store logs in depending on the effective user id of the current process. Nrz/var/log/landscapez ~/.landscape)r?r@rArB) landscape_dirrrrget_landscape_log_directoryJs   rGcCsdt|}td}d|_tj|st|tj|d}t|ddd}| || t ddS)Nzlandscape-sysinfoFz sysinfo.logi)maxBytes backupCountz'%(asctime)s %(levelname)-8s %(message)s) rGr propagater?rAisdirmkdirr#r addHandler setFormatterr)rFlogger log_filenamehandlerrrr setup_loggingWs   rSc sztWnty}z td|WYd}~nd}~wwdur&tt}|j|dd|D]}|q4fddfdddurkt  fd d fd d } | SS) zQ @param reactor: The reactor to (optionally) run the sysinfo plugins in. zUnable to setup logging. %sNT)!accept_nonexistent_default_configcs$ttdddS)Nz )indent)printr get_headers get_notes get_footnotesresult)rrr show_outputvs zrun..show_outputcsSN)run addCallbackr)r\rrr run_sysinfozszrun..run_sysinfocstSr])r chainDeferredr)doner`rrszrun..csdj|S)Nr) callLaterstoprZ)reactorrr stop_reactorszrun..stop_reactor) rSIOErrorsysexitr rloadr8addrcallWhenRunningaddBothr^)argsrfrerpluginrgr)rbrfr`r\rrr^ds2       r^r])NN)r<r?riloggingrrlogging.handlersrtwisted.python.reflectrtwisted.internet.deferrr landscaperlandscape.lib.configr landscape.sysinfo.sysinfor r r$rrGrSr^rrrrs     7