Skip to content

Commit

Permalink
Added support for item-started and item-updated events to daemon inte…
Browse files Browse the repository at this point in the history
…rface; Nothing uses them for now
  • Loading branch information
kozec committed Sep 10, 2014
1 parent d9af6ca commit e7401ca
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
28 changes: 27 additions & 1 deletion syncthing_gtk/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ class Daemon(GObject.GObject, TimerManager):
Emited after repository scan is finished
id: id of repo
item-started (repo_id, filename, time):
Emited when synchronization of file starts
repo_id: id of repo that contains file
filename: synchronized file
time: event timestamp
item-updated (repo_id, filename, mtime):
Emited when change in local file is detected (LocalIndexUpdated event)
repo_id: id of repo that contains file
filename: updated file
mtime: last modification time of updated file
system-data-updated (ram_ussage, cpu_ussage, announce)
Emited every time when system informations are recieved
from daemon.
Expand Down Expand Up @@ -178,6 +190,8 @@ class Daemon(GObject.GObject, TimerManager):
b"repo-scan-started" : (GObject.SIGNAL_RUN_FIRST, None, (object,)),
b"repo-scan-finished" : (GObject.SIGNAL_RUN_FIRST, None, (object,)),
b"repo-scan-progress" : (GObject.SIGNAL_RUN_FIRST, None, (object,)),
b"item-started" : (GObject.SIGNAL_RUN_FIRST, None, (object,object,object)),
b"item-updated" : (GObject.SIGNAL_RUN_FIRST, None, (object,object,object)),
b"system-data-updated" : (GObject.SIGNAL_RUN_FIRST, None, (int, float, int)),
}

Expand Down Expand Up @@ -809,7 +823,7 @@ def _on_event(self, e):
rid = e["data"]["repo"]
if self._repo_state_changed(rid, state, 0):
self._needs_update.add(rid)
elif eType in ("LocalIndexUpdated", "RemoteIndexUpdated"):
elif eType in ("RemoteIndexUpdated"):
rid = e["data"]["repo"]
if (not rid in self._syncing_nodes) and (not rid in self._scanning_repos):
self._needs_update.add(rid)
Expand All @@ -832,6 +846,18 @@ def _on_event(self, e):
nid = e["data"]["node"]
address = e["data"]["address"]
self.emit("node-rejected", nid, address)
elif eType == "ItemStarted":
rid = e["data"]["repo"]
filename = e["data"]["item"]
t = parsetime(e["time"])
self.emit("item-started", rid, filename, t)
elif eType == "LocalIndexUpdated":
rid = e["data"]["repo"]
filename = e["data"]["name"]
mtime = parsetime(e["data"]["modified"])
if (not rid in self._syncing_nodes) and (not rid in self._scanning_repos):
self._needs_update.add(rid)
self.emit("item-updated", rid, filename, mtime)
else:
print "Unhandled event type:", e

Expand Down
18 changes: 13 additions & 5 deletions syncthing_gtk/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,23 @@ def dst(self, dt):
return timedelta(0)

PARSER = re.compile(r"([-0-9]+)[A-Z]([:0-9]+)\.([0-9]+)([\-\+][0-9]+):([0-9]+)")
PARSER_NODOT = re.compile(r"([-0-9]+)[A-Z]([:0-9]+)([\-\+][0-9]+):([0-9]+)")
FORMAT = "%Y-%m-%d %H:%M:%S %f"

def parsetime(m):
""" Parses time recieved from Syncthing daemon """
match = PARSER.match(m)
times = list(match.groups()[0:3])
times[2] = times[2][0:6]
reformat = "%s %s %s" % tuple(times)
tz = Timezone(int(match.group(4)), int(match.group(5)))
reformat, tz = None, None
if "." in m:
match = PARSER.match(m)
times = list(match.groups()[0:3])
times[2] = times[2][0:6]
reformat = "%s %s %s" % tuple(times)
tz = Timezone(int(match.group(4)), int(match.group(5)))
else:
match = PARSER_NODOT.match(m)
times = list(match.groups()[0:2])
reformat = "%s %s 00" % tuple(times)
tz = Timezone(int(match.group(3)), int(match.group(4)))
return datetime.strptime(reformat, FORMAT).replace(tzinfo=tz)

def delta_to_string(d):
Expand Down

0 comments on commit e7401ca

Please sign in to comment.