
    -_g
+                         d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZmZ 	  e ej$                         j&                  d      Z G d	 d
e	      Z G d d      Zy# e$ r dZY w xY w)    N)OrderedDict)fill)SoSComponent)import_policy)Plugin)boldImporterHelperx   c                   z     e Zd ZdZdZdZdZdZddiZ fdZ	e
d        Zd Zd	 Zd
 Zd Zd Zd Zd Zd Z xZS )	SoSHelperzProvide better, more in-depth help for specific parts of sos than is
    provided in either standard --help output or in manpages.
    zDetailed help infomationFtopic c                 ^    t         |   |||       | j                  j                  | _        y )N)super__init__optsr   )selfparserargscmdline	__class__s       3/usr/lib/python3/dist-packages/sos/help/__init__.pyr   zSoSHelper.__init__+   s#    w/YY__
    c                 b    d|_         |j                  dd      }|j                  ddddd	       y )
Nzsos help TOPIC [options]zHelp Information Optionsz<These options control what detailed information is displayedr   TOPICr   ?z/name of the topic or component to show help for)metavardefaultnargshelp)usageadd_argument_groupadd_argument)clsr   help_grps      r   add_parser_optionszSoSHelper.add_parser_options/   sA    1,,&J
 	gw#%/ 	 	1r   c                     | j                   j                  j                  d      d   }dddd}||v r9| j                   j                  j                  |||         | j                   _        y y )N.r   cleaner	collector)cleanmaskcollect)r   r   splitreplace)r   _com_replaces      r   sanitize_topic_componentz"SoSHelper.sanitize_topic_component:   sb    yy$$S)!,"

 8"iioo55dHTNKDIIO r   c                 H   | j                   j                  s%| j                          t        j                  d       | j                          	 | j                         }r-	 t               }|j                  |       |j                          y t        d| j                   j                   d       y # t        $ rD}t        d| j                   j                   d|        t        j                  d       Y d }~d }~ww xY w# t        $ r}t        d|        Y d }~y d }~ww xY w)Nr   zCould not load help for 'z':    zError loading help: zNo help section found for '')r   r   display_self_helpsysexitr2   get_obj_for_topic	ExceptionprintHelpSectiondisplay_helpdisplay)r   klasserrhts       r   executezSoSHelper.executeD   s    yy""$HHQK 	%%'	**,E
 4 ]""2&

 /		/@BC  	-diioo->c#GHHHQKK	  4,SE2334s0   B0  +D  0	C=9:C88C= 	D!	DD!c                    dddddddd}d	}| j                   j                  |v rQt        j                  d
| j                   j                  z         }t	        ||| j                   j                           }|S | j
                  | j                  | j                  | j                  d}|j                         D ]4  \  }}| j                   j                  j                  |      s, |       } |S  |S )zBased on the help topic we're after, try to smartly decide which
        object we need to manipulate in order to get help information.
        	SoSReportr   
SoSCleanerSoSCollectorRemoteTransportClusterPolicy)reportreport.pluginsr)   r*   zcollector.transportszcollector.clusterspoliciesNsos.)zreport.plugins.z	policies.zcollector.transports.zcollector.clusters.)r   r   	importlibimport_modulegetattr_get_plugin_variant_get_policy_by_name_get_collect_transport_get_collect_clusteritems
startswith)r   
static_mapr$   mod_help_secvalues          r   r9   zSoSHelper.get_obj_for_topic\   s    
 "&#'$5"+ 

 99??j())&499??*BCC#z$))//:;C 
 $(#;#;!55)-)D)D'+'@'@	E  %{{} e99??--d3'C
	 
r   c                 r    ddl m} | j                  j                  j	                  d      d   }||v r||   S y )Nr   )
TRANSPORTSr(   )sos.collector.sosnoder]   r   r   r.   )r   r]   
_transports      r   rS   z SoSHelper._get_collect_transport|   s8    4YY__**3/3
#j))r   c                     ddl m} dd l}|j                  |j                  j
                  d      }|D ]7  }|d   | j                  j                  j                  d      d   k(  s2|d   c S  y )Nr   )rF   clustersr(   r^   r4   )	sos.collectorrF   sos.collector.clusters_load_modulesr*   rb   r   r   r.   )r   rF   sosrb   clusters        r   rT   zSoSHelper._get_collect_cluster   si    .%--cmm.D.D.8: 	"GqzTYY__2237;;qz!	" r   c                    t        j                  d| j                  j                  z         }| j	                          t        j                  |t
        j                        }|D cg c]  }t        |d   t              s|d    }}|D ]?  }|j                         s| j                  j                  |j                               }|c S  y c c}w )NrM   r4   )rN   rO   r   r   load_local_policyinspect
