Fri, 19 Jan 2018 14:42:27 +0000
Can launch borg now; output not yet processed
# # Borgend borg launcher / processor # import json from subprocess import Popen, PIPE from config import settings, arglistify class BorgInstance: def __init__(self, operation, archive_or_repository, args, argsl): self.operation=operation; self.args=args; self.archive_or_repository=archive_or_repository; self.argsl=argsl; def construct_cmdline(self): cmd=([settings['borg']['executable'], '--log-json']+ arglistify(settings['borg']['common_parameters'])+ [self.operation]) tmp1=self.operation+'_parameters' if tmp1 in settings['borg']: cmd=cmd+arglistify(settings['borg'][tmp1]) cmd=cmd+arglistify(self.args)+[self.archive_or_repository]+self.argsl print(cmd) return cmd def launch(self): # What to do with stderr? Is it needed? self.proc=Popen(self.construct_cmdline(), stdout=PIPE, stderr=PIPE) 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