
    id*                         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mZ d dl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)SoSComponent)import_policy)Plugin)boldImporterHelper)fillx   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                 f    t         t        |   |||       | j                  j                  | _        y )N)superr   __init__optsr   )selfparserargscmdline	__class__s       3/usr/lib/python3/dist-packages/sos/help/__init__.pyr   zSoSHelper.__init__+   s%    i'g>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                 F   | j                   j                  s%| j                          t        j                  d       | j                          	 | j                         }r-	 t               }|j                  |       |j                          y t        d| j                   j                  z         y # t        $ rD}t        d| j                   j                  d|       t        j                  d       Y d }~d }~ww xY w# t        $ r}t        d|z         Y d }~y d }~ww xY w)Nr   zCould not load help for 'z':    zError loading help: %szNo help section found for '%s')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
 6 ]""2&

 2TYY__DE  			MNHHQKK	  6.4556s0   B/  +C? /	C<8:C77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}|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
startswith)r   
static_mapr$   mod_help_secs         r   r8   zSoSHelper.get_obj_for_topic\   s    
 "&#'$5"+ 

 99??j())&499??*BCC#z$))//:;C 
 $(#;#;!55)-)D)D'+'@'@	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.sosnoderZ   r   r   r.   )r   rZ   
_transports      r   rR   z SoSHelper._get_collect_transport|   s:    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   )rE   clustersr(   r[   r4   )	sos.collectorrE   sos.collector.clusters_load_modulesr*   r_   r   r   r.   )r   rE   sosr_   clusters        r   rS   zSoSHelper._get_collect_cluster   sd    .%--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 )NrL   r4   )rM   rN   r   r   load_local_policyinspect
getmembersisclass
issubclassr   __subclasses__policymatch_plugin)r   rV   memsmpluginspluginr$   s          r   rP   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   rl   r   )r   r   r.   sos.policies.distrosr   rK   distrosget_modulesr   __name__lowerr/   )r   _topicrc   _helperrV   rl   _ps          r   rQ   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      z         |j                  d      }t        d      }|j                  d|z         t        d      }|j                  d	|z         |j                  d
      }|j                  d       ddddddd}|D ]1  }|j                  dj	                  t        |      ||         d       3 |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.ah  SoS - 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 %s (formerly sosreport) which is used to collect troubleshooting information into an archive for review by sysadmins or technical support teams.z
sos reportzHow to search using sos helpz$component.$topic.$subtopicz<To get more information on a given topic, use the form '%s'.zsos help report.plugins.kernelz\For example '%s' 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)rI   rJ   zreport.plugins.$pluginr+   r-   rK   z		{:<36}{}F)newlineN)r;   add_textr   add_sectionformatr=   )r   	self_helpsubsectr!   rep_ex
avail_helpsectionssects           r   r5   zSoSHelper.display_self_help   s+     (J
	 	7 < !	
 ''(FG23L	

 67 FHNO 	P **+DE
	
 >G&I<>E
  	D##DJ?   	 	r   )rv   
__module____qualname____doc__descconfigure_loggingload_policy
load_probearg_defaultsr   classmethodr&   r2   rA   r8   rR   rS   rP   rQ   r5   __classcell__)r   s   @r   r   r      sq     &DKJ 	L% 1 1LF0@*"
"5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   r9   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   )
rv   r   r   r   r   r   r}   r~   r   r=    r   r   r;   r;      s&    &$
 $*C-r   r;   )rg   rM   r6   oscollectionsr   sos.componentr   sos.policiesr   sos.report.pluginsr   sos.utilitiesr   r   textwrapr	   minget_terminal_sizecolumnsr   r9   r   r;   r   r   r   <module>r      sz      
 	 # & & % . '2'')1137H
y yxU- U-A  Hs   "A0 0A:9A: