JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbr O6ufO ddlZddlZddlZddlZddlmZmZmZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlmZddlmZ ddlmZdZ ddlZej8edZdZ%gdZ&dZ'd2dZ(dZ)d3dZ*d4dZ+dZ,d5dZ-dZ.d6dZ/e%ddddddddddf dZ0d6dZ1d7dZ2d8dZ3ejhfdZ5dZ6d Z7d!Z8d"Z9d#Z:ejvd$d%ZGd(d)Z?Gd*d+ejZAGd,d-eBZCGd.d/ZDGd0d1eEZFy#e$r ddlmZYwxYw#eef$r>ej>d Z dd l!m"Z"d Z#e jId e"e#d dzd zY wxYw)9N)PopenPIPESTDOUT)closing)deque)parse) parse_versionFTsos)fillzWARNING: Failed to load 'magic' module version >= 0.4.20 which sos aims to use for detecting binary files. A less effective method will be used. It is recommended to install proper python3-magic package with the module.  H)replace_whitespacei,)TIMEOUT_DEFAULTImporterHelperSoSTimeoutError TempFileUtilboldfile_is_binaryfileobjfindget_human_readablegrep import_module is_executablelistdirr path_exists path_isdir path_isfile path_islink path_joinrecursive_dict_values_by_key shell_outsos_get_command_outputtailc(tjd} |j|d\}}}|s|Stjdd|j d}|d|}|S#t $r'}t jd|d ||cYd }~Sd }~wwxYw) z< Convert the version into a PEP440 compliant version scheme.z2^([0-9][0-9.]*(?:(?:a|b|rc|.post|.dev)[0-9]+)*)\+?)maxsplitz[+~]+.-+zUnable to format z to pep440 format: N)recompilesplitsubstrip Exceptionlogdebug)verpublic_version_re_publiclocalsanitized_localpep440_versionerrs //usr/lib/python3/dist-packages/sos/utilities.pyformat_version_to_pep440r<Ms A ,2232C65J&&#u5;;C@"81_$56  %cU*=cUCD s"A!.A!! B*B B BcH|rt|}t|St|S)z6 Converts the version to PEP440 format before parsing )r<r )r3pep440 ver_pep440s r;sos_parse_versionr@^s% -c2 Z((  ct|d5}tj|j|kDr|j | d|j cdddS#1swYyxYw)z,Returns the last number_of_bytes of filenamerbN)openosstatst_sizeseekread)filenamenumber_of_bytesfs r;r$r$gsT h  778  $ $ 6 FFO#Q 'vvxs AAA%ct|tr t||St|S#t$rJt j d}|j d|dttjcYSwxYw)z@Returns a file-like object that can be used as a context managerr z fileobj: z could not be opened) isinstancestrrEIOErrorlogging getLoggerr2rioStringIO) path_or_filemoder1s r;rross,$ * d+ + |$$  *##E*C II ,/CD E2;;=) ) *s )AA<;A<c~t|}||k\r||z dS||k\r||z dS||k\r||z dS||k\r||z dS|S)zCConverts a number of bytes to a shorter, more human friendly formatz.1fTz.1fGz.1fMz.1fK)float)bytes_KMGTfns r; convert_bytesr`|sg vB {64! 164! 164! 164!rAcFtr@ tj|ddg}jdk(xrt fd|D St |d5} |jd dddy#t $rY4wxYw#t$r Ydddy wxYw#1swYyxYw) azHelper to determine if a given file contains binary content or not. This is especially helpful for `sos clean`, which cannot obfuscate binary data and instead, by default, will remove binary files. :param fname: The full path of the file to check binaryness of :type fname: ``str`` :returns: True if binary, else False :rtype: ``bool`` ztext/zinode/binaryc3TK|]}jj|!ywN) mime_type startswith).0_mt_ftups r; z!file_is_binary..s FEOO..s3Fs%(trr&NFT) magic_modmagicdetect_from_filenameencodinganyr0rErJUnicodeDecodeError)fname_mimestfileris @r;rrs ..u5Ex(F(*GFvFF0G  eT e  JJqM     "    s;>A1BB1 A=<A= B BBBB c#K|rKtjj|jtjj}||z }tj |D]\}}}|r1|jtjj|k\r|dd=|rt j ||sSt j||D]$}tjj||&yw)zGenerator function to find files recursively. Usage:: for filename in find("*.properties", "/var/log/foobar"): print filename N) rFpathdirnamecountsepwalkfnmatchfilterjoin) file_patterntop_dir max_depth path_pattern base_depthrvdirlistfilelistnames r;rrsWW__W-33BGGKK@ Z #%777#3+gx BGGKK0I= l C NN8\: +D'',,tT* * ++sC6C8cg}|D]0}t|5}|jfd|Dddd2|S#1swY>xYw)zReturns lines matched in fnames, where fnames can either be pathnames to files to grep through or open file objects to grep through line by linec3PK|]}tj|s|ywrd)r+match)rglinepatterns r;rjzgrep..sKT288GT3JDKs&&N)rextend)rfiles_or_pathsmatchesfopfos` r;rrs\GM S\ MR NNKRK L M MM N M Ms ;A c tjjddjtjj }|g|Dcgc]"}tjj ||$c}z}|r@||Dcgc]1}tjj ||jd3c}z }td|DScc}wcc}w)z6Returns if a command matches an executable on the PATHPATH/c3dK|](}tj|tj*ywrd)rFaccessX_OK)rgrvs r;rjz is_executable..s?Dryyrww'?s.0) rFenvirongetr-rvpathsepr}lstriprp)commandsysrootpathsp candidatescs r;rrs JJNN62 & , ,RWW__ =EF1bggll1g6FFJ:D 56BGGLL!((3- 0   ?J? ?? G s 'C6Cc   fd} fd} r?tj }|j|j |j dtj j }d|d<|r2|jD]\}}|r|||<|j|d!|rtdrd|rd nd d |d |}tj|}g}|D]c}|jd r?d|vr;tj|}|r|j|A|j|S|j|e| r t!| d}nt"} t%|d||rt&nt"d|d| }| st)|j*||}n t-||} r"|j.r,| ||j.rn |j1|r|nd| r|j7|j= |j=|j9}|j:}|jDdk(s|jDdk(rd}|jD||dS#t2$rJ|j5| r|j7d|_d|j9|j:dcYSwxYw#t>$rA}| r|j7|j@t@jBk(r dd d dcYd}~S|d}~wwxYw)zExecute a command and return a dictionary of status and output, optionally changing root or current working directory before executing command. crdk7rtjrtjtjj tj tjjtjtjjrtjyyNr) rFchrootsetgidpwdgetpwnampw_gidsetuidpw_uidchdirpw_dir)rrrunassr;_child_prep_fnz.sos_get_command_output.._child_prep_fns fm IIf   IIcll5)00 1 IIcll5)00 1 HHS\\%(// 0  HHUO rAcs|jdk(r|jttjdy)N|{Gz?)poll terminatertimesleep)procpollers r; _check_pollerz-sos_get_command_output.._check_pollers1 8tyy{c) NN ! ! 4rA)HOMELOGNAMEPWDUSERzC.UTF-8LC_ALLNtimeoutztimeout z --foregroundr zs r*wFT)shellstdoutstderrbufsizeenv close_fds preexec_fnr)statusoutput truncated~rA)#rrupdaterrFrcopyitemspoprshlexr-rfglobrappendrErrr AsyncReaderr FakeReaderrunningwaitr0rclose get_contentsis_fullrOSErrorerrnoENOENT returncode)rrrrrr foregroundrb sizelimitrto_filerrrpwd_usercmd_envkeyvalueargs expanded_argsarg expanded_arg_outputrreaderrres `` ` ` r;r#r#s  <<& OO??   jjooG!GH ))+ 'JC$  C&  ' =+ nC1WINi! ;;w DM& >># 3#:99S>L$$\2$$S)   %&w$, -uW#)t'T+ -  9f=F6*F ..a .. 5'wt4  MMOffh ffh$$&NN  ||sallc1,, = 5 MMO"'"%1D1D1F%+^^55 5&   MMO 77ell "!RbA AG sVA'J/J/I3J/ J/AJ,)J/+J,,J// K984K4,K92K44K9c|jdd} t|tt|g}tj|tjDcgc]\}}|j|k(r|}}}|r|Dcgc]}t||s|}}|S#t$r,}t d|d|j j|d}~wwxYwcc}}wcc}w)aImports the module module_fqname and returns a list of defined classes from that module. If superclasses is defined then the classes returned will be subclasses of the specified superclass or superclasses. If superclasses is plural it must be a tuple of classes.r(rz"Error while trying to load module z: N) rpartition __import__globalslocals ImportErrorprint __class____name__inspect getmembersisclass __module__ issubclass) module_fqname superclasses module_namemodulercnameclass_modulesms r;rrWs  **3/3KM79fh N !!&'//:6-%##}46G6%EA|)D1EE N  2=/B++&&') *6Fs)BCCC C#'C  Cc&t||||dS)zeShell out to an external command and return the output or the empty string in case of error. )rrrr)r#)cmdrrrunats r;r"r"ls$ "#w)/u >>F HHrAchgd}d}|dkDr|dkr|dz }|dz }|dkDr|dkr|d|d||S) N)BKiBMiBGiBTiBrr&g@r(rM)size precisionsuffixes suffixindexs r;rrts]0HK ++/q F{ ++/1YKq. !(;"7!8 99rAc|rS|tjk7r@|j|s/tjj ||j d}t ||}||Sr)rFryrfrvr}rgetattr)rvrmethodr_meths r; _os_wrapperr~sO7bff$w'77<<S)9:D FF #E ;rAcJd|vrt||dtSt||dS)Nrr)rexists)rrrvrs r;rrs) d{4&>> tWh //rAct||dS)Nisdirrrs r;rrs tWg ..rAct||dS)Nisfilerrs r;rr tWh //rAct||dS)Nislinkrrs r;rrr"rAc&t||dtS)Nr)rrFrs r;rrs tWi 44rA)rc|rN|j|s=tjj||j tj }tjj|g|Srd)rfrFrvr}rry)rvrrs r;r r sItw/ww||GT[[%89 77<< !q !!rAcd|zdzS)a"Helper to make text bold in console output, without pulling in dependencies to the project unneccessarily. :param text: The text to make bold :type text: ``str`` :returns: The text wrapped in the ASCII codes to display as bold :rtype: ``str`` zzr)texts r;rrs t i ''rAcg}g}|j|t|tr|jD]\}|j ||r||vr|jt 8ttsI |jt fd|Dd|jjn|j||Dcgc] }||vs| c}S#t $rYSwxYwcc}w)a Recursively compile all elements of a potentially nested dict by a set of keys. If a given key is a dict within ``dobj``, then _all_ elements within that dict, regardless of child keys, will be returned. For example, if a Plugin searches the devices dict for the 'storage' key, then all storage devices under the that dict (e.g. block, fibre, etc...) will be returned. However, if the Plugin specifies 'block' via ``keys``, then only the block devices within the devices['storage'] dict will be returned. Any elements passed here that are _not_ keys within the dict or any nested dicts will also be returned. :param dobj: The 'top-level' dict to intially search by :type dobj: ``dict`` :param keys: Which keys to compile elements from within ``dobj``. If no keys are given, all nested elements are returned :param keys: ``list`` of ``str`` :returns: All elements within the dict and any nested dicts :rtype: ``list`` c32K|]}|vs|ywrdr)rgrvs r;rjz/recursive_dict_values_by_key..s 5'*cQhAcF5s  r)rrOdictrrr! IndexErrorkeys)dobjr._items_filtkdr+s @r;r!r!s0F E MM$$JJL 'DAq LLO19 :1=>At$ MM45.25 QVVX&% '*  d 0!%A 00" 1s&C/ C>(C>/ C;:C;c<eZdZdZdZedZdZedZy)rzUsed as a replacement AsyncReader for when we are writing directly to disk, and allows us to keep more simplified flows for executing, monitoring, and collecting command output. c ||_||_yrd)processrb)selfr6rbs r;__init__zFakeReader.__init__s  rAcy)NFrr7s r;rzFakeReader.is_fullsrAc"|jsdSdS)NrrA)rbr:s r;rzFakeReader.get_contentssr-#-rAc:|jjduSrd)r6rr:s r;rzFakeReader.runnings||  "d**rAN) rr __qualname____doc__r8propertyrrrrrAr;rrs9 .++rArc>eZdZdZfdZdZdZedZxZ S)rzUsed to limit command output to a given size without deadlocking sos. Takes a sizelimit value in MB, and will compile stdout from Popen into a string that is limited to the given sizelimit. ct|||_||_d|_d|_|r"|dz}t ||jz |_t|j |_d|_|jy)Ni)maxlenT) superr8chanrb chunksizeslotsintrrstart)r7channelrrbrs r;r8zAsyncReader.__init__sl    !G+IY78DJ$**-   rAc |jj|j}|sn|jj |D d|_y#t t f$r Yd|_ywxYw)alReads from the channel (pipe) that is the output pipe for a called Popen. As we are reading from the pipe, the output is added to a deque. After the size of the deque exceeds the sizelimit earlier (older) entries are removed. This means the returned output is chunksize-sensitive, but is not really byte-sensitive. FN)rErJrFrr ValueErrorrQr)r7rs r;runzAsyncReader.runsk yy~~dnn5 !!$'   G$    sAAA)(A)c|jr"tjd|jr"|js"dj d|j DSdj d|j DS)z-Returns the contents of the deque as a stringrrc3@K|]}|jddyw)zutf-8ignoreN)decoderglns r;rjz+AsyncReader.get_contents..,sMB299Wh7MsrAc3 K|]}|ywrdrrRs r;rjz+AsyncReader.get_contents...s42B4s )rrrrbr}rr:s r;rzAsyncReader.get_contents%sYll JJt ll{{77M$**MM M88444 4rAc`|jsyt|j|jk(S)z?Checks if the deque is full, implying that output was truncatedF)rGlenrr:s r;rzAsyncReader.is_full0s%zz4::$**,,rA) rrr=r>r8rMrr?r __classcell__)rs@r;rrs+ * 5--rArc.eZdZdZdZdZdZdZdZy)rzProvides a list of modules that can be imported in a package. Importable modules are located along the module __path__ list and modules are files that end in .py. c||_y)zopackage is a package module import my.package.module helper = ImporterHelper(my.package.module)N)package)r7rZs r;r8zImporterHelper.__init__>s  rActjj|}tjj|\}}|S)z-Returns the plugin module name given the path)rFrvbasenamesplitext)r7rvbaserexts r; _plugin_namezImporterHelper._plugin_nameDs3ww%GG$$T* c rAc|Dcgc](}d|vr"|jdr|j|*}}|j|Scc}w)Nr8z.py)endswithr`sort)r7list_pluginpluginss r;_get_plugins_from_listz%ImporterHelper._get_plugins_from_listJsV!&K .6??53I$$V,KK   Ks-Actjj|r*tt d|}|j |}|r|SgS)Nz*.py)rFrvrlistrrg)r7rvpy_filespnamess r;_find_plugins_in_dirz#ImporterHelper._find_plugins_in_dirQs@ 77>>$ D./H00:F  rAcg}|jjD]B}tjj |s#|j |j |D|S)zQReturns the list of importable modules in the configured python package. )rZ__path__rFrvrrrl)r7rfrvs r; get_moduleszImporterHelper.get_modulesYsRLL)) @Dww}}T"t88>? @rAN) rrr=r>r8r`rgrlrorrAr;rr8s    rArceZdZdZdZdZy)rc ||_g|_yrd)tmp_dirfiles)r7rrs r;r8zTempFileUtil.__init__fs  rActj|j\}}tj|d}|j j ||f|S)N)dirzw+)tempfilemkstemprrrFfdopenrsr)r7fdrrfobjs r;newzTempFileUtil.newjsE$$6 EyyT" 5$-( rAc|jD]<\}} |j|j t j |>g|_y#t$rY+wxYw#t$rYawxYwrd)rsflushrr0rFunlink)r7rrrMs r;cleanzTempFileUtil.cleanqsq HE1     %        s" AA# A A # A/.A/N)rrr=r8r{rrrAr;rrds rArc eZdZy)rN)rrr=rrAr;rrsrAr)T)r)rrBi@l)NNrd)NN)rD)GrFrr+r subprocessrrrrRr{rrrrv threadingrrT contextlibr collectionsrpackaging.versionrr r pkg_resourcesrlrmrn__file__AttributeErrorrSr1textwrapr msgwarningr__all__r<r@r$rr`rrrrr#rr"rrvrrrrrrryr rr!rThreadrobjectrrrrrrAr;rs **  ,8   GEx(I 6" % D+,  @->EFGs% D$D5$ D21D25AE:9E: