Ñò
ú†]Dc           @   sÄ  d  Z  d Z d Z d Z d Z d d k Z d d k Z d d k l Z y  d d k l	 Z	 d d k
 Z
 Wn e j
 o n Xd d k Z 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 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e ƒ  d e ƒ  g Z d e f d „  ƒ  YZ e d j oP d d k Z d „  Z d „  Z d „  Z d  „  Z e ƒ  e ƒ  e ƒ  e ƒ  n d S(!   sF  Text progressbar library for python.

This library provides a text mode progressbar. This is tipically used
to display the progress of a long running operation, providing a
visual clue that processing is underway.

The ProgressBar class manages the progress, and the format of the line
is given by a number of widgets. A widget is an object that may
display diferently depending on the state of the progress. There are
three types of widget:
- a string, which always shows itself;
- a ProgressBarWidget, which may return a diferent value every time
it's update method is called; and
- a ProgressBarWidgetHFill, which is like ProgressBarWidget, except it
expands to fill the remaining width of the line.

The progressbar module is very easy to use, yet very powerful. And
automatically supports features like auto-resizing when available.
s   Nilton Volpatos$   first-name dot last-name @ gmail.coms
   2006-05-07s   2.2iÿÿÿÿN(   t   array(   t   ioctlt   ProgressBarWidgetc           B   s   e  Z d  Z d „  Z RS(   s   This is an element of ProgressBar formatting.

    The ProgressBar object will call it's update value when an update
    is needed. It's size may change between call, but the results will
    not be good if the size changes drastically and repeatedly.
    c         C   s   d S(   s  Returns the string representing the widget.

        The parameter pbar is a reference to the calling ProgressBar,
        where one can access attributes of the class for knowing how
        the update must be made.

        At least this function must be overriden.N(    (   t   selft   pbar(    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyt   updateI   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR   B   s   t   ProgressBarWidgetHFillc           B   s   e  Z d  Z d „  Z RS(   sf  This is a variable width element of ProgressBar formatting.

    The ProgressBar object will call it's update value, informing the
    width this object must the made. This is like TeX \hfill, it will
    expand to fill the line. You can use more than one in the same
    line, and they will all have the same width, and together will
    fill the line.
    c         C   s   d S(   s[  Returns the string representing the widget.

        The parameter pbar is a reference to the calling ProgressBar,
        where one can access attributes of the class for knowing how
        the update must be made. The parameter width is the total
        horizontal width the widget must have.

        At least this function must be overriden.N(    (   R   R   t   width(    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR   \   s    	(   R   R   R   R   (    (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR	   S   s   t   ETAc           B   s    e  Z d  Z d „  Z d „  Z RS(   s(   Widget for the Estimated Time of Arrivalc         C   s   t  i d t  i | ƒ ƒ S(   Ns   %H:%M:%S(   t   timet   strftimet   gmtime(   R   t   seconds(    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyt   format_timej   s    c         C   sj   | i  d j o d S| i o d |  i | i ƒ S| i } | | i | i  | } d |  i | ƒ Sd  S(   Ni    s   ETA:  --:--:--s   Time: %ss   ETA:  %s(   t   currvalt   finishedR   t   seconds_elapsedt   maxval(   R   R   t   elapsedt   eta(    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR   l   s    
	(   R   R   R   R   R   (    (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR   h   s   	t   FileTransferSpeedc           B   s    e  Z d  Z d „  Z d „  Z RS(   sB   Widget for showing the transfer speed (useful for file transfers).c         C   s(   d |  _  d d d d d d g |  _ d  S(   Ns   %6.2f %st   Bt   Kt   Mt   Gt   Tt   P(   t   fmtt   units(   R   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyt   __init__x   s    	c         C   s{   | i  d j  o
 d } n t | i ƒ | i  } | } x- |  i D]" } | d j  o Pn | d :} q@ W|  i | | d f S(   Ngíµ ÷ÆÀ>g        iè  s   /s(   R   t   floatR   R   R   (   R   R   t   bpst   spdt   u(    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR   {   s    

 (   R   R   R   R    R   (    (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR   v   s   	t   RotatingMarkerc           B   s#   e  Z d  Z d d „ Z d „  Z RS(   s2   A rotating marker for filling the bar of progress.s   |/-\c         C   s   | |  _  d |  _ d  S(   Niÿÿÿÿ(   t   markerst   curmark(   R   R&   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR    ‰   s    	c         C   sA   | i  o |  i d S|  i d t |  i ƒ |  _ |  i |  i S(   Ni    i   (   R   R&   R'   t   len(   R   R   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR   Œ   s    
(   R   R   R   R    R   (    (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR%   ‡   s   t
   Percentagec           B   s   e  Z d  Z d „  Z RS(   s   Just the percentage done.c         C   s   d | i  ƒ  S(   Ns   %3d%%(   t
   percentage(   R   R   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR   ”   s    (   R   R   R   R   (    (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR)   ’   s   t   Barc           B   s2   e  Z d  Z d d d d „ Z d „  Z d „  Z RS(   s5   The bar of progress. It will strech to fill the line.t   #t   |c         C   s   | |  _  | |  _ | |  _ d  S(   N(   t   markert   leftt   right(   R   R.   R/   R0   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR    ™   s    		c         C   s5   t  |  i t t f ƒ o |  i S|  i i | ƒ Sd  S(   N(   t
   isinstanceR.   t   strt   unicodeR   (   R   R   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyt   _format_marker   s    c         C   st   | i  ƒ  } | t |  i ƒ t |  i ƒ } t | | d ƒ } |  i | ƒ } |  i | | i | ƒ |  i } | S(   Nid   (   R*   R(   R/   R0   t   intR4   t   ljust(   R   R   R
   t   percentt   cwidtht   marked_widtht   mt   bar(    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR   ¢   s     !(   R   R   R   R    R4   R   (    (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR+   —   s   	t
   ReverseBarc           B   s   e  Z d  Z d „  Z RS(   s2   The reverse bar of progress, or bar of regress. :)c         C   st   | i  ƒ  } | t |  i ƒ t |  i ƒ } t | | d ƒ } |  i | ƒ } |  i | | i | ƒ |  i } | S(   Nid   (   R*   R(   R/   R0   R5   R4   t   rjust(   R   R   R
   R7   R8   R9   R:   R;   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR   ¬   s     !(   R   R   R   R   (    (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR<   ª   s   t    t   ProgressBarc           B   sn   e  Z d  Z d e d e i d „ Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z RS(   só  This is the ProgressBar class, it updates and prints the bar.

    The term_width parameter may be an integer. Or None, in which case
    it will try to guess it, if it fails it will default to 80 columns.

    The simple use is like this:
    >>> pbar = ProgressBar().start()
    >>> for i in xrange(100):
    ...    # do something
    ...    pbar.update(i+1)
    ...
    >>> pbar.finish()

    But anything you want to do is possible (well, almost anything).
    You can supply different widgets of any type in any order. And you
    can even write your own widgets! There are many widgets already
    shipped and you should experiment with them.

    When implementing a widget update method you may access any
    attribute or function of the ProgressBar object calling the
    widget's update method. The most important attributes you would
    like to access are:
    - currval: current value of the progress, 0 <= currval <= maxval
    - maxval: maximum (and final) value of the progress
    - finished: True if the bar is have finished (reached 100%), False o/w
    - start_time: first time update() method of ProgressBar was called
    - seconds_elapsed: seconds elapsed since start_time
    - percentage(): percentage of the progress (this is a method)
    id   c         C   sÉ   | d j p t  ‚ | |  _ | |  _ | |  _ t |  _ | d  j oJ y3 |  i d  d  ƒ t i t i	 |  i ƒ t
 |  _ Wq˜ d |  _ q˜ Xn
 | |  _ d |  _ t |  _ d |  _ d  |  _ d |  _ d  S(   Ni    iO   iÿÿÿÿ(   t   AssertionErrorR   t   widgetst   fdt   Falset
   signal_sett   Nonet   handle_resizet   signalt   SIGWINCHt   Truet
   term_widthR   R   t   prev_percentaget
   start_timeR   (   R   R   RA   RJ   RB   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR    Ó   s$    									c         C   s8   t  d t |  i t i d ƒ ƒ d  \ } } | |  _ d  S(   Nt   ht    i   i   t           (   R    R   RB   t   termiost
   TIOCGWINSZRJ   (   R   t   signumt   frameRM   t   w(    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyRF   ê   s    +c         C   s   |  i  d |  i S(   s'   Returns the percentage of the progress.g      Y@(   R   R   (   R   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR*   î   s    c   	      C   s  g  } g  } d } d } x¸ t  |  i ƒ D]§ \ } } t | t ƒ o( | i | ƒ | i | ƒ | d 7} q( t | t t f ƒ o! | i | ƒ | t | ƒ 7} q( | i |  ƒ } | t | ƒ 7} | i | ƒ q( Wx3 | D]+ } | | i |  |  i	 | | ƒ | | <qÚ W| S(   Ni    i   (
   t	   enumerateRA   R1   R	   t   appendR2   R3   R(   R   RJ   (	   R   t   rt
   hfill_indst	   num_hfillt	   currwidtht   iRT   t   wevalt   iw(    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyt   _format_widgetsò   s(      )c         C   s   d i  |  i ƒ  ƒ i |  i ƒ S(   Nt    (   t   joinR^   R6   RJ   (   R   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyt   _format_line  s    c         C   s   t  |  i ƒ  ƒ t  |  i ƒ j S(   N(   R5   R*   RK   (   R   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyt   _need_update
  s    c         C   så   d | j o |  i  j n p t ‚ | |  _ |  i ƒ  p
 |  i o d S|  i p t i ƒ  |  _ n t i ƒ  |  i |  _ |  i ƒ  |  _	 | |  i  j o |  i
 i |  i ƒ  d ƒ n$ t |  _ |  i
 i |  i ƒ  d ƒ d S(   s(   Updates the progress bar to a new value.i    Ns   s   
(   R   R@   R   Rb   R   RL   R   R   R*   RK   RB   t   writeRa   RI   (   R   t   value(    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR     s    (	
	c         C   s   |  i  d ƒ |  S(   s  Start measuring time, and prints the bar at 0%.

        It returns self so you can use it like this:
        >>> pbar = ProgressBar().start()
        >>> for i in xrange(100):
        ...    # do something
        ...    pbar.update(i+1)
        ...
        >>> pbar.finish()
        i    (   R   (   R   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyt   start  s    c         C   s8   |  i  |  i ƒ |  i o t i t i t i ƒ n d S(   s&   Used to tell the progress is finished.N(   R   R   RD   RG   RH   t   SIG_DFL(   R   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyt   finish+  s    
N(   R   R   R   t   default_widgetsRE   t   syst   stderrR    RF   R*   R^   Ra   Rb   R   Re   Rg   (    (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR?   µ   s   								t   __main__c          C   s‰   d t  ƒ  d t d t ƒ  ƒ d t ƒ  d t ƒ  g }  t d |  d d ƒ i ƒ  } x) t d ƒ D] } | i d | d	 ƒ q[ W| i	 ƒ  Hd  S(
   Ns   Test: R>   R.   RA   R   i€–˜ i@B i
   i   (
   R)   R+   R%   R   R   R?   Re   t   rangeR   Rg   (   RA   R   R[   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyt   example19  s     
c          C   s—   d t  f d „  ƒ  Y}  |  ƒ  d t ƒ  d t ƒ  d t ƒ  g } t d | d d ƒ } | i ƒ  x) t d	 ƒ D] } | i d
 | d ƒ qi W| i ƒ  Hd  S(   Nt   CrazyFileTransferSpeedc           B   s   e  Z d  Z d „  Z RS(   s%   It's bigger between 45 and 80 percentc         S   sM   d | i  ƒ  j  o
 d j  n o d t i |  | ƒ St i |  | ƒ Sd  S(   Ni-   iP   s   Bigger Now (   R*   R   R   (   R   R   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyR   F  s    $(   R   R   R   R   (    (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyRn   D  s   s    <<<s   >>> R>   RA   R   i€–˜ i€„ i   i   (	   R   R+   R)   R   R?   Re   Rl   R   Rg   (   Rn   RA   R   R[   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyt   example2C  s    '
 
c          C   sz   t  d ƒ d t ƒ  d t d ƒ g }  t d |  d d ƒ i ƒ  } x) t d ƒ D] } | i d | d	 ƒ qL W| i ƒ  Hd  S(
   Nt   >R>   t   <RA   R   i€–˜ i@B i
   i   (   R+   R   R<   R?   Re   Rl   R   Rg   (   RA   R   R[   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyt   example3V  s    $ 
c       
   C   s¡   d t  ƒ  d t d d d d d d ƒ d t ƒ  d t ƒ  g }  t d	 |  d
 d ƒ } | i ƒ  x4 t d d d ƒ D]  } t i d ƒ | i	 | ƒ qn W| i
 ƒ  Hd  S(   Ns   Test: R>   R.   t   0R/   t   [R0   t   ]RA   R   iô  id   i   i2   gš™™™™™É?iõ  (   R)   R+   R   R   R?   Re   Rl   R   t   sleepR   Rg   (   RA   R   R[   (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyt   example4_  s    
 
(   R   t
   __author__t   __author_email__t   __date__t   __version__Ri   R   R    t   fcntlR   RP   t   ImportErrorRG   t   objectR   R	   R   R   R%   R)   R+   R<   Rh   R?   R   t   osRm   Ro   Rr   Rw   (    (    (    sJ   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\progressbar.pyt   <module>(   s@   
	
				