
    AIdL                        d Z ddlmZ ddlmZ ddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZ	 ddlmZ n$# e$ r 	 ddlmZ n# e$ r	 ddlmZ Y nw xY wY nw xY wddlZdZdadadZd	 Zd
 Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(dZ)d Z* G d de+          Z,d Z-d Z.d Z/d Z0d  Z1d! Z2d" Z3d)d$Z4d% Z5d*d&Z6e7d'k    r e6ej8        d(d                    dS dS )+a8  
Basic tools for working with LMDB.

    copy: Consistent high speed backup an environment.
        %prog copy -e source.lmdb target.lmdb

    copyfd: Consistent high speed backup an environment to stdout.
        %prog copyfd -e source.lmdb > target.lmdb/data.mdb

    drop: Delete one or more sub-databases.
        %prog drop db1

    dump: Dump one or more databases to disk in 'cdbmake' format.
        Usage: dump [db1=file1.cdbmake db2=file2.cdbmake]

        If no databases are given, dumps the main database to 'main.cdbmake'.

    edit: Add/delete/replace values from a database.
        %prog edit --set key=value --set-file key=/path \
                   --add key=value --add-file key=/path/to/file \
                   --delete key

    get: Read one or more values from a database.
        %prog get [<key1> [<keyN> [..]]]

    readers: Display readers in the lock table
        %prog readers -e /path/to/db [-c]

        If -c is specified, clear stale readers.

    restore: Read one or more database from disk in 'cdbmake' format.
        %prog restore db1=file1.cdbmake db2=file2.cdbmake

        The special db name ":main:" may be used to indicate the main DB.

    rewrite: Re-create an environment using MDB_APPEND
        %prog rewrite -e src.lmdb -E dst.lmdb [<db1> [<dbN> ..]]

        If no databases are given, rewrites only the main database.

    shell: Open interactive console with ENV set to the open environment.

    stat: Print environment statistics.

    warm: Read environment into page cache sequentially.

    watch: Show live environment statistics
    )absolute_import)with_statementN)BytesIO)StringIOi   zutf-8c                      t                                          dt                    |                               t                    S )zlGiven either a Python 2.x or 3.x str, return either a str (Python 2.x)
    or a bytes instance (Python 3.x).unicode)globalsgetstrencodeENCODING)ss    )lib/python3.11/site-packages/lmdb/tool.py	_to_bytesr   k   s4     )799==C((++228<<<    c                 D    | t           j        v ot          |           dk    S )zReturn ``True`` if the character `c` can be printed visibly and without
    adversely affecting printing position (e.g. newline).   )string	printableord)cs    r   isprintr   q   s!       0SVVb[0r   c           	         t                      }t          d          }t          |           D ]I\  }}t          j        d         dk    rt          |          }|dz  s|rY|                    t          d                     |                    |           |                    t          d                     |                    t          d|z                       t          d          }|dz  s"|                    t          d	                     |                    t          d
t          |          fz                       |t          |          rt          |          nt          d          z  }K|dz  rd|dz  z
  }|                    t          d          |z             |                    t          d	          |dz  z             |                    t          d                     |                    |           |                    t          d                     |	                                
                    t                    S )zQReturn a vaguely /usr/bin/xxd formatted representation of the bytestring
    `s`. r      r   z  
