author | Gilles Moris <gilles.moris@free.fr> |
Fri, 22 Aug 2008 22:32:53 +0200 | |
changeset 6935 | 03916abdfb64 |
parent 6753 | ed5ffb2c12f3 |
child 7027 | ab57069232b4 |
permissions | -rw-r--r-- |
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 |
||
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6239
diff
changeset
|
14 |
def query(ui, repo, names, match, ignored, clean, unknown=True): |
6239 | 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!' |
|
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6239
diff
changeset
|
23 |
if ignored: |
6239 | 24 |
raise ValueError('this is insanity') |
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6239
diff
changeset
|
25 |
if clean: states += 'n' |
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6239
diff
changeset
|
26 |
if unknown: states += '?' |
6239 | 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) |