hgext/inotify/client.py
author Nicolas Dumazet <nicdumz.commits@gmail.com>
Tue, 07 Apr 2009 19:30:01 +0900
changeset 8552 06561793778e
parent 8551 7089d9727867
child 8553 e387ecd7a6ed
permissions -rw-r--r--
inotify: Separate query sending logic from Server starting. Use a decorator around the public statusquery method of Client: start_server(query_to_server): try: query_to_server() except QueryFailed: [error recovery, inotify Server (re)starting] query_to_server() This way, introducing a new xxxquery Client method is easy: one has only to code the protocol part of xxxquery, ignoring errors, and decorating it using start_server to handle server recovery and (re)starts
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
     1
# client.py - inotify status client
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
     2
#
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
     3
# Copyright 2006, 2007, 2008 Bryan O'Sullivan <bos@serpentine.com>
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
     4
# Copyright 2007, 2008 Brendan Cully <brendan@kublai.com>
8551
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
     5
# Copyright 2009 Nicolas Dumazet <nicdumz@gmail.com>
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
     6
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8067
diff changeset
     7
# This software may be used and distributed according to the terms of the
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8067
diff changeset
     8
# GNU General Public License version 2, incorporated herein by reference.
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
     9
7225
59b4ae211584 i18n: import _ instead of gettext
Martin Geisler <mg@daimi.au.dk>
parents: 7145
diff changeset
    10
from mercurial.i18n import _
8552
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    11
import common, server
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    12
import errno, os, socket, struct
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    13
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    14
class QueryFailed(Exception): pass
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    15
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    16
def start_server(function):
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    17
    """
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    18
    Decorator.
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    19
    Tries to call function, if it fails, try to (re)start inotify server.
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    20
    Raise QueryFailed if something went wrong
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    21
    """
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    22
    def decorated_function(self, *args):
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    23
        result = None
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    24
        try:
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    25
            return function(self, *args)
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    26
        except (OSError, socket.error), err:
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    27
            autostart = self.ui.configbool('inotify', 'autostart', True)
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    28
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    29
            if err[0] == errno.ECONNREFUSED:
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    30
                self.ui.warn(_('(found dead inotify server socket; '
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    31
                               'removing it)\n'))
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    32
                os.unlink(self.repo.join('inotify.sock'))
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    33
            if err[0] in (errno.ECONNREFUSED, errno.ENOENT) and autostart:
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    34
                self.ui.debug(_('(starting inotify server)\n'))
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    35
                try:
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    36
                    try:
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    37
                        server.start(self.ui, self.repo)
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    38
                    except server.AlreadyStartedException, inst:
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    39
                        # another process may have started its own
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    40
                        # inotify server while this one was starting.
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    41
                        self.ui.debug(str(inst))
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    42
                except Exception, inst:
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    43
                    self.ui.warn(_('could not start inotify server: '
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    44
                                   '%s\n') % inst)
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    45
                else:
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    46
                    try:
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    47
                        return function(self, *args)
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    48
                    except socket.error, err:
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    49
                        self.ui.warn(_('could not talk to new inotify '
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    50
                                       'server: %s\n') % err[-1])
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    51
            elif err[0] in (errno.ECONNREFUSED, errno.ENOENT):
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    52
                # silently ignore normal errors if autostart is False
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    53
                self.ui.debug(_('(inotify server not running)\n'))
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    54
            else:
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    55
                self.ui.warn(_('failed to contact inotify server: %s\n')
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    56
                         % err[-1])
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    57
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    58
        self.ui.traceback()
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    59
        raise QueryFailed('inotify query failed')
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    60
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    61
    return decorated_function
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    62
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    63
8551
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    64
class client(object):
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    65
    def __init__(self, ui, repo):
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    66
        self.ui = ui
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    67
        self.repo = repo
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    68
        self.sock = socket.socket(socket.AF_UNIX)
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    69
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    70
    def _connect(self):
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    71
        sockpath = self.repo.join('inotify.sock')
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    72
        try:
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    73
            self.sock.connect(sockpath)
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    74
        except socket.error, err:
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    75
            if err[0] == "AF_UNIX path too long":
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    76
                sockpath = os.readlink(sockpath)
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    77
                self.sock.connect(sockpath)
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    78
            else:
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    79
                raise
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    80
8551
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    81
    def _send(self, data):
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    82
        """Sends protocol version number, and the data"""
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    83
        self.sock.sendall(chr(common.version) + data)
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    84
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    85
        self.sock.shutdown(socket.SHUT_WR)
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    86
8551
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    87
    def _receive(self):
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    88
        """
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    89
        Read data, check version number, extract headers,
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    90
        and returns a tuple (data descriptor, header)
8552
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    91
        Raises QueryFailed on error
8551
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    92
        """
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    93
        cs = common.recvcs(self.sock)
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    94
        version = ord(cs.read(1))
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    95
        if version != common.version:
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    96
            self.ui.warn(_('(inotify: received response from incompatible '
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
    97
                      'server version %d)\n') % version)
8552
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
    98
            raise QueryFailed('incompatible server version')
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
    99
8551
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   100
        # only one type of request is supported for now
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   101
        type = 'STAT'
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   102
        hdrfmt = common.resphdrfmts[type]
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   103
        hdrsize = common.resphdrsizes[type]
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   104
        try:
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   105
            resphdr = struct.unpack(hdrfmt, cs.read(hdrsize))
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   106
        except struct.error:
8552
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
   107
            raise QueryFailed('unable to retrieve query response headers')
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   108
8551
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   109
        return cs, resphdr
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   110
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   111
    def query(self, req):
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   112
        self._connect()
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   113
8551
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   114
        self._send(req)
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   115
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   116
        return self._receive()
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   117
8552
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
   118
    @start_server
8551
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   119
    def statusquery(self, names, match, ignored, clean, unknown=True):
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   120
8551
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   121
        def genquery():
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   122
            for n in names:
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   123
                yield n
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   124
            states = 'almrx!'
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   125
            if ignored:
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   126
                raise ValueError('this is insanity')
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   127
            if clean: states += 'c'
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   128
            if unknown: states += '?'
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   129
            yield states
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   130
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   131
        req = '\0'.join(genquery())
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   132
8551
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   133
        cs, resphdr = self.query(req)
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   134
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   135
        def readnames(nbytes):
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   136
            if nbytes:
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   137
                names = cs.read(nbytes)
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   138
                if names:
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   139
                    return filter(match, names.split('\0'))
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   140
            return []
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   141
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
   142
        return map(readnames, resphdr)