z%07x:    z%02x.   )r   r   	enumeratesysversion_infochrwriter   r   getvaluedecoder   )r   siopridxchneeds         r   xxdr-   w   s    **C	2BQ<< ? ?RA!##RBb 	 +		)D//***		"		)D//***IIi#..///2Ba 	&IIinn%%%		)Fc"ggZ/00111
wr{{>immm	#>
Rx S2X		)D//D()))		)C..DAI.///		)D//"""		"IIioo<<>>  ***r   c                     t          j                    } d| _        dt                                          z   | _        |                     ddd           |                     ddd	           |                     d
dd           |                     ddddd           |                     dddd           |                     ddd           |                     dddd           |                     dddd d!           |                     d"dd#d$           |                     d%          }|                    d&dd'd()           |                     d*          }|                    d+d,d-           |                    d.d,d/           |                    d0d,d1           |                    d2d,d/           |                    d3d,d4           |                     d5          }|                    d6d7dd8           |                     d9          }|                    d:dd;           |                    d<dd#d=           |                    d>dd?d@           | S )ANzpython -mlmdbz%prog [options] <command>
z-ez--envzEnvironment file to open)helpz-dz--dbz Database to open (default: main)z-rz--readzOpen environment read-onlyz-Sz
--map_sizeint10z#Map size in megabytes (default: 10))typedefaultr/   z-sz--use-single-file
store_truez@The database was created as a single file and not a subdirectory)actionr/   z-Ez--target_envz$Target environment file for "dumpfd"z-xz--xxdzPrint values in xxd formatz-Mz	--max-dbs   zMaximum open DBs (default: 128)z--out-fd   z"copyfd" command target fdzOptions for "copy" commandz	--compactFz!Perform compaction while copying.)r5   r3   r/   zOptions for "edit" commandz--setappendzList of key=value pairs to set.z
--set-filez%List of key pairs to read from files.z--addzList of key=value pairs to add.z
--add-filez--deletez"List of key=value pairs to delete.zOptions for "readers" commandz-cz--cleanz"Clean stale readers? (default: no)zOptions for "watch" commandz--csvz(Generate CSV instead of terminal output.z
--intervalzInterval size (default: 1sec)z--window
   z!Average window size (default: 10))optparseOptionParserprog__doc__rstripusage
add_optionadd_option_group)parsergroups     r   make_parserrD      sG   "$$F!FK07>>3C3CCFL
dG*DEEE
dF)KLLL
dH+GHHH
dLud@  B B B
d/]  _ _ _
 dNA  C C C
dGL7  9 9 9
dKeS<  > > >
jua7  9 9 9##$@AAE	[u=  ? ? ?##$@AAE	WX;  = = =	\(A  C C C	WX;  = = =	\(A  C C C	Z>  @ @ @##$CDDE	T9\>  @ @ @##$ABBE	W\D  F F F	\q9  ; ; ;	ZeR=  ? ? ?Mr   c                 t    |r| |z  } t           j                            d| d           t          d          )Nzlmdb.tool: r   r7   )r"   stderrr%   
SystemExit)fmtargss     r   dierJ      s?     tJ###/000
Q--r   c           
         | D ]\  }}|                     t          dt          |          t          |          fz                       |                     |           |                     t          d                     |                     |           |                     t          d                     |                     t          d                     d S )Nz+%d,%d:z->r   )r%   r   len)cursorfpkeyvalues       r   dump_cursor_to_fprQ      s     " "
U
9C#e**'==>>???

4!!!

4!!!!HHYt__r   c                 D   i }| D ]y}|                     d          \  }}}|st          d|           |dk    rd }||v rt          d|           t                              |rt	          |          nd           |f||<   z|st                              d           df|d<   |S )N=z DB specification missing "=": %r:main:zDB specified twice: %rzmain.cdbmake)	partitionrJ   ENVopen_dbr   )rI   db_mapargdbnameseppaths         r   db_map_from_argsr]      s    F 	T 	TMM#..T 	92C888XFV(#...++6&Ki&7&7&7tLLdSv ?KK--~>xMr   c                 f   t          |          dk    rt          d           |d         }t          j                            |          rt          d|           t          j        |t          dd                     t          d|d           t          	                    || j
        	           d S )
