author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
Sun, 07 Sep 2008 15:10:11 +0200 | |
changeset 7024 | ee308d44ad76 |
parent 6239 | 39cfcef4f463 |
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 |
||
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') |
|
7024
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
17 |
try: |
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
18 |
sock.connect(sockpath) |
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
19 |
except socket.error, err: |
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
20 |
if err[0] == "AF_UNIX path too long": |
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
21 |
sockpath = os.readlink(sockpath) |
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
22 |
sock.connect(sockpath) |
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
23 |
else: |
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
24 |
raise |
6239 | 25 |
|
26 |
def genquery(): |
|
27 |
for n in names or []: |
|
28 |
yield n |
|
29 |
states = 'almrx!' |
|
30 |
if list_ignored: |
|
31 |
raise ValueError('this is insanity') |
|
32 |
if list_clean: states += 'n' |
|
33 |
if list_unknown: states += '?' |
|
34 |
yield states |
|
35 |
||
36 |
req = '\0'.join(genquery()) |
|
37 |
||
38 |
sock.sendall(chr(common.version)) |
|
39 |
sock.sendall(req) |
|
40 |
sock.shutdown(socket.SHUT_WR) |
|
41 |
||
42 |
cs = common.recvcs(sock) |
|
43 |
version = ord(cs.read(1)) |
|
44 |
||
45 |
if version != common.version: |
|
46 |
ui.warn(_('(inotify: received response from incompatible server ' |
|
47 |
'version %d)\n') % version) |
|
48 |
return None |
|
49 |
||
50 |
try: |
|
51 |
resphdr = struct.unpack(common.resphdrfmt, cs.read(common.resphdrsize)) |
|
52 |
except struct.error: |
|
53 |
return None |
|
54 |
||
55 |
def readnames(nbytes): |
|
56 |
if nbytes: |
|
57 |
names = cs.read(nbytes) |
|
58 |
if names: |
|
59 |
return filter(match, names.split('\0')) |
|
60 |
return [] |
|
61 |
||
62 |
return map(readnames, resphdr) |