o .&aj<@sddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZGdddeZGdd d eZGd d d eZGd d d e ZdS)N)COLORAMA_KWARGS)six)HistorySubcommand) RegexFilterc@s.eZdZd ddZddZddZdd ZdS) FormatterNcCs8||_|jdur tj|_|r|rtd||_||_dS)a#Formats and outputs CLI history events :type output: File-like obj :param output: The stream to write the formatted event to. By default sys.stdout is used. :type include: list :param include: A filter specifying which event to only be displayed. This parameter is mutually exclusive with exclude. :type exclude: list :param exclude: A filter specifying which events to exclude from being displayed. This parameter is mutually exclusive with include. Nz4Either input or exclude can be provided but not both)_outputsysstdout ValueError_include_exclude)selfoutputincludeexcluderD/usr/lib/python3/dist-packages/awscli/customizations/history/show.py__init__s  zFormatter.__init__cCs||r ||dSdS)zDisplays a formatted version of the event record :type event_record: dict :param event_record: The event record to format and display. N)_should_display_displayr event_recordrrrdisplay5s zFormatter.displaycCstd)Nz _display())NotImplementedErrorrrrrr>szFormatter._displaycCs,|jr |d|jvS|jr|d|jvSdS)N event_typeT)r r rrrrrAs zFormatter._should_display)NNN)__name__ __module__ __qualname__rrrrrrrrrs   rc s@eZdZeddZdddigddddigid d d d d dd ddddgddddd ddd dddegdddddgdddd d ddddddddgdd!d"dd#gdd$dd%igdd&Zejjej j d'Z d@fd*d+ Z d,d-Z d.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;ZdAdd?ZZS)BDetailedFormatterz#Signature=([a-z0-9]{4})[a-z0-9]{60}zSignature=\1...zAWS CLI command entered descriptionzwith AWS CLI version)titlevaluesr!zwith argumentsz API call madez to serviceservice)r payload_keyzusing operation operationzwith parametersparams dictionary)rr# value_formatzHTTP request sentzto URLurlz with methodmethodz with headersheaders)rr#r'filtersz with bodybody http_bodyzHTTP response receivedzwith status code status_codezHTTP response parsedz parsed to)rr'zAWS CLI command exitedzwith return code) CLI_VERSION CLI_ARGUMENTSAPI_CALL HTTP_REQUEST HTTP_RESPONSEPARSED_RESPONSECLI_RC)r rNTcsLtt||||i|_d|_||_t|_|jr$tj dit dSdS)Nrr) superrr_request_id_to_api_num_num_api_calls _colorizeSectionValuePrettyFormatter_value_pformattercoloramainitr)r rrrcolorize __class__rrrszDetailedFormatter.__init__cCs,|j|d}|dur|||dSdS)Nr) _SECTIONSget_display_section)r rsection_definitionrrrrszDetailedFormatter._displaycCs6d|vr ||d||dD]}|||qdS)Nr r!)_display_title_display_value)r rrDvalue_definitionrrrrCs  z"DetailedFormatter._display_sectioncCs|||}||dSN)_format_section_title _write_output)r r rformatted_titlerrrrEs z DetailedFormatter._display_titlecCsx|d}|d}|}d|vr||d}||}|||||d7}d|vr5|dD]}||}q-||dS)Nrpayloadr#r'r+)_format_description _format_valuerB filter_textrJ)r rGrvalue_descriptionevent_record_payloadvalueformatted_value text_filterrrrrFs     z DetailedFormatter._display_valuecCs&t|tjr |d}|j|dS)Nzutf-8) isinstancer text_typeencoderwrite)r contentrrrrJs  zDetailedFormatter._write_outputcCsd|}||}|durd||}||d}|d7}|d}||j|d|dd7}d||S)Nz[%s] r  zat time timestamp)r') _get_api_num_color_if_configuredrMrN)r r rrKapi_numformatted_timestamprrrrIs      z'DetailedFormatter._format_section_titlecCs>|d}|r||jvr|j|j|<|jd7_|j|SdS)N request_id)r7r8)r rr`rrrr\s  zDetailedFormatter._get_api_numcCs||ddS)Nz: r)r])r rPrrrrMsz%DetailedFormatter._format_descriptioncCs,|r|j|||}|dSt|}|dS)NrZ)r;pformatstr)r rRrr'rSrrrrNszDetailedFormatter._format_valuecCs$|jr|j|}||tjjS|SrH)r9_COMPONENT_COLORSr<Style RESET_ALL)r text componentcolorrrrr]s z&DetailedFormatter._color_if_configured)NNNTrH)rrrr _SIG_FILTERrAr<reBRIGHTForeCYANrdrrrCrErFrJrIr\rMrNr] __classcell__rrr?rrJs \  rc@sXeZdZddZdddZdddZdd Zd d Zd d ZddZ ddZ ddZ dS)r:cCst|d|||S)N _pformat_)getattr)r rRr'rrrrrbsz#SectionValuePrettyFormatter.pformatNcCstj|ddddS)Ng@@z%Y-%m-%d %H:%M:%S.%f)datetime fromtimestampstrftime)r event_timestamprrrr_pformat_timestamp s  z.SectionValuePrettyFormatter._pformat_timestampcCstj|dddS)NT)obj sort_keysindent)jsondumps)r rxrrrr_pformat_dictionarysz/SectionValuePrettyFormatter._pformat_dictionarycCsH|sdS|dddrdS||r||S||r"||S|S)NzThere is no associated bodyrL streamingFz.The body is a stream and will not be displayed)rB_is_xml_get_pretty_xml_is_json_structure_get_pretty_json)r r,rrrr_pformat_http_bodys    z.SectionValuePrettyFormatter._pformat_http_bodycCs&||}tjj|}|jdddS)Nz rZ)rznewl)_strip_whitespacexmldomminidom parseString toprettyxml)r r, stripped_bodyxml_domrrrr#s z+SectionValuePrettyFormatter._get_pretty_xmlcCst|}||SrH)r{loadsr})r r,rxrrrr.s  z,SectionValuePrettyFormatter._get_pretty_jsoncCs0z tjj|WdStjjjyYdSw)NFT)rrrrparsersexpat ExpatErrorr r,rrrr4s z#SectionValuePrettyFormatter._is_xmlcCs*tjj|}ddd|DS)NcSsg|]}|qSr)strip).0linerrr >szASectionValuePrettyFormatter._strip_whitespace..)rrrrjointoxml splitlines)r xml_stringrrrrr;sz-SectionValuePrettyFormatter._strip_whitespacecCs8|drzt|WdStjjyYdSwdS)N{TF) startswithr{rdecoderJSONDecodeErrorrrrrrAs  z.SectionValuePrettyFormatter._is_json_structurerH) rrrrbrvr}rrrrrrrrrrr:s    r:c@sreZdZdZdZdeiZdddddd d d d d dd dd dedddgZddZ ddZ ddZ ddZ dS) ShowCommandshowzShows the various events related to running a specific CLI command. If this command is ran without any positional arguments, it will display the events for the last CLI command ran.detailed command_id?latestTzuThe ID of the CLI command to show. If this positional argument is omitted, it will show the last the CLI command ran.)namenargsdefaultpositional_arg help_textr+zSpecifies which events to **only** include when showing the CLI command. This argument is mutually exclusive with ``--exclude``.)rrrrzwSpecifies which events to exclude when showing the CLI command. This argument is mutually exclusive with ``--include``.formataESpecifies which format to use in showing the events for the specified CLI command. The following formats are supported:
  • detailed - This the default format. It prints out a detailed overview of the CLI command ran. It displays all of the key events in the command lifecycle where each important event has a title and its important values underneath. The events are ordered by timestamp and events of the same API call are associated together with the [``api_id``] notation where events that share the same ``api_id`` belong to the lifecycle of the same API call.
)rchoicesrrcCs|z;|||}||||}||D]}||qWdn1s-wYW|dSW|dS|w)Nr)_connect_to_history_db_validate_args_get_output_stream_get_formatter_get_record_iteratorr_close_history_db)r parsed_argsparsed_globals output_stream formatterrecordrrr _run_mainys"    zShowCommand._run_maincCs|jr |jr tddSdS)Nz:Either --exclude or --include can be provided but not both)rrr r rrrrrs zShowCommand._validate_argscCs@|j}|j|j|d}|dkr|||d<|j|di|S)N)rrrrr>r)rrr_should_use_color FORMATTERS)r rrr format_typeformatter_kwargsrrrrszShowCommand._get_formattercCs"|jdkr |jS|j|jS)Nr)r _db_readeriter_latest_records iter_recordsrrrrrs  z ShowCommand._get_record_iteratorN) rrrNAME DESCRIPTIONrrkeys ARG_TABLErrrrrrrrrKs2$  r)rrr{rxml.parsers.expatrxml.dom.minidomr< awscli.tabler awscli.compatr&awscli.customizations.history.commandsr%awscli.customizations.history.filtersrobjectrrr:rrrrrs     /=E