ó •abc@@sdZddlmZddlZddlZddlZddlmZmZm Z m Z m Z m Z defd„ƒYZ d„Zd „Zd „ZdS( s8 Lockfile behaviour implemented via Unix PID files. i(tabsolute_importNi(tLockBaset AlreadyLockedt LockFailedt NotLockedt NotMyLockt LockTimeoutt PIDLockFilecB@sVeZdZedd„Zd„Zd„Zd„Zdd„Z d„Z d„Z RS( sA Lockfile implemented as a Unix PID file. The lock file is a normal file named by the attribute `path`. A lock's PID file contains a single line of text, containing the process ID (PID) of the process that acquired the lock. >>> lock = PIDLockFile('somefile') >>> lock = PIDLockFile('somefile') cC@s&tj||t|ƒ|j|_dS(N(Rt__init__tFalsetpatht unique_name(tselfR tthreadedttimeout((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyR$scC@s t|jƒS(s- Get the PID from the lock file. (tread_pid_from_pidfileR (R ((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pytread_pid*scC@stjj|jƒS(sv Test if the lock is currently held. The lock is held if the PID file for this lock exists. (tosR texists(R ((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyt is_locked/scC@s"|jƒo!tjƒ|jƒkS(s¡ Test if the lock is held by the current process. Returns ``True`` if the current process ID matches the number stored in the PID file. (RRtgetpidR(R ((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyt i_am_locking7scC@s)|dk r|n|j}tjƒ}|dk rL|dkrL||7}nxÖtr$yt|jƒWn´tk r}|jtjkrtjƒ|krà|dk rÊ|dkrÊt d|jƒ‚qàt d|jƒ‚ntj |dk rü|dpÿdƒq!t d|jƒ‚qOXdSqOWdS(s† Acquire the lock. Creates the PID file for this lock, or raises an error if the lock could not be acquired. is&Timeout waiting to acquire lock for %ss%s is already lockedi gš™™™™™¹?sfailed to create %sN( tNoneRttimetTruetwrite_pid_to_pidfileR tOSErrorterrnotEEXISTRRtsleepR(R Rtend_timetexc((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pytacquire?s$   &cC@sU|jƒs"td|jƒ‚n|jƒsDtd|jƒ‚nt|jƒdS(s¥ Release the lock. Removes the PID file to release the lock, or raises an error if the current process does not hold the lock. s%s is not lockeds%s is locked, but not by meN(RRR RRtremove_existing_pidfile(R ((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pytrelease_s   cC@st|jƒdS(s‚ Break an existing lock. Removes the PID file if it already exists, otherwise does nothing. N(R!R (R ((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyt break_locklsN( t__name__t __module__t__doc__R RRRRRR R"R#(((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyRs     cC@sqd}yt|dƒ}Wntk r,nAX|jƒjƒ}yt|ƒ}Wntk rbnX|jƒ|S(sï Read the PID recorded in the named PID file. Read and return the numeric PID recorded as text in the named PID file. If the PID file cannot be read, or if the content is not a valid PID, return ``None``. trN(RtopentIOErrortreadlinetstriptintt ValueErrortclose(t pidfile_pathtpidtpidfiletline((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyRvs    cC@sotjtjBtjB}d}tj|||ƒ}tj|dƒ}tjƒ}|jd|ƒ|jƒdS(s° Write the PID in the named PID file. Get the numeric process ID (“PIDâ€) of the current process and write it to the named file as a line of text. i¤tws%s N( RtO_CREATtO_EXCLtO_WRONLYR(tfdopenRtwriteR.(R/t open_flagst open_modet pidfile_fdR1R0((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyR˜s cC@sCytj|ƒWn+tk r>}|jtjkr8q?‚nXdS(sÏ Remove the named PID file if it exists. Removing a PID file that doesn't already exist puts us in the desired state, so we ignore the condition if the file does not exist. N(RtremoveRRtENOENT(R/R((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyR!°s (R&t __future__RRRRtRRRRRRRRRR!(((sD/usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyt s   .] "