Current File : //lib/python2.7/site-packages/progressbar/__init__.pyc
�
<ԭTc@ s�dZddlmZddlZddlZddlZddlZddlZy0ddlm	Z	ddl
m
Z
ddlZWnek
r�nXddl
TddlTdZdZd	Zd
Zddd��YZd
efd��YZdS(sMText progress bar library for Python.

A text progress bar is typically used to display the progress of a long
running operation, providing a visual cue that processing is underway.

The ProgressBar class manages the current progress, and the format of the line
is given by a number of widgets. A widget is an object that may display
differently depending on the state of the progress bar. There are three types
of widgets:
 - a string, which always shows itself

 - a ProgressBarWidget, which may return a different value every time its
   update method is called

 - 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. It will also
automatically enable features like auto-resizing when the system supports it.
i����(tdivisionN(tioctl(tarray(t*sNilton Volpatos$first-name dot last-name @ gmail.coms
2011-05-14s2.3t
UnknownLengthcB seZRS((t__name__t
__module__(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyRDstProgressBarcB s�eZdZd$ZdZdZe�de�gZd%d%d%de
ejd�Z
d�Zd�Zd�ZeZd�Zd%d%d�Zd�Zee�Zd�Zd�Zd�Zd �Zd%d!�Zd"�Zd#�ZRS(&s�The ProgressBar class which updates and prints the bar.

    A common way of using it is like:
    >>> pbar = ProgressBar().start()
    >>> for i in range(100):
    ...    # do something
    ...    pbar.update(i+1)
    ...
    >>> pbar.finish()

    You can also use a ProgressBar as an iterator:
    >>> progress = ProgressBar()
    >>> for i in progress(some_iterable):
    ...    # do something
    ...

    Since the progress bar is incredibly customizable you can specify
    different widgets of any type in any order. You can even write your own
    widgets! However, since there are already a good number of widgets you
    should probably play around with them before moving on to create your own
    widgets.

    The term_width parameter represents the current terminal width. If the
    parameter is set to an integer then the progress bar will use that,
    otherwise it will attempt to determine the terminal width falling back to
    80 columns if the width cannot be determined.

    When implementing a widget's update method you are passed a reference to
    the current progress bar. As a result, you have access to the
    ProgressBar's methods and attributes. Although there is nothing preventing
    you from changing the ProgressBar you should treat it as read only.

    Useful methods and attributes include (Public API):
     - currval: current progress (0 <= currval <= maxval)
     - maxval: maximum (and final) value
     - finished: True if the bar has finished (reached 100%)
     - start_time: the time when start() method of ProgressBar was called
     - seconds_elapsed: seconds elapsed since start_time and last call to
                        update
     - percentage(): progress in percent [0..100]
    tcurrvaltfdtfinishedtlast_update_timetleft_justifytmaxvaltnext_updatet
num_intervalstpolltseconds_elapsedt
signal_sett
start_timet
term_widthtupdate_intervaltwidgetst_time_sensitivet
__iterableidiPt icC s+|dkrt|j�}n||_||_||_||_t|_|dk	rc||_	nry@|j
�tjtj|j
�tj
tjt�t|_Wn/ttfk
r��n|j�|_	nXd|_|j�d|_t|_d|_||_d|_d|_d|_dS(s-Initializes a progress bar with sane defaultsiiN(tNonetlistt_DEFAULT_WIDGETSR
RR	RtFalseRRt_handle_resizetsignaltSIGWINCHtsiginterrupttTruet
SystemExittKeyboardInterruptt	_env_sizet_ProgressBar__iterablet_update_widgetsRR
RRRRR(tselfR
RRRRR	((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt__init__|s6					

	
						cC sKyt|�|_Wn"|jdkr8t|_q8nXt|�|_|S(s0Use a ProgressBar to iterate through an iterableN(tlenR
RRtiterR&(R(titerable((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt__call__�scC s|S(N((R(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt__iter__�scC slyGt|j�}|jdkr.|j�n|j|jd�|SWntk
rg|j��nXdS(Ni(	tnextR&RRtstarttupdateRt
StopIterationtfinish(R(tvalue((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt__next__�s


cC s ttjjd|j��dS(s2Tries to find the term_width from the environment.tCOLUMNSi(tinttostenvirontgett_DEFAULT_TERMSIZE(R(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyR%�scC s8tdt|jtjd��d \}}||_dS(s5Tries to catch resize signals sent from the terminal.thtiiNt(RRR	ttermiost
TIOCGWINSZR(R(tsignumtframeR<tw((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyR�s+cC s|jd|jS(s%Returns the progress as a percentage.gY@(RR
(R(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt
percentage�scC sg}g}|j}xxt|j�D]g\}}t|t�r`|j|�|jd|�q%t||�}|j|�|t|�8}q%Wt|�}xv|rt	t
tj|d|��d�}|j
�}|d8}||j||�}|t|�8}|||<q�W|S(Nig�?i(Rt	enumerateRt
isinstancetWidgetHFilltappendtinserttformat_updatableR*tmaxR7tmathtceiltpopR1(R(tresultt	expandingtwidthtindextwidgettcounttportion((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt_format_widgets�s&	

	&
cC sBdj|j��}|jr.|j|j�S|j|j�SdS(s(Joins the widgets and justifies the linetN(tjoinRVRtljustRtrjust(R(R((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt_format_line�s	cC sH|j|jks|jrtStj�|j}|joG||jkS(s7Returns whether the ProgressBar should redraw the line.(RRR
R"ttimeRRR(R(tdelta((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt_need_update�scC s td�|jD��|_dS(s-Checks all widgets for the time sensitive bitcs s!|]}t|dt�VqdS(tTIME_SENSITIVEN(tgetattrR(t.0RC((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pys	<genexpr>sN(tanyRR(R(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyR's	cC s�|dk	rb|tk	rb|jtk	rVd|koA|jknrVtd��n||_n|j�srdS|jdkr�td��ntj�}||j|_	|j|j
|_|jj
|j�d�||_dS(s'Updates the ProgressBar to a new value.isValue out of rangeNs-You must call "start" before calling "update"s
(RRR
t
ValueErrorRR^RtRuntimeErrorR\RRRR	twriteR[R(R(R4tnow((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyR1	s cC s�|jdkr|j|_ntd|j�|_d|_|jtk	r|jdkritd��n|j|j|_	nt
j
�|_|_|j
d�|S(sStarts measuring time, and prints the bar at 0%.

        It returns self so you can use it like this:
        >>> pbar = ProgressBar().start()
        >>> for i in range(100):
        ...    # do something
        ...    pbar.update(i+1)
        ...
        >>> pbar.finish()
        idisValue out of rangeN(R
Rt_DEFAULT_MAXVALRKRRRRRcRR\RRR1(R(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyR0 s	
cC sOt|_|j|j�|jjd�|jrKtjtjtj	�ndS(s/Puts the ProgressBar bar in the finished state.s
N(
R"R
R1R
R	ReRRR tSIG_DFL(R(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyR3=s
		(scurrvalsfdsfinishedslast_update_timesleft_justifysmaxvalsnext_updates
num_intervalsspollsseconds_elapseds
signal_sets
start_times
term_widthsupdate_intervalswidgetss_time_sensitives
__iterableN(RRt__doc__t	__slots__RgR;t
PercentagetBarRRR"tsyststderrR)R-R.R5R/R%RRDtpropertytpercentRVR[R^R'R1R0R3(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyRGs4)$	
		
								((Rit
__future__RRLR8RRmR\tfcntlRRR?tImportErrortprogressbar.compattprogressbar.widgetst
__author__t__author_email__t__date__t__version__RtobjectR(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt<module>)s(