ó ðYSc@sÑddlZddlZddlZddlZddlZddljZddlj j Z ddl m Z ddl mZdefd„ƒYZdefd„ƒYZd„Zd „Zd „Zd „ZdS( iÿÿÿÿN(tglobal_settings(t DummyLocktLockFilecBsGeZdZddded„Zed„ƒZed„Zd„Z RS(s”A class that provides generic lockfile support. This allows Python processes to perform inter-process locking using the filesystem.cCsyd|_||_||_||_t|_|r?||_n t|_|rit j ƒ|_ t |_n t ƒ|_ dS(s'Create a LockFile object. The 'filepath' argument should be the path to the file that will be used as the lockfile. If the caller may supply the following optional arguments: set_lockstr - A function that returns a string. This is called when the lock operation wants to write implementation specific text into the lock file. get_lockstr - A function that takes a string and returns a dictionary. This function must be able to parse the lock string created by set_lockstr. The dictionary object is passed as **kwargs to 'failure_exc' if the lock is non-blocking and fails. failure_exc - If a non-blocking lock acquisition fails, this exception will be raised. It should allow the caller to specify a kwargs argument, but not all invocations will provide kwargs. provide_mutex - By default, the LockFile object will use a mutex to sychronize access for threads in the current process. If the caller is already providing mutual exclusion to the LockFile object, this should be set to False.N(tNonet_fileobjt _filepatht _set_lockstrt _get_lockstrtFalset_provide_mutext _failure_exct FileLockedtnrlocktNRLockt_locktTrueR(tselftfilepatht set_lockstrt get_lockstrt failure_exct provide_mutex((s2/usr/lib/python2.7/vendor-packages/pkg/lockfile.pyt__init__,s        cCs#|jr|jjo|jS|jS(N(R RtlockedR(R((s2/usr/lib/python2.7/vendor-packages/pkg/lockfile.pyRWs c CsR|jjdt|ƒƒ}|s0|jƒ‚ntj}|sO|tjO}nd}yCtj |j tj tj Btj BtjBƒ}tj|dƒ}Wn‡tk r }|jjƒ|jtjkrtjtjj|j ƒtjj|j ƒ|jƒ‚n|‚n|jjƒ‚nXytj||ƒWntk rÈ}|jtjtjfkrv|jjƒ‚n|jƒjƒ}|jjƒ|jr°|j|ƒ}ni}|j|‚nXyX|j dƒd} |j!r÷|j!ƒ} n| r |j"| ƒn|j#ƒ||_$Wn*d|_$|j%ƒ|jjƒ‚nXdS(s0Lock the lockfile, to prevent access from other processes. If blocking is False, this method will return an exception, instead of blocking, if the lock is held. If the lockfile cannot be opened, this method may return an EnvironmentError.tblockingsab+iN(&RtacquiretintR tfcntltLOCK_EXtLOCK_NBRtostopenRtO_RDWRtO_APPENDtO_CREATt O_NOFOLLOWtfdopentOSErrortreleaseterrnotELOOPt api_errorstUnexpectedLinkErrortpathtdirnametbasenametlockftIOErrortEAGAINtEACCEStreadtstripRttruncateRtwritetflushRtclose( RRtrvalt lock_typetlftfdtet lock_datat lock_dicttlock_str((s2/usr/lib/python2.7/vendor-packages/pkg/lockfile.pytlock]sb                cCs¨|jr…zlyDtj|jtjƒ|jjdƒ|jjƒ|jjƒWn!tk rs|jjƒ‚nXWdd|_Xn|j r¤|jj s¤t ‚ndS(sUnlocks the LockFile.iN( RRR.tLOCK_UNR4R7RR&tEnvironmentErrorRR RtAssertionError(R((s2/usr/lib/python2.7/vendor-packages/pkg/lockfile.pytunlock¯s       N( t__name__t __module__t__doc__RRRtpropertyRR@RD(((s2/usr/lib/python2.7/vendor-packages/pkg/lockfile.pyR's * RR cBs eZdZd„Zd„ZRS(suGeneric exception class used by LockFile. Raised in non-blocking mode when file or thread is already locked.cOs,|r|d|_n d|_||_dS(Ni(tdataRt_args(Rtargstkwargs((s2/usr/lib/python2.7/vendor-packages/pkg/lockfile.pyRÍs cCs'd}|jr#|d|j7}n|S(NsUnable to lock files: %s(RI(Rterrstr((s2/usr/lib/python2.7/vendor-packages/pkg/lockfile.pyt__str__Ôs (RERFRGRRN(((s2/usr/lib/python2.7/vendor-packages/pkg/lockfile.pyR És cCsci}yD|jddƒ\}}}}||d<||d<||d<|SWntk r^|SXdS(Ns itpidtpid_namethostname(tsplitt ValueError(tlockstrtlockdictRORPRQtlock_ts((s2/usr/lib/python2.7/vendor-packages/pkg/lockfile.pytclient_lock_get_strÛs    cCs@tjjƒ}djttjƒƒtjt j ƒ|dfƒS(Ns ( tpkgtcatalogtnow_to_basic_tstjointstrRtgetpidRt client_nametplatformtnode(RV((s2/usr/lib/python2.7/vendor-packages/pkg/lockfile.pytclient_lock_set_strçscCsVi}y7|jddƒ\}}}||d<||d<|SWntk rQ|SXdS(Ns iRORQ(RRRS(RTR>RORQRV((s2/usr/lib/python2.7/vendor-packages/pkg/lockfile.pytgeneric_lock_get_strís   cCs:tjjƒ}djttjƒƒtjƒ|dfƒS(Ns ( RXRYRZR[R\RR]R_R`(RV((s2/usr/lib/python2.7/vendor-packages/pkg/lockfile.pytgeneric_lock_set_str÷s(R'RRR_t pkg.catalogRXt pkg.nrlockR tpkg.client.api_errorstclientR)t pkg.clientRtpkg.miscRtobjectRt ExceptionR RWRaRbRc(((s2/usr/lib/python2.7/vendor-packages/pkg/lockfile.pyts     ¢