6239
|
1 |
# client.py - inotify status client
|
|
2 |
#
|
|
3 |
# Copyright 2006, 2007, 2008 Bryan O'Sullivan <bos@serpentine.com>
|
|
4 |
# Copyright 2007, 2008 Brendan Cully <brendan@kublai.com>
|
|
5 |
#
|
|
6 |
# This software may be used and distributed according to the terms
|
|
7 |
# of the GNU General Public License, incorporated herein by reference.
|
|
8 |
|
|
9 |
from mercurial.i18n import gettext as _
|
|
10 |
from mercurial import ui
|
|
11 |
import common
|
|
12 |
import os, select, socket, stat, struct, sys
|
|
13 |
|
|
14 |
def query(ui, repo, names, match, list_ignored, list_clean, list_unknown=True):
|
|
15 |
sock = socket.socket(socket.AF_UNIX)
|
|
16 |
sockpath = repo.join('inotify.sock')
|
|
17 |
sock.connect(sockpath)
|
|
18 |
|
|
19 |
def genquery():
|
|
20 |
for n in names or []:
|
|
21 |
yield n
|
|
22 |
states = 'almrx!'
|
|
23 |
if list_ignored:
|
|
24 |
raise ValueError('this is insanity')
|
|
25 |
if list_clean: states += 'n'
|
|
26 |
if list_unknown: states += '?'
|
|
27 |
yield states
|
|
28 |
|
|
29 |
req = '\0'.join(genquery())
|
|
30 |
|
|
31 |
sock.sendall(chr(common.version))
|
|
32 |
sock.sendall(req)
|
|
33 |
sock.shutdown(socket.SHUT_WR)
|
|
34 |
|
|
35 |
cs = common.recvcs(sock)
|
|
36 |
version = ord(cs.read(1))
|
|
37 |
|
|
38 |
if version != common.version:
|
|
39 |
ui.warn(_('(inotify: received response from incompatible server '
|
|
40 |
'version %d)\n') % version)
|
|
41 |
return None
|
|
42 |
|
|
43 |
try:
|
|
44 |
resphdr = struct.unpack(common.resphdrfmt, cs.read(common.resphdrsize))
|
|
45 |
except struct.error:
|
|
46 |
return None
|
|
47 |
|
|
48 |
def readnames(nbytes):
|
|
49 |
if nbytes:
|
|
50 |
names = cs.read(nbytes)
|
|
51 |
if names:
|
|
52 |
return filter(match, names.split('\0'))
|
|
53 |
return []
|
|
54 |
|
|
55 |
return map(readnames, resphdr)
|