Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 29 lines (22 sloc) 0.82 kB
7bcb582 @engla Find files created by external processes as Async results
authored
1 import gio
2
3 from kupfer.objects import FileLeaf
4
d528342 @engla Port runtimehelper and image, archivemanager to wants_context
authored
5 def register_async_file_result(ctx, filepath):
6 """
7 Register that @filepath may appear soon
8 @ctx: The action's execution context token
9 """
10 return AsyncFileResult(ctx, filepath)
7bcb582 @engla Find files created by external processes as Async results
authored
11
12 class AsyncFileResult (object):
13 """Expect a given file path to be created, and when (probably) done,
14 post the file as a late result.
15 """
d528342 @engla Port runtimehelper and image, archivemanager to wants_context
authored
16 def __init__(self, ctx, filepath):
17 self.ctx = ctx
7bcb582 @engla Find files created by external processes as Async results
authored
18 gfile = gio.File(filepath)
19 self.monitor = gfile.monitor_file(gio.FILE_MONITOR_NONE)
20 self.callback_id = self.monitor.connect("changed", self.changed)
21
22 def changed(self, monitor, gfile1, gfile2, event):
23 if event == gio.FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
d528342 @engla Port runtimehelper and image, archivemanager to wants_context
authored
24 self.ctx.register_late_result(FileLeaf(gfile1.get_path()))
7bcb582 @engla Find files created by external processes as Async results
authored
25 self.monitor.disconnect(self.callback_id)
26 self.monitor = None
27
28
Something went wrong with that request. Please try again.