/usr/lib/python3/dist-packages/sos/__pycache__
NameSizeModeActions
archive.cpython-310.pyc235540644editdlrm
component.cpython-310.pyc161280644editdlrm
missing.cpython-310.pyc27590644editdlrm
options.cpython-310.pyc115130644editdlrm
utilities.cpython-310.pyc232920644editdlrm
__init__.cpython-310.pyc52530644editdlrm
Edit: /usr/lib/python3/dist-packages/sos/__pycache__/component.cpython-310.pyc (16128B)
o G%@iR@sddlZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z ddl m Z ddlmZddlmZdd lmZdd lmZdd lmZmZGd d d ZGdddZdS)N)fill)SUPPRESS)datetime)getpass)rmtree)Path) __version__)TarFileArchive) SoSOptions) TempFileUtil shell_outc @seZdZdZdZiZdZdZdZdZ dddddddddd dd d Z gd Z d dZ ddZ ddZddZd5ddZddZddZeddZddZdd Zd!d"Zd#d$Zd%d&Zd6d'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Z dS)7 SoSComponentaAny sub-command that sos supports needs to subclass SoSComponent in order to be properly supported by the sos binary. This class contains the standardized entrypoint for subcommands, as well as building out supported options from both globally shared option lists, and options supported by that specific subcommand. When sos initializes, it will load an unintialized instance of each class found within one recursion of the module root directory that subclasses SoSComponent. If sos is able to match the user-specified subcommand to one that exists locally, then that SoSComponent is initialized, logging is setup, and a policy is loaded. From there, the component's execute() method takes over. Added in 4.0 unsetTFautoz/etc/sos/sos.confNr) batchcompression_type config_filedebugencrypt encrypt_key encrypt_passquietthreadstmp_dirsysroot verbosity)zsos_logs/sos.logzsos_reports/manifest.jsonzsos_commands/process/ps_*zsos_commands/selinux/ps_*z+sos_commands/systemd/systemctl_status_--allc Cs||_||_||_d|_d|_d|_d|_d|_zddl}||j | Wnt yC}zt j d|dWYd}~nd}~wwt|jd|_|jrR||j|j||_|jr|}t|_tj|rvt|tjsd|d}|d7}t j|| d ||_!t"j#d |j!d |_t$|j|_|%|jdur|j&d t'|j&d d(|j|j&dt)*|j&dd|j&dd|j&dd|j&d|j|j&d|j+|j&d|j,j-|j.ddSdS)NFrz'Notice: Could not set SIGTERM handler:   arg_defaultsztemporary directory  z"does not exist or is not writable zsos.)prefixdirversioncmdline start_timeend_timerrun_time compressiontmpdirtmpdir_fs_typepolicy components)/parserargsr& exit_processarchiver+ tempfile_utilmanifestsignalSIGTERMget_exit_handler Exceptionsysstdoutwriter _arg_defaultsopts load_policyload_local_policyupdater load_optionsconfigure_loggingget_tmpdir_default SoSMetadataospathisdiraccessW_OKstderr_exitsys_tmptempfilemkdtempr _setup_logging add_fieldrjoinrnow tmpfstyper-os_release_name add_section)selfr/ parsed_args cmdline_argsr5errr+msgr[//usr/lib/python3/dist-packages/sos/component.py__init__Rs\         zSoSComponent.__init__cCs\zddl}|jj|jj|jd|_|jj|_Wnty%|dYnw|j |_ dS)Nr)r probe_runtime) sos.policiespoliciesloadr=r load_prober-KeyboardInterruptrKis_root_is_root)rVsosr[r[r\r?s  zSoSComponent.load_local_policycCtNNotImplementedErrorrVr[r[r\executeszSoSComponent.executecsfdd}|S)Ncsd_dS)NT)r1rK)signumframerkr[r\ exit_handlers z3SoSComponent.get_exit_handler..exit_handlerr[)rVror[rkr\r7s zSoSComponent.get_exit_handlercCs$|r|jd|j|t|)Nr)ui_logerror SystemExit)rVrqrZr[r[r\rKs  zSoSComponent._exitcCsf|jjr tj|jj}n tddp|jd}td| |_ |j dkr1t dt d|S)zIf --tmp-dir is not specified, provide a default location. Normally this is /var/tmp, but if we detect we are in a container, then use a standardized env var to redirect to the host's filesystem instead TMPDIRNzstat --file-system --format=%T tmpfszWARNING: tmp-dir is set to a tmpfs filesystem. This may increase memory pressure and cause instability on low memory systems, or when using --all-logs.)r=rrErFabspathgetenvr- get_tmp_dirr striprSprinttimesleep)rVr+r[r[r\rCs  zSoSComponent.get_tmpdir_defaultcs6ddjD}|rtfdd|DSdS)NcSsg|] }|dr|qS)list startswith).0or[r[r\ z6SoSComponent.check_listing_options..c3s|] }tj|VqdSrh)getattrr=)roptrkr[r\ sz5SoSComponent.check_listing_options..F)r=dictkeysany)rVr=r[rkr\check_listing_optionssz"SoSComponent.check_listing_optionscCrg)ziThis should be overridden by each subcommand to add its own unique options to the parser ri)clsr/r[r[r\add_parser_optionsszSoSComponent.add_parser_optionsc sFtj|j|j|jddd}|jdd}|D]\}}||jvs-|dgdfvr.q|dvrTdD]}t |t t ||@rSt ||fddt ||Dq4|d krt ||}d d|D}d d|D} t |t | @D]d fd d|D}qst ||t t |t |Bq||j|krt |||q|S)a.(Re-)apply options specified via the cmdline to an options instance There are several cases where we may need to re-apply the options from the cmdline over previously loaded options - for instance when an option is specified in both a config file and cmdline, or a preset and the cmdline, or all three. Use this to re-apply cmdline option overrides to anything that may change the default values of options Positional arguments: :param opts: SoSOptions object to update F) preset_filterrNr)enable_plugins skip_plugins only_pluginscsg|]}|vr|qSr[r[)rx)commonr[r\rsz;SoSComponent.apply_options_from_cmdline..plugoptscSg|] }|ddqS=rsplitrvr[r[r\rrcSrrrrr[r[r\rrrcsg|] }|s|qSr[r~)roopt)cstringr[r\rs ) r from_argsr/ parse_argsr&ritemsr rsetrsetattrr}) rVr=cmdoptscodictrvalr oplugoptsvalnames ovalnamesr[)rrr\apply_options_from_cmdlines4       z'SoSComponent.apply_options_from_cmdlinecCsbt|jd}|jjD] }|jtkrd|_q ||jj|jj d|j vs)d|j vr1||jjdt dkrNt j td}t j |rN|||jj ||}d|_t|dr|j|jdkr|j|j|_|jstjd |jd |j|_d |_|js|j|_|j|jjd d ||}t|jjd r|jjjdkr||jjj|S)zxCompile arguments loaded from defaults, config files, and the command line into a usable set of options rNz--cleanz--maskcleanrz.config/sos/sos.confpresetzUnknown preset: 'z' T) prefer_newr) r r<r/_actionsdefaultrupdate_from_confr0r componentr&rEgetuidrFrQrhomeexistsrrhasattrr- find_presetr9rJr; probe_preset list_presetsmerger=rset_loggers_verbosity)rVr=optionuserconfr[r[r\rAs:          zSoSComponent.load_optionsc Cszz|jr |j|jr|j|jrt|jWdSWdSty<}ztd|d|jWYd}~dSd}~ww)NzFailed to finish cleanup: z Contents may remain in )r2cleanupr3rr+rr8rz)rVrYr[r[r\r9s   zSoSComponent.cleanupcCsbd}tjdrtjd|j_d}ntjdr#tjd|j_d}|j||j|dS)NzFNo encryption environment variables set, archive will not be encrypted SOSENCRYPTKEYz+Encryption key set via environment variableSOSENCRYPTPASSz2Encryption passphrase set via environment variable) rEenvirongetr=rrsosloginforp)rVrZr[r[r\_set_encrypt_from_env_varsGs   z'SoSComponent._set_encrypt_from_env_varscCs|jjsLd}|dvrtd}|dvs |dkr td|j_dS|dkr,td|j_dS|dkr6|dSd|j_d|j_|j d|j d dS|dS) N)PKENzLSpecify encryption method [P]assphrase, [K]ey, [E]nv vars, [N]o encryption: rzSpecify encryption passphrase: rzSpecify encryption key: rz@User specified --encrypt, but chose no encryption when prompted.zArchive will not be encrypted) r=rinputupperrrrrrrrpwarning)rV_encr[r[r\_get_encryption_methodSs(   z#SoSComponent._get_encryption_methodcCs|jjr||jjp|jj|jj|jjd}|s|j}tj |j |}|jj dkrD|j }|||j |j|jj ||j|j|_nt||j |j|jj ||j|j|_|j|jjdkdS)N)rkeypasswordrru)r=rrrrr-get_archive_namerErFrQr+rget_preferred_archiverrr4r2r set_debugr)rVnameenc_opts archive_name auto_archiver[r[r\ setup_archiveks,     zSoSComponent.setup_archivecCsV|j}|jD] }t||D]}tj||}dD] }|j||dqqqdS)N)z(--upload-pass[\s=]+)\S+z$(--upload-url[\s=]+\S+://.*:)([^@]*)z!(--upload-s3-secret-key[\s=]+)\S+z \1********) r2get_archive_pathfiles_with_upload_passwdrglobrErFrelpath do_file_sub)rV _arc_pathrFfrer[r[r\_obfuscate_upload_passwordss  z(SoSComponent._obfuscate_upload_passwordscCsJttj}|td||jjdkrtj ntj |j |dS)N %(message)sr") logging StreamHandlerr9r: setFormatter FormattersetLevelr=rDEBUGINFOrp addHandler)rV ui_consoler[r[r\add_ui_log_to_stdouts z!SoSComponent.add_ui_log_to_stdoutcCsbt|ddr|r|jtjt|ddr/|r&|jjdkr&|jtjdS|jtjdSdS)Nflogconsoler") rrrrrr=rrWARNING)rVrr[r[r\rs z"SoSComponent.set_loggers_verbositycCsftd|_|jtjd|_|s7||_t |j|_|j t d|jtj |j |j|jjsZt tj|_|j t d||jj|j |jnt tj}| t d|tj|j |td|_|j|jjdkrtjntj |s||_t |j}| t d|j ||jjs|dSdS)zCreates the log handler that shall be used by all components and any and all related bits to those components that need to log either to the console or to the log file for that run of sos. rfNz&%(asctime)s %(levelname)s: %(message)srsos_uir")r getLoggerrrrrr get_temp_file sos_log_filerrrrrr=rr9r:rrrrJERRORrpsos_ui_log_filer)rV console_err ui_fhandlerr[r[r\rOsD           zSoSComponent._setup_loggingcCs |jSrh)r3newrkr[r[r\r zSoSComponent.get_temp_filecCs0d}d}|D] }|t||ddd}q|S)NPrF)replace_whitespacer) splitlinesr)rVrZwidth_fmtliner[r[r\_fmt_msgs  zSoSComponent._fmt_msg)rN)r)!__name__ __module__ __qualname____doc__descr rBr>rb root_requiredr<rr]r?rlr7rKrCr classmethodrrrArrrrrrrrOrrr[r[r[r\r sV8   <3  . r c@sVeZdZdZddZddZddZdd Zd d Zd d Z gfddZ dddZ dS)rDa8This class is used to record metadata from a sos execution that will then be stored as a JSON-formatted manifest within the final tarball. It can be extended by adding further instances of SoSMetadata to represent dict-like structures throughout the various sos bits that record to metadata cCs i|_dSrh_valuesrkr[r[r\r]rzSoSMetadata.__init__ccs |jD]}|dVqdS)Nr")rrrVitemr[r[r\__iter__s zSoSMetadata.__iter__cC |j|Srhrrr[r[r\ __getitem__rzSoSMetadata.__getitem__cCr rhr)rVattrr[r[r\ __getattr__rzSoSMetadata.__getattr__cCs||j|<dS)z@Add a key, value entry to the current metadata instance Nr)rV field_namecontentr[r[r\rPszSoSMetadata.add_fieldcCst|j|<|j|S)zCAdds a new instance of SoSMetadata to the current instance )rDr)rV section_namer[r[r\rUs  zSoSMetadata.add_sectioncCs t|ts td||j|<dS)zAdd a named list element to the current instance. If content is not supplied, then add an empty list that can alter be appended to zcontent added must be listN) isinstancer} TypeErrorr)rV list_namerr[r[r\add_lists zSoSMetadata.add_listNcCstj|dd|dS)zConvert contents of this SoSMetdata instance, and all other nested instances (sections), into a json-formatted output. Used to write manifest.json to the final archives. cSst|dt|S)Nr)rstr)rr[r[r\sz&SoSMetadata.get_json..)rindent)jsondumps)rVrr[r[r\get_json szSoSMetadata.get_jsonrh) rrrrr]r r r rPrUrrr[r[r[r\rDs rD)rrrErMr9r{textwraprargparserrrshutilrpathlibrrfr sos.archiver sos.optionsr sos.utilitiesr r r rDr[r[r[r\s*          D