Nr7   z,Please specify output directory (see --help)r   z#Output directory %r already exists.0755   zRunning copy to z....)compact)rL   rJ   osr\   existsmakedirsr0   printrV   copyra   )optsrI   
output_dirs      r   cmd_copyri      s    
4yyA~~:;;;aJ	w~~j!! ?1:>>>K
CNN+++	Ejjj
2333HHZH.....r   c                    |rt          d           	 t          j        | j        dd           n?# t          $ r2 t          j                    d         }t          d| j        |           Y nw xY wt                              | j                   d S )Nz0"copyfd" command takes no arguments (see --help)wr   r7   zBad --out-fd %d: %s)	rJ   rb   fdopenout_fdOSErrorr"   exc_inforV   copyfd)rg   rI   es      r   
cmd_copyfdrr      s     @>???3
	$+sA&&&& 3 3 3LNN1!4;222223 JJt{s   / 9A+*A+c                    t          |          }t                              d          5 }|                                D ]o\  }\  }}t	          |dt
                    5 }t          d|d           |                    |          }t          ||           d d d            n# 1 swxY w Y   p	 d d d            d S # 1 swxY w Y   d S )NT)bufferswbzDumping to ...db)	r]   rV   beginitemsopenBUF_SIZEre   rM   rQ   )	rg   rI   rX   txnrZ   rx   r\   rN   rM   s	            r   cmd_dumpr~     sH   d##F	4	 	  .C"(,,.. 	. 	.FJRdD(++ .rDDD2333r**!&"---. . . . . . . . . . . . . . .	.. . . . . . . . . . . . . . . . . .s5   3B>:B$B>$B((B>+B(,B>>CCc                    |j         }t          j        |d          fd}d}	 |dz  } |d          }|dk    rn|dk    rt          d|           	 t	           |d          d	          }t	           |d
          d	          }n # t
          $ r t          d|           Y nw xY w ||          }	 |d          dk    rt          d|            ||          }
t          |	          t          |
          z   ||z   k    rt          d|            |d          dk    rt          d|           |                     |	|
|           &|S )Nr7   c                 J    d                     t          |                     S )Nr   )joiniter)r[   read1s    r   <lambda>z(restore_cursor_from_fp.<locals>.<lambda>  s    SXXd5#&6&677 r   r   T   
   +z$bad or missing plus, line/record #%d   ,r9      :z&bad or missing length, line/record #%dr   s   ->z)bad or missing separator, line/record #%dz"short key or data, line/record #%dz bad line ending, line/record #%drw   )read	functoolspartialrJ   r0   
ValueErrorrL   put)r}   rN   rx   r   
read_untilrec_nrplusklendlenrO   datar   s              @r   restore_cursor_from_fpr     s   7DdA&&E7777JF"!tAww5==T\\6???	Bzz$'',,Dzz$'',,DD 	B 	B 	B8&AAAAA	B d4jj477e;VDDDtDzzHHs4yy dTk224f===477e2F;;;Tb!!!3"6 Ms   2B B%$B%c                    |st          d           t          t          j        t          t          |                    }t          |          D ]}\  }}||         }|dk    rt          d           t          d|d           t                              d          5 }|                    |           d d d            n# 1 swxY w Y   ~d S )Nz3Must specify at least one sub-database (see --help)rT   zCannot drop main DBzDropping DB rv   Tr%   )	rJ   maprV   rW   r   r!   re   ry   drop)rg   rI   dbsr*   rx   namer}   s          r   cmd_dropr   5  s    CABBB
ckC	400
2
2CS>>  RCy8%&&&TTT+,,,YYTY"" 	cHHRLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 s   C  C	C	c                     | j         r*t          dt                                          fz             t          t                                                     d S )NzCleaned %d stale entries.)cleanre   rV   reader_checkreadersrg   rI   s     r   cmd_readersr   C  sL    z C)S-=-=-?-?,AABBB	#++--r   c                    t          |          }t                              dd          5 }|                                D ]n\  }\  }}t	          |dt
                    5 }t          d|d           t          |||          }t          d||fz             d d d            n# 1 swxY w Y   o	 d d d            d S # 1 swxY w Y   d S )NT)rt   r%   rbzRestoring from rv   zLoaded %d keys from %r)r]   rV   ry   rz   r{   r|   re   r   )	rg   rI   rX   r}   rZ   rx   r\   rN   counts	            r   cmd_restorer   I  sv   d##F	4t	,	, @"(,,.. 	@ 	@FJRdD(++ @r6777.sB;;.%>???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @	@@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @s5   3B>9B$B>$B((B>+B(,B>>CCc                 V      fdt          dt                               D             S )Nc                 8    g | ]}|         |d z
           z
  S )r7    ).0ihsts     r   
