diff -r e343594c0014 -r 4cad934aa9ce instance.py --- a/instance.py Fri Jan 19 10:41:01 2018 +0000 +++ b/instance.py Fri Jan 19 14:42:27 2018 +0000 @@ -5,25 +5,13 @@ import json from subprocess import Popen, PIPE from config import settings, arglistify -from queue import Queue -from threading import Thread - -def linereader(stream, instance, queue): - # What to do on error? - for line in iter(stream.readline, b''): - status=json.loads(line) - queue.put({'identifier': instance.identifier, - 'operation': instance.operation, - 'status': status}) - out.close() class BorgInstance: - def __init__(self, identifier, operation, args, archive, argsl): - self.identifier=identifier; + def __init__(self, operation, archive_or_repository, args, argsl): self.operation=operation; self.args=args; - self.archive=archive; + self.archive_or_repository=archive_or_repository; self.argsl=argsl; def construct_cmdline(self): @@ -33,22 +21,41 @@ tmp1=self.operation+'_parameters' if tmp1 in settings['borg']: cmd=cmd+arglistify(settings['borg'][tmp1]) - return cmd+arglistify(self.args)+[self.archive]+self.argsl + cmd=cmd+arglistify(self.args)+[self.archive_or_repository]+self.argsl + print(cmd) + return cmd - def launch(self, queue): + def launch(self): # What to do with stderr? Is it needed? self.proc=Popen(self.construct_cmdline(), stdout=PIPE, stderr=PIPE) - linereaderargs=(self.proc.stdout, self, queue) - self.t=Thread(target=linereader, args=linereaderargs) - t.daemon=True - t.start() - def read_output(): - try: - obj=self.queue.get_nowait() - except Empty: - obj=Empty - return obj + def read(self): + line=self.proc.stdout.readline() + if line==b'': + line=self.proc.stderr.readline() + if line==b'': + return None + print('EEE'+str(line)) + return 'error' + else: + print('###' + str(line)) + # # What to do on error? stderr? + status=json.loads(line) + return status + + # for line in iter(stream.readline, b''): + # status=json.loads(line) + # queue.put({'identifier': instance.identifier, + # 'operation': instance.operation, + # 'status': status}) + # out.close() + + # def read_output(): + # try: + # obj=self.queue.get_nowait() + # except Empty: + # obj=Empty + # return obj