o c&@svddlZddlmZddlZddlZddlmZddlmZddl m Z ddl m Z Gddde Z dddZdS)N) getLogger)Failure) log_failure)PluginRegistry)gather_resultscsheZdZdZfddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ZS)SysInfoPluginRegistryaG When the sysinfo plugin registry is run, it will run each of the registered plugins so that they get a chance to feed information into the registry. There are three kinds of details collected: headers, notes, and footnotes. They are presented to the user in a way similar to the following: Header1: Value1 Header3: Value3 Header2: Value2 Header4: Value4 => This is first note => This is the second note The first footnote. The second footnote. Headers are supposed to display information which is regularly available, such as the load and temperature of the system. Notes contain eventual information, such as warnings of high temperatures, and low disk space. Finally, footnotes contain pointers to further information such as URLs. cs0tt|i|_g|_g|_g|_d|_dS)NF)superr__init__ _header_index_headers_notes _footnotes _plugin_errorself __class__;/usr/lib/python3/dist-packages/landscape/sysinfo/sysinfo.pyr 's  zSysInfoPluginRegistry.__init__cCs`|j|}|durt|j|j|<|j||fdS|d7}||j|<|j|||fdS)ajAdd a new information header to be displayed to the user. Header names can be repeated. Headers with value None are not returned by get_headers(), but they still allocate a position in the list. This fact may be explored to create a deterministic ordering even when dealing with values obtained asynchornously. N)r getlenr appendinsert)rnamevalueindexrrr add_header/s  z SysInfoPluginRegistry.add_headercCsdd|jDS)zGet all information headers to be displayed to the user. Headers which were added with value None are not included in the result. cSsg|] }|ddur|qS)rNr).0pairrrr Hsz5SysInfoPluginRegistry.get_headers..)r rrrr get_headersBsz!SysInfoPluginRegistry.get_headerscC|j|dS)z c sf|t8}t|}d}|} |D]\} } t| t| t| d} qttt|| t|} tt|t| } g}d}t| D]F}d}d}t| D] }|| |}||kro||\} } t|t| }t|t| }qO|dkrz|t|7}|||t|7}|||fqE| dks||krn| d8} q2g}t| D]R}}t| D]D}|| |}||kr||\} } ||\}}|dkr||7}|| |d|t| | 7}||d| |kr|d|t| 7}q||q|r|r|d|}|D]}| t j ||dt||dq|r.|r"|d| fd d |Dd |S) aFormat sysinfo headers, notes and footnotes to be displayed. This function will format headers notes and footnotes in a way that looks similar to the following: Header1: Value1 Header3: Value3 Header2: Value2 Header4: Value4 => This is first note => This is the second note The first footnote. The second footnote. Header columns will be dynamically adjusted to conform to the size of header labels and values. z: Trr rD)initial_indentsubsequent_indentwidthc3s|]}|VqdS)Nr)rfootnoteindentrr sz!format_sysinfo.. ) rminintmathceilfloatrangemaxrextendtextwrapwrapr>)headersnotes footnotesrKrNcolumn_separator note_prefix headers_lenvalue_separator min_lengthheaderrcolumnsheaders_per_columnheader_lengths total_lengthcolumnwidest_header_lenwidest_value_lenrow header_indexlineslinerIr$rrMrformat_sysinfo{s          .          ro)rrrrCrDrErF)rYloggingrrSr<twisted.python.failurerlandscape.lib.logrlandscape.lib.pluginrlandscape.lib.twisted_utilrrrorrrrs     n