<listcomp>zdelta.<locals>.<listcomp>T  s*    >>>aSVc!a%j >>>r   r7   )rangerL   )r   s   `r   deltar   S  s-    >>>>5CHH+=+=>>>>r   z
/sys/blockc                    t           j                            t                    sd S t          j        |           }|j        dz	  d|j        dz  fd}t          j        t                    D ]}t           j                            t          |          } ||          }|r|c S t          j        |          D ]5}t           j                            ||          } ||          }|r|c c S 6d S )Nr`   :   c                    t           j                            | d          }t           j                            |          rt	          |          5 }|                                                                k    r,t           j                            | d          cd d d            S 	 d d d            d S # 1 swxY w Y   d S d S )Ndevstat)rb   r\   r   rc   r{   r   strip)rootpathdpathrN   devss      r   maybez_find_diskstat.<locals>.maybe`  s    Xu--7>>%   	:e :7799??$$,,7<<&99: : : : : : : :,: : : : : : : : : : : : : : : : : :	: 	:s   A
B55B9<B9)rb   r\   rc   	SYS_BLOCKr   st_devlistdirr   )r\   str   r   basepathstatpath	base2pathr   s          @r   _find_diskstatr   Z  s   7>>)$$ 	Bi1nnnbi$&6&67D: : : : : 
9%% 	  	 7<<	4005?? 	OOOJx(( 	  	 DXt44IuY''H   	 	  	 r   c                       e Zd ZdZd Zd ZdS )DiskStatter)readsreads_mergedsectors_readread_mswriteswrites_mergedsectors_writtenwrite_msio_countio_mstotal_msc                 V    t          |          | _        |                                  d S N)r{   rN   refresh)selfr\   s     r   __init__zDiskStatter.__init__  s     t**r   c                      j                             d           t                                          fdt	           j                                                                                   D                        d S )Nr   c              3   V   K   | ]#\  }}j         |         t          |          fV  $d S r   )FIELDSr0   )r   r   r   r   s      r   	<genexpr>z&DiskStatter.refresh.<locals>.<genexpr>  sT       I I"a  ;q>3q662 I I I I I Ir   )rN   seekvarsupdater!   r   split)r   s   `r   r   zDiskStatter.refresh  s    QT

 I I I I&/0D0D0F0F&G&GI I I 	I 	I 	I 	I 	Ir   N)__name__
__module____qualname__r   r   r   r   r   r   r   r   s  s>        F  I I I I Ir   r   c                     d d  fd}fd}ddfdfddfdfddfd	fd
d |fd          fddfdfd
d |fd          fddfdfd
d |fd          fddfdfdd|fdd ||          fddfdfdd |fd          fg}d t          t                                                    }|r4t          |          |d
d |fd           fd
d! |fd"          fgz  }d#}d$ |D             } j        rIt	          j        t          j        t          j        %          }|	                    d& |D                        d#}		 	 t          
                                t                                          r                                 g }
