
Tc           @   s  d  d l  Z  d  d l Z d  d l Z d  d l m Z m Z m Z m Z m Z d  d l	 m
 Z
 d  d l m Z m Z m Z d  d l m Z y d  d l Z d  d l Z Wn e k
 r e d  n Xe  j j   Z e Z d   Z d   Z d	 e f d
     YZ d   Z d e j f d     YZ d e f d     YZ  d e  f d     YZ! d e  f d     YZ" d e  f d     YZ# d e# f d     YZ$ d   Z% d   Z& e& Z' e& Z( e& Z) d e+ e+ d d d  Z, e- e+ d d  Z. d d e+ e+ d d d  Z/ d d e+ d d  Z0 d d  Z1 d d e+ d d e+ e+ d d  d! d d"  Z2 d e+ d d#  Z3 d d d d$  Z4 d e+ d d% d d&  Z5 d d e+ d d d% e+ d e+ d d e+ d'  Z6 d< d= d> d? d@ dA dB dC g Z7 d8   Z8 d9   Z9 d:   Z: e; d; k re:   n  d S(D   iN(   t   UINotImportablet	   NoPackaget   NoBugst	   NoNetworkt   NoReport(   t   launch_browser(   t   ewritet   spawn_editort   system(   t   VERSIONs>   Please install the python-urwid package to use this interface.c          C   s0   t  j j   }  |  j t  |  j d d  |  S(   Nt   max_waitg?(   t   urwidt   raw_displayt   Screent   register_palettet   palettet   set_input_timeouts(   t   ui(    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   initialize_urwid_ui4   s    c           C   s   d  S(   N(    (    (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   nullfunc<   s    t
   buttonpushc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyR   @   s   c         C   s   t  |  j  d  S(   N(   R   t   exitcode(   t   button(    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   button_pressC   s    t   SelectableTextc           B   s   e  Z d    Z RS(   c         C   s   t  S(   N(   t   False(   t   selft   ch(    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt
   valid_charG   s    (   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyR   F   s   t   dialogc           B   s_   e  Z d	 d	 d	 d  d  d  Z d e d  Z d   Z d   Z d   Z d   Z	 d	 d  Z
 RS(
   t    c   	   	   C   s  | |  _  t |  _ | s | r_ t d |  } | j d  t j | g  |  _  } t |  _ q t j t j	   d  |  _  } n  | s d } n  | s d } n  t j
 | d d |  _ | r t j t j |  t j	   g  |  j _ n  |  j } t j | d d  } t j | d d  } t j | d  } | r_t j
 |  } t j d | f  | _ n  t j | d d t j t j t j d  d  d  f g  } t j
 | d t j t j d  d  } t j | d |  } t j | d |  } t j | d  } | |  _ d  S(   Nt	   edit_texti    t   topt   relativeiP   t
   focus_partt   footers
   fixed lefti   s   fixed rights	   fixed topi   s   fixed bottomt   bodyt   titlet   fixedt   bordert    t   shadowt   centert   middle(   R#   iP   (   R#   iP   (   s
   fixed lefti   (   s   fixed righti   (   s	   fixed topi   (   s   fixed bottomi   (   R)   R*   (   R)   R*   (   R&   R   t
   scrollmodeR   t   set_edit_posR   t   ListBoxt   Truet   Fillert   Dividert   Framet   framet   Pilet   Textt   headert   Paddingt   AttrWrapt   Columnst   view(	   R   t   messageR&   t   widtht   heightR'   t   long_messaget   boxt   w(    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   __init__K   s<    		"			?*i    c   	      C   sb  g  } x | D]| \ } } | d k rI t  j |  } t  j | d  } n3 t  j | |  j  } | | _ t  j | d d  } | j |  q W| r t  j |  } | j | p d  t  j	 t  j | d   |  _
 t  j |  j
 t t |  d   |  j _ n^ t  j | d d d	 d
  |  _
 |  j
 j | p0d  t  j t  j   |  j
 g d d	 |  j _ d  S(   Ns   ---t   scrolllabelt
   selectablet   focusi    i
   i   i   i   R,   t
   focus_item(   R   R7   R:   t   ButtonR   R   t   appendR0   t	   set_focusR4   t   buttonst
   BoxAdaptert   mint   lenR5   R%   t   GridFlowR6   R3   (	   R   RK   t   defaultt   verticalt   lt   nameR   t   bRA   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   add_buttonsw   s$    	-c         C   s   t  | j  d  S(   N(   R   R   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyR      s    c   
   	   C   s>  |  j  j   } yx t r|  j j | d t } |  j  j | |  d  } x | sg |  j  j   } qO Wx | D] } t j	 j
 |  r | \ } } } } |  j j | | | | | d t n  | d k r |  j  j   } n  |  j j | |  } | ro |  j | |  qo qo Wq WWn$ t k
 r9}	 |  j |	 j d  SXd  S(   NRF   s   window resizei    (   R   t   get_cols_rowsR1   R<   t   rendert   draw_screent   Nonet	   get_inputR   t   utilt   is_mouse_eventt   mouse_eventt   keypresst   unhandled_keyR   t   on_exitt   args(
   R   t   sizet   canvast   keyst   kt   eventR   t   colt   rowt   e(    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   run   s*    		
c         C   s   | S(   N(    (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyR`      s    c         C   s   | d
 k rJ |  j  j } | d k r7 |  j  j d  qJ |  j  j d  n  | d k r |  j r |  j  j d  |  j j | |  q | d k r |  j  j d  q |  j  j d  n  | d	 k r |  j  j d  |  j j | |  n  d  S(   Nt   tabs	   shift tabR%   R&   t   ups   page upt   downs	   page downt   enter(   Rk   s	   shift tab(   Rl   s   page upRm   s	   page down(   Rl   s   page up(   R5   R$   RJ   R.   R&   R^   R<   (   R   Rb   Re   RF   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyR_      s    	c         C   s1   | r | |  _  n t   |  _  |  j  j |  j  S(   N(   R   R   t   run_wrapperRj   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   main   s    N(   R   R   RY   RC   R   RU   R   Rj   R`   R_   Rp   (    (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyR   J   s   	+				t
   displayboxc           B   s   e  Z d d   Z RS(   c         C   sv   | r | |  _  n t   |  _  |  j  j   } |  j j | d t } |  j  j   |  j  j | |  |  j  j   d  S(   NRF   (	   R   R   RV   R<   RW   R1   t   startRX   t   stop(   R   R   Rb   Rc   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   show   s    N(   R   R   RY   Rt   (    (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyRq      s   t	   textentryc           B   s)   e  Z d d e d  d  d  Z d   Z RS(   R    c         C   s   t  j d | d |  |  _ t  j |  j g  } t  j | d d  } | s t  j d d | f t  j   g  } t  j |  } n  t j	 |  | | | | |  |  j
 j d  d  S(   NR!   t	   multilineRE   t	   focustextR(   i   R&   (   R   t   Editt   editR0   R:   R6   R3   R2   R   RC   R5   RJ   (   R   t   textR>   R?   Rv   R'   R!   R&   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyRC      s    $c         C   s   | |  j  j   f S(   N(   Ry   t   get_edit_text(   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyR`      s    N(   R   R   RY   R   RC   R`   (    (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyRu      s   	t
   listdialogc           B   s)   e  Z e d d d  d d  Z d   Z RS(   R    i   c         C   s   g  } g  |  _  xy | D]q \ }	 }
 |  j  j |	  |
 re t j d | |	 f t j |
  g d  }	 n  t j |	 d d  }	 | j |	  q Wt j |  } t j | d  } t j |  | d | d | d | d | |  j	 j
 d  d  S(	   NR(   i   RE   RF   R?   R>   R&   R'   (   t   itemsRI   R   R;   R7   R:   R0   R   RC   R5   RJ   (   R   Rz   t   widgetst   has_defaultR>   R?   R'   t   buttonwidthRR   RB   t   labelt   lb(    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyRC      s    	!c         C   sY   | r | d f Sx< |  j D]1 } t | d  r | j   r | | j   f Sq W| d f S(   s#   Print the tag of the item selected.t	   get_stateN(   RY   R}   t   hasattrR   t	   get_label(   R   R   t   i(    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyR`      s    
N(   R   R   R   RY   RC   R`   (    (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyR|      s   t   checklistdialogc           B   s   e  Z d    Z RS(   c         C   sV   | r | g  f Sg  } x3 |  j  D]( } | j   r  | j | j    q  q  W| | f S(   s|   
        Mimick dialog(1)'s --checklist exit.
        Put each checked item in double quotes with a trailing space.
        (   R}   R   RI   R   (   R   R   RR   R   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyR`     s    
(   R   R   R`   (    (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyR     s   c         O   s   | r |  t  |  }  n  d | k r2 | d } n d } d | k rQ | d } n d  } t j d |   } g  | D]! } t j d d |  j   ^ qp } d j |  j   }  t d d |  d | p t } | j	 |  d  S(	   NR'   R    R   s   

+s   \s+R*   s   

R@   (
   t   tupleRY   t   ret   splitt   subt   stript   joinRq   R	   Rt   (   R=   Ra   t   kwargsR'   R   t   chunkst   xRA   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   display_message  s    .c         O   s   | r |  t  |  }  n  d | k r2 | d } n d } d | k rQ | d } n d  } t j d |   } g  | D]! } t j d d |  j   ^ qp } d j |  j   }  t d d |  d | p t } | j	 d g  | j
 |  d  S(   NR'   R    R   s   

+s   \s+R*   s   

R@   t   OKi    (   R   i    (   R   RY   R   R   R   R   R   R   R	   RU   Rp   (   R=   Ra   R   R'   R   R   R   RA   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyR@   *  s    .c         C   s   t  d d |  d d d | p t } | s3 i  } n  g  } d  }	 xZ t |  D]L \ }
 } | j   ry |
 }	 | j   } n  | j | j | |  | f  qL W| j | |	 d t	 | j
 |  } | S(	   NR    R@   R?   R#   iP   R'   RQ   (   s   relativeiP   (   R   R	   RY   t	   enumeratet   isuppert   lowerRI   t   getRU   R1   Rp   (   t   msgt   okt   helpt   allow_numberst   nowrapR   R'   RA   RK   RP   R   t   optiont   result(    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   select_optionsE  s    	#c         C   s^   t  d d |  d d t } | j d t f d t f g d d t |  | j |  } | S(	   NR    R@   t   ?R'   t   Yest   NoRP   i   (   R   R	   RU   R1   R   t   intRp   (   R   t   yeshelpt   nohelpRP   R   R   RA   R   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   yes_noX  s    /R    c   
      C   sf   | r d t  | f } n t  } t |  d | d | } | j d g  | j |  \ } }	 |	 pe | S(   Ns   %s: %sR'   R!   R   i    (   s   OKi    (   R	   Ru   RU   Rp   (
   t   promptt   optionsR'   t   empty_okt   force_promptRP   R   RA   t   codeRz   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt
   get_string^  s    c   	      C   si   | r d t  | f } n t  } t |  d t } | j d g  | j |  \ } } | j d  } | S(   Ns   %s: %sRv   R   i    s   
(   s   OKi    (   R	   Ru   R1   RU   Rp   R   (	   R   R   R'   R   R   RA   R   Rz   RR   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   get_multilinej  s    c         C   s   t  j  |   S(   N(   t   getpass(   R   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   get_passwordw  s    t   Okt   Cancelc      	   C   s  | s g  } n t  |  } | s* d } n  | rC d t | f } n t } t | t  r| j   } | r g  } x> | D]6 } | j |  rw | j | | | f  | | =qw qw W| j   } | j   x | D] } | j |  q W| } q| j   } | j   n  g  } xR | D]J \ } } | rK| j | t	 j
 d d |  f  q| j | | f  qW| } | rBg  | D]3 \ } } t j | d | | k | pd f ^ qu} t |  | d d d	 | } | r| j | d
 f | d f | d f g  n | j | d
 f | d f g  | j |
  \ } } | d
 k  r>g  S| Sd   } g  } g  } x | D] \ } } | d k rt j |  } t j | d  } d } nE t j | | | |  d | | k } | | _ t j | d d  } | j | | f  q^Wt |  | d d d	 | d d } | rN| j | d
 f | d f | d f g  n | j | d
 f | d f g  d
 } | rx7 t |  D]& \ } } | d
 | k r| } PqqWn  | j |
  \ } } | d
 k  r| S| S(   NR    s   %s: %ss   \s+R*   t   stateR?   R#   iP   R'   i    iic         S   s   |  S(   N(    (   R   t   desc(    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   label_button  s    s   ---RD   RE   RF   R   i   (   s   relativeiP   (   s   relativeiP   (   t   listR	   t
   isinstancet   dictt   copyt   has_keyRI   R}   t   sortR   R   R   t   CheckBoxR   RU   Rp   R7   R:   t   RadioButtonR   R|   R   (   t   parR   R   RP   R'   t   any_okt   ordert   extrast   multipleR   R   t   oklabelt   cancellabelt	   quitlabelt   olistt   keyR   t   optsR   R~   RA   R   t   chosenR   t   rlistRT   RF   R   t   opt(    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   menuz  s    		
	%=			'	
+c         C   s   t  |  d | d | d | S(   NR'   R   RP   (   R   (   R   R'   R   RP   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   get_filename  s    c         C   s.   t  |  | | d | d | d | d t d t S(   NR'   R   R   R   R   (   R   R1   R   (   R   R   R   R'   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   select_multiple  s    !t   noc
      
   C   s`  d d l  m }
 | } | s( t   } n  |
 j | } t d |  | d d | d | |
 j |  | | d | d | d	 | } | s t d
 |  d | d | d  St d d d d d d d d  } d } x | \ } } | d } t | | d | j	 d | d | } d  } | s| d k r Pn  | d k r0d S| d k r@| St |
 j | |  |   q d  S(   Ni(   t   debbugss4   Retrieving report #%d from %s bug tracking system...RS   R'   R   t   mirrorst
   http_proxyt   archiveds   Bug report #%d not found.t   oR   t   ds   More details (launch browser)t   ms   Submit more informationt   qt   Quitt   Odmqi    R   (   t	   reportbugR   R   t   SYSTEMSR   t
   get_reportR@   R   R   t   subjectRY   R   t   get_report_url(   t   numberR   R   R   t   timeoutt   screent	   queryonlyR'   R   t   mbox_reader_cmdR   R   t   sysinfot   infoR   t   validt   buginfot   bodiesR&   t   r(    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   show_report  s8    
$c   %      C   s  d d l  m } | j | } | j d  } | sG t d | d  d  S| } | s_ t   } n  t |  t  r |  } |	 r | d 7} n  t d | j | d | d | d	 | nI t d
 | j | d d j	 g  |  D] } t
 |  ^ q  d | d	 | d  } y`| j |  | | d | d |
 d | d | d |	 \ } } } | sp| j t  | d  k rgt  q_t  n| d k rd | f } n d | f } g  } x | D] \ } } t |  } | j d | f  i  } x@ | D]8 } d } | j d k rd } n  | j | | | j <qWt | j g  t | d | D] } t
 |  | | f ^ q6 qW| d d }  | rd }! d  }" n d }! d }" x t r^t d | d d | d	 | d |  d d  d! |! d" |" }# d  } |# d k  r!|# d k rd  } n+ |# d# k rt  n | j |# |  d } Pq|# }  t t |   | | | | d$ | }$ |$ r|$ } PqqWWnn t t f k
 r| j t  t  d% | d d	 | n4 t k
 r| j t  t  d& d	 | t  n X| rt | | j! j"  rt  n  | S('   Ni(   R   t   btsroots8   %s bug tracking system has no web URL; bypassing query.
RS   s	    (source)s1   Querying %s bug tracking system for reports on %sR   R'   s.   Querying %s bug tracking system for reports %sR*   R   t   versionR   R   t   sourcei   s   %d bug reports founds   %d bug report founds   ---R    t   dones     [RESOLVED]t   reversei    t   Exits   New bugR   sP   Select a bug to read (and possibly report more information) or report a new bug:RP   R   s   Read bugR   R   iR   s   Unable to connect to %s BTS.s    No record of this package found.(#   R   R   R   R   R   R   R   t
   basestringR   R   t   strRY   t   get_reportsRo   R   R   R   RN   RI   t   pendingR   t   bug_numt   mapt   sortedR1   R   R   R   R   R   t   IOErrorR   R@   t	   debianbtst	   Bugreport(%   t   packaget   btsR   R   R   R   R   R'   R   R   R   t   mboxt   buglistR   t   latest_firstR   R   t   rootR   t   pkgnameR   R   t   countt   sectitlet	   hierarchyt   tt   bugst   bcountt   buglist_tmpt   bugR   Re   t   pR   R   R   t   res(    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   handle_bts_query  s    5			C						

	R&   t   blacks
   light grayt   standoutR)   s	   dark blueR+   t   whiteRE   s	   dark cyanRF   t   boldRw   R'   s   dark redRD   c           C   s   t  S(   N(   R1   (    (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt
   initialize  s    c           C   s   t  j j   S(   N(   t   syst   stdint   isatty(    (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt	   can_input  s    c          C   s   d d  l  }  t j } t d  |  j d  g  t j j   D] } | d f ^ q< } | j   t	 d | d d d d	 t
 } | | IJd d  l } | j   } t d
 | d  } | | IJd  S(   NisD   This is a test.  This is only a test.
Please do not adjust your set.i   R    s   Choose a mailer for your reports   Select mailer: RP   t   muttR   s-   Do any of the following apply to this report?s   Please select tags: (   t   timeR  t   stdoutR@   t   sleepR   t   MUARd   R   R   R1   R   t   get_tagsR   (   R  t   fpR   t   mailerst   mailerR   t   tagst   taglist(    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   test  s    	
(
	
	t   __main__(   s   bodyR  s
   light grayR  (   s   borderR  s	   dark blue(   s   shadowR  R  (   s
   selectableR  s	   dark cyan(   s   focusR  s	   dark blueR  (   s	   focustexts
   light grays	   dark blue(   s   titles   dark reds
   light gray(   s   scrolllabelR  s	   dark cyan(<   R  R   R   t   reportbug.exceptionsR    R   R   R   R   t   reportbug.urlutilsR   t   text_uiR   R   R   R   R	   t   urwid.raw_displayR   t   ImportErrorR  R  t   ISATTYt   log_messageR   R   t	   ExceptionR   R   Rx   R   t   objectR   Rq   Ru   R|   R   R   R@   t   final_messaget   display_reportt   display_failureRY   R   R   R1   R   R   R   R   R   R   R   R   R
  R   R  R  R  R   (    (    (    s9   /usr/lib/python2.7/dist-packages/reportbug/ui/urwid_ui.pyt   <module>   sx   (								g	%n				 