Show More
@@ -25,7 +25,7 b' def serve(ui, repo, **opts):' | |||||
25 | class service: |
|
25 | class service: | |
26 | def init(self): |
|
26 | def init(self): | |
27 | try: |
|
27 | try: | |
28 |
self.master = server. |
|
28 | self.master = server.master(ui, repo, timeout) | |
29 | except server.AlreadyStartedException, inst: |
|
29 | except server.AlreadyStartedException, inst: | |
30 | raise util.Abort(str(inst)) |
|
30 | raise util.Abort(str(inst)) | |
31 |
|
31 |
@@ -11,12 +11,12 b'' | |||||
11 | The inotify subsystem provides an efficient mechanism for file status |
|
11 | The inotify subsystem provides an efficient mechanism for file status | |
12 | monitoring and change notification. |
|
12 | monitoring and change notification. | |
13 |
|
13 | |||
14 |
The |
|
14 | The watcher class hides the low-level details of the inotify | |
15 | interface, and provides a Pythonic wrapper around it. It generates |
|
15 | interface, and provides a Pythonic wrapper around it. It generates | |
16 | events that provide somewhat more information than raw inotify makes |
|
16 | events that provide somewhat more information than raw inotify makes | |
17 | available. |
|
17 | available. | |
18 |
|
18 | |||
19 |
The |
|
19 | The autowatcher class is more useful, as it automatically watches | |
20 | newly-created directories on your behalf.''' |
|
20 | newly-created directories on your behalf.''' | |
21 |
|
21 | |||
22 | __author__ = "Bryan O'Sullivan <bos@serpentine.com>" |
|
22 | __author__ = "Bryan O'Sullivan <bos@serpentine.com>" | |
@@ -29,7 +29,7 b' import os' | |||||
29 | import termios |
|
29 | import termios | |
30 |
|
30 | |||
31 |
|
31 | |||
32 |
class |
|
32 | class event(object): | |
33 | '''Derived inotify event class. |
|
33 | '''Derived inotify event class. | |
34 |
|
34 | |||
35 | The following fields are available: |
|
35 | The following fields are available: | |
@@ -72,7 +72,7 b' class Event(object):' | |||||
72 |
|
72 | |||
73 | def __repr__(self): |
|
73 | def __repr__(self): | |
74 | r = repr(self.raw) |
|
74 | r = repr(self.raw) | |
75 |
return ' |
|
75 | return 'event(path=' + repr(self.path) + ', ' + r[r.find('(')+1:] | |
76 |
|
76 | |||
77 |
|
77 | |||
78 | _event_props = { |
|
78 | _event_props = { | |
@@ -100,12 +100,12 b' for k, v in _event_props.iteritems():' | |||||
100 | return self.mask & mask |
|
100 | return self.mask & mask | |
101 | getter.__name__ = k |
|
101 | getter.__name__ = k | |
102 | getter.__doc__ = v |
|
102 | getter.__doc__ = v | |
103 |
setattr( |
|
103 | setattr(event, k, property(getter, doc=v)) | |
104 |
|
104 | |||
105 | del _event_props |
|
105 | del _event_props | |
106 |
|
106 | |||
107 |
|
107 | |||
108 |
class |
|
108 | class watcher(object): | |
109 | '''Provide a Pythonic interface to the low-level inotify API. |
|
109 | '''Provide a Pythonic interface to the low-level inotify API. | |
110 |
|
110 | |||
111 | Also adds derived information to each event that is not available |
|
111 | Also adds derived information to each event that is not available | |
@@ -177,7 +177,7 b' class Watcher(object):' | |||||
177 |
|
177 | |||
178 | events = [] |
|
178 | events = [] | |
179 | for evt in inotify.read(self.fd, bufsize): |
|
179 | for evt in inotify.read(self.fd, bufsize): | |
180 |
events.append( |
|
180 | events.append(event(evt, self._wds[evt.wd][0])) | |
181 | if evt.mask & inotify.IN_IGNORED: |
|
181 | if evt.mask & inotify.IN_IGNORED: | |
182 | self._remove(evt.wd) |
|
182 | self._remove(evt.wd) | |
183 | elif evt.mask & inotify.IN_UNMOUNT: |
|
183 | elif evt.mask & inotify.IN_UNMOUNT: | |
@@ -265,8 +265,8 b' class Watcher(object):' | |||||
265 | return [w for w in self.add_iter(path, mask, onerror)] |
|
265 | return [w for w in self.add_iter(path, mask, onerror)] | |
266 |
|
266 | |||
267 |
|
267 | |||
268 |
class |
|
268 | class autowatcher(watcher): | |
269 |
''' |
|
269 | '''watcher class that automatically watches newly created directories.''' | |
270 |
|
270 | |||
271 | __slots__ = ( |
|
271 | __slots__ = ( | |
272 | 'addfilter', |
|
272 | 'addfilter', | |
@@ -284,13 +284,13 b' class AutoWatcher(Watcher):' | |||||
284 | True, the directory will be watched if it still exists, |
|
284 | True, the directory will be watched if it still exists, | |
285 | otherwise, it will beb skipped.''' |
|
285 | otherwise, it will beb skipped.''' | |
286 |
|
286 | |||
287 |
super( |
|
287 | super(autowatcher, self).__init__() | |
288 | self.addfilter = addfilter |
|
288 | self.addfilter = addfilter | |
289 |
|
289 | |||
290 | _dir_create_mask = inotify.IN_ISDIR | inotify.IN_CREATE |
|
290 | _dir_create_mask = inotify.IN_ISDIR | inotify.IN_CREATE | |
291 |
|
291 | |||
292 | def read(self, bufsize=None): |
|
292 | def read(self, bufsize=None): | |
293 |
events = super( |
|
293 | events = super(autowatcher, self).read(bufsize) | |
294 | for evt in events: |
|
294 | for evt in events: | |
295 | if evt.mask & self._dir_create_mask == self._dir_create_mask: |
|
295 | if evt.mask & self._dir_create_mask == self._dir_create_mask: | |
296 | if self.addfilter is None or self.addfilter(evt): |
|
296 | if self.addfilter is None or self.addfilter(evt): | |
@@ -305,7 +305,7 b' class AutoWatcher(Watcher):' | |||||
305 | return events |
|
305 | return events | |
306 |
|
306 | |||
307 |
|
307 | |||
308 |
class |
|
308 | class threshold(object): | |
309 | '''Class that indicates whether a file descriptor has reached a |
|
309 | '''Class that indicates whether a file descriptor has reached a | |
310 | threshold of readable bytes available. |
|
310 | threshold of readable bytes available. | |
311 |
|
311 |
@@ -113,7 +113,7 b' def _explain_watch_limit(ui, repo, count' | |||||
113 | raise util.Abort(_('cannot watch %s until inotify watch limit is raised') |
|
113 | raise util.Abort(_('cannot watch %s until inotify watch limit is raised') | |
114 | % repo.root) |
|
114 | % repo.root) | |
115 |
|
115 | |||
116 |
class |
|
116 | class repowatcher(object): | |
117 | poll_events = select.POLLIN |
|
117 | poll_events = select.POLLIN | |
118 | statuskeys = 'almr!?' |
|
118 | statuskeys = 'almr!?' | |
119 | mask = ( |
|
119 | mask = ( | |
@@ -136,11 +136,11 b' class RepoWatcher(object):' | |||||
136 | self.timeout = None |
|
136 | self.timeout = None | |
137 | self.master = master |
|
137 | self.master = master | |
138 | try: |
|
138 | try: | |
139 |
self.watcher = watcher. |
|
139 | self.watcher = watcher.watcher() | |
140 | except OSError, err: |
|
140 | except OSError, err: | |
141 | raise util.Abort(_('inotify service not available: %s') % |
|
141 | raise util.Abort(_('inotify service not available: %s') % | |
142 | err.strerror) |
|
142 | err.strerror) | |
143 |
self.threshold = watcher. |
|
143 | self.threshold = watcher.threshold(self.watcher) | |
144 | self.registered = True |
|
144 | self.registered = True | |
145 | self.fileno = self.watcher.fileno |
|
145 | self.fileno = self.watcher.fileno | |
146 |
|
146 | |||
@@ -542,7 +542,7 b' class RepoWatcher(object):' | |||||
542 | def shutdown(self): |
|
542 | def shutdown(self): | |
543 | self.watcher.close() |
|
543 | self.watcher.close() | |
544 |
|
544 | |||
545 |
class |
|
545 | class server(object): | |
546 | poll_events = select.POLLIN |
|
546 | poll_events = select.POLLIN | |
547 |
|
547 | |||
548 | def __init__(self, ui, repo, repowatcher, timeout): |
|
548 | def __init__(self, ui, repo, repowatcher, timeout): | |
@@ -658,13 +658,13 b' class Server(object):' | |||||
658 | if err.errno != errno.ENOENT: |
|
658 | if err.errno != errno.ENOENT: | |
659 | raise |
|
659 | raise | |
660 |
|
660 | |||
661 |
class |
|
661 | class master(object): | |
662 | def __init__(self, ui, repo, timeout=None): |
|
662 | def __init__(self, ui, repo, timeout=None): | |
663 | self.ui = ui |
|
663 | self.ui = ui | |
664 | self.repo = repo |
|
664 | self.repo = repo | |
665 | self.poll = select.poll() |
|
665 | self.poll = select.poll() | |
666 |
self.repowatcher = |
|
666 | self.repowatcher = repowatcher(ui, repo, self) | |
667 |
self.server = |
|
667 | self.server = server(ui, repo, self.repowatcher, timeout) | |
668 | self.table = {} |
|
668 | self.table = {} | |
669 | for obj in (self.repowatcher, self.server): |
|
669 | for obj in (self.repowatcher, self.server): | |
670 | fd = obj.fileno() |
|
670 | fd = obj.fileno() | |
@@ -727,7 +727,7 b' def start(ui, repo):' | |||||
727 | except OSError: |
|
727 | except OSError: | |
728 | pass |
|
728 | pass | |
729 |
|
729 | |||
730 |
m = |
|
730 | m = master(ui, repo) | |
731 | sys.stdout.flush() |
|
731 | sys.stdout.flush() | |
732 | sys.stderr.flush() |
|
732 | sys.stderr.flush() | |
733 |
|
733 |
General Comments 0
You need to be logged in to leave comments.
Login now