ó •abc@`s’ddlmZmZddlZddlZyeWnek rOeZnXddlm Z m Z m Z m Z m Z de fd„ƒYZdS(i(tabsolute_importtdivisionNi(tLockBaset NotLockedt NotMyLockt LockTimeoutt AlreadyLockedtSQLiteLockFilecB`s\eZdZdZedd„Zdd„Zd„Zd„Z d„Z d„Z d„Z RS( sDemonstrate SQL-based locking.c C`stj||||ƒt|jƒ|_t|jƒ|_tjdkr“ddl}|j ƒ\}}t j |ƒt j |ƒ~~|t_nddl }|jtjƒ|_|jjƒ}y|jdƒWn|jk rên0X|jjƒddl} | jt j tjƒdS(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Ì|jƒs.|jd|j|j fƒ|jj ƒ|jd|j fƒ|j ƒ}t |ƒdkr'|jd|j fƒ|jj ƒqfdSn8|jd|j fƒ|j ƒ}t |ƒdkrfdS|dk r¼tjƒ|kr¼|dkr¦t d|jƒ‚q¼td |jƒ‚ntj|ƒq’WdS( 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†|jƒs"td|jƒ‚n|jƒsPtd|j|jƒfƒ‚n|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ƒ|jƒdS(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ƒ|jjƒdS(Ns&delete from locks where lock_file = ?(RRRR R(RR((sG/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/sqlitelockfile.pyt break_lock—s  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    (