t          |          D ]Q\  }\  }}}| |            z  }|
                    |           t          ||         t!          |                    ||<   R j        r|	                    |
           n|t"          k    s|	t$          d(z
  z  szt          |          D ]D\  }\  }}}t          j                            |                    ||         d)z                        Et          j                            d*           t"          }t          |
          D ]@\  }}t          j                            |                    ||         d)z                        At          j                            d*           t+          j         j                   |	d)z  }	# t0          $ r Y d S w xY w)+Nc                 @     t          j                     fd}|S )Nc                  L                                                t                    j        k    r                                 t                    dk    rdS t	          t                              t          t                    dz
            z  } | j        z  S )Nr7   r   )r8   rL   windowpopleftsumr   floatinterval)nfunchistoryrg   s    r   
windowfuncz-cmd_watch.<locals>.window.<locals>.windowfunc  s    NN4466"""7||dk))!!!7||q  qE'NN##eCLL1,<&=&==At}$$r   )collectionsdeque)r   r   r   rg   s   ` @r   r   zcmd_watch.<locals>.window  s>    #%%	% 	% 	% 	% 	% 	% 	% r   c                  ,     d         d         z  dz  S )N	last_pgnopsize      0Ar   )infor   s   r   r   zcmd_watch.<locals>.<lambda>  s    T+&g6(B r   z%dDepthc                       d         S )Ndepthr   r   s   r   r   zcmd_watch.<locals>.<lambda>  s    4= r   Branchc                       d         S )Nbranch_pagesr   r   s   r   r   zcmd_watch.<locals>.<lambda>  s    D$8 r   Leafc                       d         S N
leaf_pagesr   r   s   r   r   zcmd_watch.<locals>.<lambda>  s    $|"4 r   z%+dzLeaf/sc                       d         S r   r   r   s   r   r   zcmd_watch.<locals>.<lambda>  s    4+= r   Oflowc                       d         S Noverflow_pagesr   r   s   r   r   zcmd_watch.<locals>.<lambda>  s    4(8#9 r   zOflow/sc                       d         S r   r   r   s   r   r   zcmd_watch.<locals>.<lambda>  s    D1A,B r   Recsc                       d         S Nentriesr   r   s   r   r   zcmd_watch.<locals>.<lambda>  s    $y/ r   zRecs/sc                       d         S r  r   r   s   r   r   zcmd_watch.<locals>.<lambda>  s    4	? r   Rdrsc                       d         S )Nnum_readersr   r   s   r   r   zcmd_watch.<locals>.<lambda>  s    $}"5 r   z%.2fEnvMbz%+.2fzEnvMb/sTxsc                       d         S N
last_txnidr   r  s   r   r   zcmd_watch.<locals>.<lambda>  s    l!3 r   zTxs/sc                       d         S r  r   r  s   r   r   zcmd_watch.<locals>.<lambda>  s    $|*< r   zSctRd/sc                       j         S r   )r   statters   r   r   zcmd_watch.<locals>.<lambda>  s
    g.B r   zSctWr/sc                       j         S r   )r   r  s   r   r   zcmd_watch.<locals>.<lambda>  s
    g.E r   r   c                 4    g | ]\  }}}t          |          S r   )rL   r   _heads      r   r   zcmd_watch.<locals>.<listcomp>  s$    ///JAtQc$ii///r   )quotingc                     g | ]\  }}}|	S r   r   r  s      r   r   zcmd_watch.<locals>.<listcomp>  s    555*!T1555r   Tr   r7   r   )r   rV   r\   r   csvwriterr"   stdout	QUOTE_ALLwriterowr   r   r   r!   r8   maxrL   _TERM_WIDTH_TERM_HEIGHTr%   rjusttimesleepr   KeyboardInterrupt)rg   rI   r   envmbcolsr   
term_widthwidthsr  cntvalsr   rH   r  r   valr   r   r  s   `               @@@r   	cmd_watchr/    s*   DD     CBBBBE 
'00001	(88889	&44445	(FF#=#=#=#=>>?	'9999:	)VV$B$B$B$BCCD	&11112	(FF#:#:#:#:;;<	&55556	'5!	)VVE]]+	%33334	'66"<"<"<"<==>D  Gchhjj))H 
h''Ivv&B&B&B&BCCDIvv&E&E&E&EFFG
 	

 J//$///Fx 7CJ>>>55555666
C	88::D88::D "!!!D(1$ 5 5$$CtDDFFlC   q	3s8844q		x 
'%%%%,,SL1<L5M,09$ D D,,Ct
((F1IM)B)BCCCCJ$$T***!,J'oo ? ?FAsJ$$SYYvay1}%=%=>>>>
  &&&Jt}%%%1HC3	4    s   G+M 
MMc                 T   t                                           }t                                           }d}|d         |d         z  }t          j        dt	          d|z                      }t          j                    }| j        rt          | j        d|          }nt          | j        dz   d|          }|	                                |k     r-|
                    |           |	                                |k     -t          d|d	z  d
t          j                    |z
  z  fz             d S )Ni   r   r   B r   z	/data.mdbzWarmed %.2fmb in %dmsr   i  )rV   r   r   arrayr   r%  use_single_filer{   envtellreadintore   )	rg   rI   r   r   bufsizelast_offsetbuft0rN   s	            r   cmd_warmr<    s   88::D88::DGw-${"33K
+c9Vg%566
7
7C	B 9$(D'**$([($88
''))k
!
!
C ''))k
!
!	
!!449;;+;#<
=> ? ? ? ? ?r   c           	         | j         st          d           t                                          }t	          j        | j         |d         dz  | j        dddd          }g }|D ]m}|dk    rd n|}t                              t          |                    }|                    t          |                    }|	                    |||f           n|sC|	                    dt                              d           |                    d           f           |D ]\  }}}t          d|d	           |                    |d
          5 }	t                              |d          5 }
|
                                D ]\  }}|	                    ||d           	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          d           |                    d           d S )Nz,Must specify target environment path with -Emap_sizer   FT)r>  max_dbssyncwritemap	map_asyncmetasyncrT   zWriting rv   )rx   r%   )rx   rt   )r8   z	Syncing..)
target_envrJ   rV   r   lmdbr{   r?  rW   r   r8   re   ry   rM   r   r@  )rg   rI   src_inforD  r   rY   r   src_dbdst_dbwtxnrtxnrO   rP   s                r   cmd_rewriterK    sq   ? <:;;;xxzzH4?$,Z$81$<#'<e$(D$)	+ + +J C * *httCYt__--##IdOO44

C()))) L

Hckk$//1C1CD1I1IJKKK # 6 6ff'(((t44 	6fd33 6t"&++-- 6 6JCHHS%H555566 6 6 6 6 6 6 6 6 6 6 6 6 6 6	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6
 
+OODs6   F;$3F$F;$F((F;+F(,F;;F?	F?	c                    t          |          dk    }t                              dt                    5 }|D ]}|                    t          |                    }|t          |d           9|rt          |d           | j        rt          t          |                     qt          t          |                     	 d d d            d S # 1 swxY w Y   d S )Nr7   T)rt   rx   z	: missingr   )	rL   rV   ry   DBr
   r   re   r-   bytes)rg   rI   print_headerr}   rY   rP   s         r   cmd_getrP    s$   t99q=L	4B	'	' $3 
	$ 
	$CGGIcNN++E}sss,--- &sssn%%%x $c%jj!!!!eEll####
	$$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s   BCCCc                    |rt          d           t                              d          5 }|                    t                    }| j        pg D ]M}t          |                              t          d                    \  }}}|                    ||d           N| j	        pg D ]K}t          |                              t          d                    \  }}}|                    ||           L| j
        pg D ]+}|
                    t          |          t                     ,| j        pg D ]}t          |                              t          d                    \  }}}t          |d          5 }	|                    ||	                                d           d d d            n# 1 swxY w Y   | j        pg D ]}t          |                              t          d                    \  }}}t          |d          5 }	|                    ||	                                           d d d            n# 1 swxY w Y   	 d d d            d S # 1 swxY w Y   d S )	Nz;Edit command only takes options, not arguments (see --help)Tr   rw   rS   F)	overwriter   )rJ   rV   ry   rM   rM  addr   rU   r   setdeleteadd_filer{   r   set_file)
rg   rI   r}   rM   elemrO   r  rP   r\   rN   s
             r   cmd_editrY  #  s    KIJJJ			 +#r""HN 	4 	4D%dOO55innEEMCEJJsEUJ3333HN 	# 	#D%dOO55innEEMCEJJsE"""";$" 	. 	.CJJy~~"J----M'R 	< 	<D$T??44Ys^^DDLCDdD!! <R

3		U
;;;< < < < < < < < < < < < < < < M'R 	+ 	+D$T??44Ys^^DDLCDdD!! +R

3		***+ + + + + + + + + + + + + + +	+%+ + + + + + + + + + + + + + + + + +s[   EI8+F/#I/F33I6F37AI	)H>2I>IIIIIIc                 |    dd l }dd l}|                    t                                                                 d S )Nr   )codereadlineInteractiveConsoler	   interact)rg   rI   r[  r\  s       r   	cmd_shellr_  ?  s>    KKKOOOGII&&//11111r   c                     t          j         t                                                     t          j         t                                                     d S r   )pprintrV   r   r   r   s     r   cmd_statrb  E  s8    
M#((**
M#((**r   P      c                     	 dd l }dd l}|                    t          j                                        |j        d          }t          j        d|          \  }}||fS # t          $ r | cY S w xY w)Nr   1234hh)
fcntltermiosioctlr"   r  fileno
TIOCGWINSZstructunpack	Exception)r3   ri  rj  r   heightwidths         r   _get_term_widthrs  J  s    KK
))++W-?HHdA..f}   s   AA A-,A-c                  (    t                      \  aad S r   )rs  r"  r#  )rI   s    r   _on_sigwinchru  U  s     / 1 1Kr   c           	         t                      }|                    |           \  }}|st          d           |j        st          d           t	          j        |j        |j        dz  |j         |j        d|j	        dk              a
|j        r,t                              t          |j                            at          t           d          r$t!          j        t           j        t$                     t%                       t'                                          d|d	         z             }|st          d
|d	                     |||dd                     d S )Nz%Please specify a command (see --help)z"Please specify environment (--env)i   FREAD)r>  subdirr?  createreadonlySIGWINCHcmd_r   zNo such command: r7   )rD   
parse_argsrJ   r5  rE  r{   r>  r4  r?  r   rV   rx   rW   r   rM  hasattrsignalr{  ru  r	   r
   )argvrB   rg   rI   r   s        r   mainr  Z  sG   ]]F""4((JD$ 534448 20111 )DHt}w'>4K_G_ LfATV V VC w -[[47++,,vz"" 5fo|444NNN99==$q')**D 0T!WW.///DtABBxr   __main__r7   )rc  r   )9r=   
__future__r   r   r3  r   r  r   r:   rb   ra  r  r   rn  r"   r%  ior   r   ImportError	cStringIOrE  r|   rV   rM  r   r   r   r-   rD   rJ   rQ   r]   ri   rr   r~   r   r   r   r   r   r   r   objectr   r/  r<  rK  rP  rY  r_  rb  rs  ru  r  r   r  r   r   r   <module>r     sX  ./ /b ' & & & & & % % % % % %      



      				     



 &&&&&&&& & & &&&&&&&&& & & &%%%%%%%%&&  
	 = = =1 1 1+ + +@. . .b      &
/ 
/ 
/
 
 
. . ." " "J    @ @ @? ? ? 	     2I I I I I& I I I2P P Pf? ? ?&  @$ $ $"+ + +82 2 2  
   2 2 2
   8 zD!"" s6    A A(AA(A"A(!A""A('A(