usr/lib/python2.7/site-packages/pip/_vendor/lockfile/pidlockfile.pyc000064400000013425147205626430021447 0ustar00 abc@@sdZddlmZddlZddlZddlZddlmZmZm Z m Z m Z m Z defdYZ dZd Zd ZdS( s8 Lockfile behaviour implemented via Unix PID files. i(tabsolute_importNi(tLockBaset AlreadyLockedt LockFailedt NotLockedt NotMyLockt LockTimeoutt PIDLockFilecB@sVeZdZeddZdZdZdZddZ dZ dZ 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|jS(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|jS(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"|jo!tj|jkS(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}nxtr$yt|jWntk r}|jtjkrtj|kr|dk r|dkrt d|jqt d|jntj |dk r|dpdq!t d|jqOXdSqOWdS(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|js"td|jn|jsDtd|jnt|jdS(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|jdS(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|jj}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||jdS(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. itws%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.pyRs 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   .] "