ruby-livesync 1.0.0.beta4 → 1.0.0.beta5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 182e21dbd5e045ed2de4492cdefcd295dd92f9af62154ce4cfb7569610cd55ee
|
4
|
+
data.tar.gz: c3d0fe0760f40b408b9e3b72d0349dcf5a838f8aff1224ae2de424af508947fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76aa54c57ad5ee3b64fcee946432021d5e5e948125ffaf72c524bb81bd2abdfefbd53138a67772d05e557690b6ffb89cf608b6267ac124fcb3f0ecc84f59d9e1
|
7
|
+
data.tar.gz: b38edffeb1ae8e63d20346cebf2510da50950bd621d2bf8cf864d0975915b8ee91d823299449cc294225b9c657b966df9e2b934c5a22fe21a988c03e82b41e61
|
@@ -25,13 +25,13 @@ module LiveSync
|
|
25
25
|
|
26
26
|
Thread.new do
|
27
27
|
stdout.sync = true
|
28
|
-
|
28
|
+
stdout.each_line.each do |line|
|
29
29
|
file,events = parse line
|
30
30
|
yield [OpenStruct.new(absolute_name: file, flags: events)]
|
31
31
|
end
|
32
32
|
end
|
33
33
|
Thread.new do
|
34
|
-
STDERR.puts
|
34
|
+
stderr.each_line.each{ |line| STDERR.puts line }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -1,11 +1,13 @@
|
|
1
1
|
import pyinotify
|
2
2
|
import os
|
3
3
|
import time
|
4
|
+
import sys
|
4
5
|
|
5
6
|
class EventHandler(pyinotify.ProcessEvent):
|
6
|
-
def my_init(self, excludes, recursive, mask):
|
7
|
+
def my_init(self, excludes, recursive, mask, base_device):
|
7
8
|
self.excludes = excludes
|
8
9
|
self.recursive = recursive
|
10
|
+
self.base_device = base_device
|
9
11
|
self.mask = mask
|
10
12
|
self.events = set()
|
11
13
|
|
@@ -21,15 +23,32 @@ class EventHandler(pyinotify.ProcessEvent):
|
|
21
23
|
print(f"{event_desc} {full_path}", flush=True)
|
22
24
|
self.events.clear()
|
23
25
|
|
26
|
+
def watch_path(self, path):
|
27
|
+
if not any(exclude in path for exclude in self.excludes):
|
28
|
+
try:
|
29
|
+
if os.stat(path).st_dev == self.base_device:
|
30
|
+
wm.add_watch(path, self.mask, auto_add=True)
|
31
|
+
else:
|
32
|
+
print(f"Skipping {path} (different device)", file=sys.stderr)
|
33
|
+
except Exception as e:
|
34
|
+
print(f"Error adding watch on {path}: {e}", file=sys.stderr)
|
35
|
+
|
24
36
|
def add_watch(self, path):
|
25
|
-
|
37
|
+
if self.recursive:
|
38
|
+
for root, dirs, _ in os.walk(path):
|
39
|
+
self.watch_path(root)
|
40
|
+
for dir in dirs:
|
41
|
+
self.watch_path(os.path.join(root, dir))
|
42
|
+
else:
|
43
|
+
self.watch_path(path)
|
26
44
|
|
27
|
-
excludes
|
28
|
-
recursive
|
29
|
-
event_mask
|
45
|
+
excludes = [%{excludes}]
|
46
|
+
recursive = %{recursive}
|
47
|
+
event_mask = pyinotify.IN_CREATE | pyinotify.IN_MODIFY | pyinotify.IN_MOVED_TO | pyinotify.IN_DELETE # Event mask
|
48
|
+
base_device = os.stat('%{path}').st_dev
|
30
49
|
|
31
50
|
wm = pyinotify.WatchManager()
|
32
|
-
handler = EventHandler(excludes=excludes, recursive=recursive, mask=event_mask)
|
51
|
+
handler = EventHandler(excludes=excludes, recursive=recursive, mask=event_mask, base_device=base_device)
|
33
52
|
notifier = pyinotify.Notifier(wm, handler)
|
34
53
|
handler.add_watch('%{path}')
|
35
54
|
|