
                            d Z ddlmZ ddlmZ ddlm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 ddlmZ ddlZddlmZ dZdZdj3                  ee      Zdj3                  e
j6                        Zd Zd Z ej>                  ej@                  jB                         G d dejD                               Z#y)a  Command to assist user in submitting feedback about gcloud.

Does one of two things:

1. If invoked in the context of a recent gcloud crash (i.e. an exception that
was not caught anywhere in the Cloud SDK), will direct the user to the Cloud SDK
bug tracker, with a partly pre-filled form.

2. Otherwise, directs the user to either the Cloud SDK bug tracker,
StackOverflow, or the Cloud SDK groups page.
    )absolute_import)division)unicode_literalsN)base)feedback_util)info_holder)log)
console_io)files)text)mapz0http://stackoverflow.com/questions/tagged/gcloudzChttps://groups.google.com/forum/?fromgroups#!forum/google-cloud-deva  
We appreciate your feedback.

If you have a question, post it on Stack Overflow using the "gcloud" tag at
[{0}].

For general feedback, use our groups page
[{1}],
send a mail to [google-cloud-dev@googlegroups.com] or visit the [#gcloud] IRC
channel on freenode.
zaWould you like to file a bug using our issue tracker site at [{0}] (will open a new browser tab)?c                 6   |r:|j                   s.t        j                  dj                  |j                               t        j                  t        j                  d      j                  t        t        t        j                               t        j                         }t        j                  |       |r+|j                   rt        j                  |j                          t        j                  | j                                t        j                  |       y)zPrint message referring to various feedback resources for quiet execution.

  Args:
    info_str: str, the output of `gcloud info`
    log_data: info_holder.LogData, log data for the provided log file
  zHPlease consider including the log file [{0}] in any feedback you submit.a  
      If you have a question, post it on Stack Overflow using the "gcloud" tag
      at [{0}].

      For general feedback, use our groups page
      [{1}],
      send a mail to [google-cloud-dev@googlegroups.com], or visit the [#gcloud]
      IRC channel on freenode.

      If you have found a bug, file it using our issue tracker site at
      [{2}].

      Please include the following information when filing a bug report:      N)	tracebackr	   PrintformatfilenametextwrapdedentSTACKOVERFLOW_URLGROUPS_PAGE_URLr   ISSUE_TRACKER_URL
GetDividerstrip)info_strlog_datadividers      lib/surface/feedback.py_PrintQuietr   H   s     	ii ()/0A0A)BD ))HOO 
  6#_1134  $$&'))G($$IIh  !))HNN))G    c                     t        j                         j                         } | rft        j                  j	                         fd}t        j                  t        t        ||             dgz   dd      }|t        |       k  r| |   S y y )Nc                     | j                   rdnd}d}| j                  r%t        j                  | j                  z
        dz   }dj	                  | j
                  ||      S )Nz (crash detected) zUnknown timez agoz[{0}]{1}: {2})r   date	text_utilPrettyTimeDeltar   command)runcrashtimenows      r   _FormatLogDataz1_SuggestIncludeRecentLogs.<locals>._FormatLogDatap   sS    %(]]!ed	((sxx86A##CKK==r   zNone of theser   zjWhich recent gcloud invocation would you like to provide feedback about? This will open a new browser tab.)defaultmessage)
r   LogsInfoGetRecentRunsdatetimer*   r
   PromptChoicelistr   len)recent_runsr+   idxr*   s      @r   _SuggestIncludeRecentLogsr6   l   s    $$&446+





!C> 
!
!S-./1BBAEGC S  r   c                   F    e Zd ZdZddiZej                  Zed        Z	d Z
y)Feedbacka  Provide feedback to the Google Cloud CLI team.

  The Google Cloud CLI team offers support through a number of channels:

  * Google Cloud CLI Issue Tracker
  * Stack Overflow "#gcloud" tag
  * google-cloud-dev Google group

  This command lists the available channels and facilitates getting help through
  one of them by opening a web browser to the relevant page, possibly with
  information relevant to the current install and configuration pre-populated in
  form fields on that page.
  EXAMPLESa  
          To send feedback, including the log file for the most recent command,
          run:

            $ {command}

          To send feedback with a previously generated log file named
          'my-logfile', run:

            $ {command} --log-file=my-logfile
          c                 *    | j                  dd       y )Nz
--log-filez-Path to the log file from a prior gcloud run.)help)add_argument)parsers    r   ArgszFeedback.Args   s    
<  >r   c                 v   t        j                  t        j                               }d }|j                  r*	 t         j                  j                  |j                        }|j                  r t        t        j                  |      |       y t        j                  j!                  t"               |s
t%               }|st'        j(                  d      rt+        j,                  ||       y y # t        j                  $ r9}t        j                  dj                  |j                  |             Y d }~d }~ww xY w)N)
anonymizerz,Error reading the specified file [{0}]: {1}
zXNo invocation selected. Would you still like to file a bug (will open a new browser tab))prompt_string)r   
InfoHolder
Anonymizerlog_fileLogDataFromFiler   Errorr	   warningr   quietr   six	text_typestatusr   FEEDBACK_MESSAGEr6   r
   PromptContinuer   OpenNewIssueInBrowser)selfargsinfor   errs        r   RunzFeedback.Run   s    !![-C-C-EFDH}}8&&//> zz#--%x0	jj'(,.	Z..?A 	++D(;A [[ 8 "F4==#6	8 	88s   )C, ,D8?/D33D8N)__name__
__module____qualname____doc__detailed_helpr   SDK_TOOLS_CATEGORYcategorystaticmethodr>   rT    r   r   r8   r8   ~   s<      
- $$(> >
<r   r8   )$rX   
__future__r   r   r   r0   r   googlecloudsdk.callioper   googlecloudsdk.command_libr   r   googlecloudsdk.corer	   googlecloudsdk.core.consoler
   googlecloudsdk.core.utilr   r   r$   rJ   	six.movesr   r   r   r   rM   r   FEEDBACK_PROMPTr   r6   ReleaseTracksReleaseTrackGACommandr8   r]   r   r   <module>rj      s    
 '  '   ( 4 2 # 2 * 6 
  G & Fo.  F=**+ !H$ D%%(()7<t|| 7< *7<r   