getmembersisclass
issubclassr   __subclasses__policymatch_plugin)r   rX   memsmpluginspluginr$   s          r   rQ   zSoSHelper._get_plugin_variant   s    %%ftyy&>? !!#w7!%BAAaD&)A1Q4BB 	F$$&kk..v/D/D/FG
	  Cs   %C>Cc                 N   | j                   j                  j                  d      d   }dd l}t	        |j
                  j                        }|j                         D ]G  }t        |      D ]7  }|j                  j                         j                  dd      }||k(  s3|c c S  I y )Nr(   r^   r   ro   r   )r   r   r.   sos.policies.distrosr	   rL   distrosget_modulesr   __name__lowerr/   )r   _topicrf   _helperrX   ro   _ps          r   rR   zSoSHelper._get_policy_by_name   s    &&s+B/ 	$ !5!56&&( 	"C', "__**,44XrB<!M"	"
 r   c                    t        dd      }|j                  dt        d       d       |j                  d      }t        d      }|j                  d| d	       t        d
      }|j                  d| d       |j                  d      }|j                  d       ddddddd}|j	                         D ]'  \  }}|j                  dt        |      d| d       ) |j                          y)zhDisplays the help information for this component directly, that is
        help for `sos help`.
        zDetailed help for sos helpzThe 'help' sub-command is used to provide more detailed information on different sub-commands available to sos as well as different components at play within those sub-commands.zSoS - officially pronounced "ess-oh-ess" - is a diagnostic and supportability utility used by several Linux distributions as an easy-to-use tool for standardized data collection. The most known component of which is z
sos reportz (formerly sosreport) which is used to collect troubleshooting information into an archive for review by sysadmins or technical support teams.zHow to search using sos helpz$component.$topic.$subtopicz8To get more information on a given topic, use the form 'z'.zsos help report.plugins.kernelzFor example 'zM' will provide more information on the kernel plugin for the report function.zAvailable Help SectionszThe following help sections are available. Additional help topics and subtopics may be displayed within their respective help section.
z#Detailed help on the report commandz'Information on the plugin design of sosz!Information on a specific $pluginz"Detailed help on the clean commandz$Detailed help on the collect commandz+How sos operates on different distributions)rJ   rK   zreport.plugins.$pluginr+   r-   rL   	z<36F)newlineN)r<   add_textr   add_sectionrU   r>   )	r   	self_helpsubsectr!   rep_ex
avail_helpsectionssectr[   s	            r   r6   zSoSHelper.display_self_help   s?     (J
	 	& '+<&8%9 :JJ	
 ''(FG23s	

 67= 1% % 	& **+DE
	
 >G&I<>E
 $>>+ 	MKD%"T$Z$4UG <eL	M 	r   )ry   
__module____qualname____doc__descconfigure_loggingload_policy
load_probearg_defaultsr   classmethodr&   r2   rB   r9   rS   rT   rQ   rR   r6   __classcell__)r   s   @r   r   r      sq     &DKJ 	L% 1 1LD0@	2r   r   c                   <    e Zd ZdZd	dZd Zd
dZddZddZd Z	y)r<   zThis class is used to build the output displayed by `sos help` in a
    standard fashion that provides easy formatting controls.
    c                 L    || _         || _        || _        t               | _        y)a  
        :param title:   The title of the output section, will be prominently
                        displayed
        :type title:    ``str``

        :param content: The text content to be displayed with this section
        :type content:  ``str``

        :param indent:  If the section should be nested, set this to a multiple
                        of 4.
        :type indent:   ``int``
        N)titlecontentindentr   r   r   r   r   r   s       r   r   zHelpSection.__init__   s"     
#r   c                     || _         y)zSet or override the title for this help section

        :param title:   The name to set for this help section
        :type title:    ``str``
        N)r   )r   r   s     r   	set_titlezHelpSection.set_title   s     
r   c                 \    | j                   r|rdnd}||z   }| xj                   |z  c_         y)zAdd body text to this section. If content for this section already
        exists, append the new ``content`` after a newline.

        :param content:     The text to add to the section
        :type content:      ``str``
        z


N)r   )r   r   r   lns       r   r   zHelpSection.add_text   s+     <<"B7lGr   c                 F    | j                  |||       | j                  |   S )ac  Add a section of text to the help section that will be displayed
        when the HelpSection object is printed.

        Sections will be printed *in the order added*.

        This will return a subsection object with which block(s) of text may be
        added to the subsection associated with ``title``.

        :param title:   The title of the subsection being added
        :type title:    ``str``

        :param content: The text the new section should contain
        :type content:  ``str``

        :returns:   The newly created subsection for ``title``
        :rtype:     ``HelpSection``
        )_add_sectionr   r   s       r   r   zHelpSection.add_section  s%    $ 	%&1}}U##r   c                 j    || j                   v rt        d      t        |||      | j                   |<   y)zInternal method used to add a new subsection to this help output

        :param title:   The title of the subsection being added
        :type title:    ``str`
        z(A section with that title already existsN)r   r:   r<   r   s       r   r   zHelpSection._add_section  s3     DMM!FGG*5'6Ber   c                 n   t        t        t        | j                        t        | j
                               | j                  j                         D ]'  }t        t        |t        | j
                               ) | j                  D ]*  }t        d       | j                  |   j                          , y)zWPrint the HelpSection contents, including any subsections, to
        console.
        )widthinitial_indentr   N)
r;   r   r   r   TERMSIZEr   r   
splitlinesr   r>   )r   r   sections      r   r>   zHelpSection.display$  s     	dHT[[
 	 ,,))+ 	HB$r$++FG	H}} 	-G"IMM'"**,	-r   N)r   r   r   )T)r   r   )
ry   r   r   r   r   r   r   r   r   r>    r   r   r<   r<      s&    &$
 $*C-r   r<   )rj   rN   r7   oscollectionsr   textwrapr   sos.componentr   sos.policiesr   sos.report.pluginsr   sos.utilitiesr   r	   minget_terminal_sizecolumnsr   r:   r   r<   r   r   r   <module>r      sz      
 	 #  & & % .'2'')1137H
z zzU- U-C  Hs   "A0 0A:9A: