Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/internet/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/internet/inotify.pyc


Mc@scdZddlZddlZddlmZddlmZddlmZm	Z	dZ
dZdZd	Z
d
ZdZdZd
ZdZdZdZdZdZdZdZdZdZdZdZdZe
eBZeeBZeeBZ eeBeBeBeBeBeBeBeBZ!e
dfedfedfe
dfedfedfed fed!fed"fed#fed$fed%fed&fed'fed(fed)fed*fed+fed,fed-fgZ"d.Z#d/e$fd0YZ%d1ee$fd2YZ&e	j'Z'd1d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKgZ(dS(Ls 
This module provides support for Twisted to linux inotify API.

In order to use this support, simply do the following (and start a reactor
at some point)::

    from twisted.internet import inotify
    from twisted.python import filepath

    def notify(ignored, filepath, mask):
        """
        For historical reasons, an opaque handle is passed as first
        parameter. This object should never be used.

        @param filepath: FilePath on which the event happened.
        @param mask: inotify event as hexadecimal masks
        """
        print "event %s on %s" % (
            ', '.join(inotify.humanReadableMask(mask)), filepath)

    notifier = inotify.INotify()
    notifier.startReading()
    notifier.watch(filepath.FilePath("/some/directory"), callbacks=[notify])

@since: 10.1
iN(tfdesc(tFileDescriptor(tlogt_inotifyllllll l@llllll l@liii i@Itaccesstmodifytattribtclose_writet
close_nowritetopent
moved_fromtmoved_totcreatetdeletetdelete_selft	move_selftunmounttqueue_overflowtignoredtonly_dirtdont_followtmask_addtis_dirtone_shotcCs;g}x.tD]&\}}||@r
|j|q
q
W|S(si
    Auxiliary function that converts an hexadecimal mask into a series
    of human readable flags.
    (t_FLAG_TO_HUMANtappend(tmasktstktv((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pythumanReadableMaskcs

t_WatchcBs)eZdZeeddZdZRS(s
    Watch object that represents a Watch point in the filesystem. The
    user should let INotify to create these objects

    @ivar path: The path over which this watch point is monitoring
    @ivar mask: The events monitored by this watchpoint
    @ivar autoAdd: Flag that determines whether this watch point
        should automatically add created subdirectories
    @ivar callbacks: C{list} of callback functions that will be called
        when an event occurs on this watch.
    cCs=||_||_||_|dkr0g}n||_dS(N(tpathRtautoAddtNonet	callbacks(tselfR RR!R#((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pyt__init__|s				cCs(x!|jD]}||||q
WdS(sL
        Callback function used by L{INotify} to dispatch an event.
        N(R#(R$tfilepathteventstcallback((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pyt_notifysN(t__name__t
__module__t__doc__t
IN_WATCH_MASKtFalseR"R%R)(((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pyRps	tINotifycBseZdZeZddZdZdZdZdZ	dZ
dZdZe
eded	Zd
ZdZRS(
s
    The INotify file descriptor, it basically does everything related
    to INotify, from reading to notifying watch points.

    @ivar _buffer: a C{str} containing the data read from the inotify fd.

    @ivar _watchpoints: a C{dict} that maps from inotify watch ids to
        watchpoints objects

    @ivar _watchpaths: a C{dict} that maps from watched paths to the
        inotify watch ids
    cCsvtj|d||jj|_tj|jtj|jd|_t	|_
d|_i|_i|_
dS(Ntreactorit(RR%Rtinitt_fdRtsetNonBlockingt_setCloseOnExect	connectedtTruet_writeDisconnectedt_buffert_watchpointst_watchpaths(R$R0((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pyR%s				cCsQ|jj|j|j|}t||||}||j|<||j|<|S(s~
        Private helper that abstracts the use of ctypes.

        Calls the internal inotify API and checks for any errors after the
        call. If there's an error L{INotify._addWatch} can raise an
        INotifyError. If there's no error it proceeds creating a watchpoint and
        adding a watchpath for inverse lookup of the file descriptor from the
        path.
        (RtaddR3R RR:R;(R$R RR!R#twdtiwp((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pyt	_addWatchs



cCs?|jj|j||jj|}|jj|jdS(s
        Private helper that abstracts the use of ctypes.

        Calls the internal inotify API to remove an fd from inotify then
        removes the corresponding watchpoint from the internal mapping together
        with the file descriptor from the watchpath.
        N(RtremoveR3R:tpopR;R (R$R=R>((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pyt_rmWatchscCs`tj|||jdkr\ytj|jWq\tk
rX}tj|dq\XndS(sR
        Release the inotify file descriptor and do the necessary cleanup
        is'Couldn't close INotify file descriptor.N(RtconnectionLostR3tostclosetOSErrorRterr(R$treasonte((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pyRCscCs|jS(s
        Get the underlying file descriptor from this inotify observer.
        Required by L{abstract.FileDescriptor} subclasses.
        (R3(R$((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pytfilenoscCstj|j|jdS(sC
        Read some data from the observed file descriptors
        N(Rt
readFromFDR3t_doRead(R$((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pytdoReadsc

Csq|j|7_x[t|jdkrltjd|jdd!\}}}}|ru|jdd|!jd}nd}|jd||_y|j|}Wntk
rqnX|j}|r|j	|}n|j
|||jrO|t@rO|t
@rO|j|d|jdtd|j}	|jjd|j|j|	n|t@r|j|qqWdS(	sF
        Work on the data just read from the file descriptor.
        is=LLLLitRR!R#N(R9tlentstructtunpacktrstripR"R:tKeyErrorR tchildR)R!tIN_ISDIRt	IN_CREATEtwatchRR7R#R0t	callLatert_addChildrentIN_DELETE_SELFRB(
R$tin_R=RtcookietsizetnameR>R tnew_wd((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pyRLs.( 
	
c	Csy|jj}Wntk
r'dSXx|D]}|jr|j|d|jdtd|j}|j|t	t
B|jjd|j
|j|n|jr/|j|t
tBq/q/WdS(s
        This is a very private method, please don't even think about using it.

        Note that this is a fricking hack... it's because we cannot be fast
        enough in adding a watch to a directory and so we basically end up
        getting here too late if some operations have already been going on in
        the subdir, we basically need to catchup.  This eventually ends up
        meaning that we generate double events, your app must be resistant.
        NRR!R#i(R tchildrenRFtisdirRWRR7R#R)RURVR0RXRYR:tisfiletIN_CLOSE_WRITE(R$R>tlistdirtfR=((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pyRYs


cCs|rKx{|jD]1}|jr|j||||dtqqWn9|j|}|rd|S|tB}|j||||SdS(sR
        Watch the 'mask' events in given path. Can raise C{INotifyError} when
        there's a problem while adding a directory.

        @param path: The path needing monitoring
        @type path: L{FilePath}

        @param mask: The events that should be watched
        @type mask: C{int}

        @param autoAdd: if True automatically add newly created
                        subdirectories
        @type autoAdd: C{boolean}

        @param callbacks: A list of callbacks that should be called
                          when an event happens in the given path.
                          The callback should accept 3 arguments:
                          (ignored, filepath, mask)
        @type callbacks: C{list} of callables

        @param recursive: Also add all the subdirectories in this path
        @type recursive: C{boolean}
        t	recursiveN(twalkRaRWR.t
_isWatchedRZR?(R$R RR!R#RfRTR=((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pyRWEs
cCsB|j|}|dkr1td|fn
|j|dS(s
        Remove the watch point monitoring the given path

        @param path: The path that should be ignored
        @type path: L{FilePath}
        s%r is not watchedN(RhR"RSRB(R$R R=((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pytignoresscCs|jj|dS(s
        Helper function that checks if the path is already monitored
        and returns its watchdescriptor if so or None otherwise.

        @param path: The path that should be checked
        @type path: L{FilePath}
        N(R;tgetR"(R$R ((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pyRhsN(R*R+R,RR"R%R?RBRCRJRMRLRYR-R.RWRiRh(((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pyR/s		
				.	'-	RR-t	IN_ACCESSt	IN_MODIFYt	IN_ATTRIBtIN_CLOSE_NOWRITERctIN_OPENt
IN_MOVED_FROMtIN_MOVED_TORVt	IN_DELETERZtIN_MOVE_SELFt
IN_UNMOUNTt
IN_Q_OVERFLOWt
IN_IGNOREDt
IN_ONLYDIRtIN_DONT_FOLLOWtIN_MASK_ADDRUt
IN_ONESHOTtIN_CLOSEtIN_MOVEDt
IN_CHANGED()R,RDRPttwisted.internetRttwisted.internet.abstractRttwisted.pythonRRRkRlRmRcRnRoRpRqRVRrRZRsRtRuRvRwRxRyRURzR{R|R}R-RRtobjectRR/tINotifyErrort__all__(((s</usr/lib/python2.7/dist-packages/twisted/internet/inotify.pyt<module>sx


&