abc@`sddlmZmZddlZddlZyeWnek rOeZnXddlm Z m Z m Z m Z m Z de fdYZdS(i(tabsolute_importtdivisionNi(tLockBaset NotLockedt NotMyLockt LockTimeoutt AlreadyLockedtSQLiteLockFilecB`s\eZdZdZeddZddZdZdZ dZ dZ dZ RS( sDemonstrate SQL-based locking.c C`stj||||t|j|_t|j|_tjdkrddl}|j \}}t j |t j |~~|t_nddl }|jtj|_|jj}y|jdWn|jk rn0X|jjddl} | jt j tjdS(su >>> lock = SQLiteLockFile('somefile') >>> lock = SQLiteLockFile('somefile', threaded=False) iNsGcreate table locks( lock_file varchar(32), unique_name varchar(32))(Rt__init__tunicodet lock_filet unique_nameRttestdbtNonettempfiletmkstemptostclosetunlinktsqlite3tconnectt connectiontcursortexecutetOperationalErrortcommittatexittregister( tselftpathtthreadedttimeoutRt_fdR RtcR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyRs(       cC`s|dk r|n|j}tj}|dk rL|dkrL||7}n|dkrad}n|dkrvd}n |d}|jj}x;tr|js.|jd|j|j f|jj |jd|j f|j }t |dkr'|jd|j f|jj qfdSn8|jd|j f|j }t |dkrfdS|dk rtj|kr|dkrt d|jqtd |jntj|qWdS( Nig?i s;insert into locks (lock_file, unique_name) values (?, ?)s*select * from locks where unique_name = ?is(delete from locks where unique_name = ?s&Timeout waiting to acquire lock for %ss%s is already locked(R RttimeRRtTruet is_lockedRR R RtfetchalltlenRRRtsleep(RRtend_timetwaitRtrows((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pytacquire5sD                    cC`s|js"td|jn|jsPtd|j|jfn|jj}|j d|jf|jj dS(Ns%s is not lockeds#%s is locked, but not by me (by %s)s(delete from locks where unique_name = ?( R$RRt i_am_lockingRR t_who_is_lockingRRRR(RR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pytreleasets    cC`s3|jj}|jd|jf|jdS(Ns2select unique_name from locks where lock_file = ?i(RRRR tfetchone(RR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyR-s  cC`s7|jj}|jd|jf|j}| S(Ns(select * from locks where lock_file = ?(RRRR R%(RRR*((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyR$s    cC`s7|jj}|jd|j|jf|j S(Ns?select * from locks where lock_file = ? and unique_name = ?(RRRR R R%(RR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyR,s cC`s6|jj}|jd|jf|jjdS(Ns&delete from locks where lock_file = ?(RRRR R(RR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyt break_locks  N( t__name__t __module__t__doc__R R R#RR+R.R-R$R,R0(((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyRs" ?   (t __future__RRR"RR t NameErrortstrtRRRRRR(((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyts    (