| |
1 # |
| |
2 # Borgend borg launcher / processor |
| |
3 # |
| |
4 |
| |
5 import json |
| |
6 import subprocess |
| |
7 import config |
| |
8 import Queue |
| |
9 import Thread |
| |
10 |
| |
11 def linereader(stream, instance, queue) |
| |
12 # What to do on error? |
| |
13 for line in iter(stream.readline, b''): |
| |
14 status=json.loads(line) |
| |
15 queue.put({'identifier': instance.identifier, |
| |
16 'operation': instance.operation, |
| |
17 'status': status}) |
| |
18 out.close() |
| |
19 |
| |
20 class BorgInstance: |
| |
21 |
| |
22 def __init__(self, identifier, operation, args): |
| |
23 self.identifier=identifier; |
| |
24 self.operation=operation; |
| |
25 self.args=args; |
| |
26 |
| |
27 def construct_cmdline(self): |
| |
28 ??? |
| |
29 |
| |
30 def launch(self, queue): |
| |
31 # What to do with stderr? Is it needed? |
| |
32 self.proc=subprocess.Popen(self.construct_cmdline(), |
| |
33 stdout=subprocess.PIPE, |
| |
34 stderr=subprocess.PIPE) |
| |
35 linereaderargs=(self.proc.stdout, self, queue) |
| |
36 self.t=Thread(target=linereader, args=linereaderargs) |
| |
37 t.daemon=True |
| |
38 t.start() |
| |
39 |
| |
40 def read_output(): |
| |
41 try: |
| |
42 obj=self.queue.get_nowait() |
| |
43 except Empty: |
| |
44 obj=Empty |
| |
45 return obj |
| |
46 |
| |
47 |
| |
48 |
| |
49 |