instance.py

changeset 21
c36e549a7f12
parent 20
fdfbe5d7b677
child 23
86b42610d5a8
equal deleted inserted replaced
20:fdfbe5d7b677 21:c36e549a7f12
34 if self.operation in necessary_opts_for: 34 if self.operation in necessary_opts_for:
35 cmd=cmd+necessary_opts_for[self.operation] 35 cmd=cmd+necessary_opts_for[self.operation]
36 36
37 return cmd+arglistify(self.args)+[self.archive_or_repository]+self.argsl 37 return cmd+arglistify(self.args)+[self.archive_or_repository]+self.argsl
38 38
39 def launch(self, password=None): 39 def launch(self, passphrase=None):
40 cmd=self.construct_cmdline() 40 cmd=self.construct_cmdline()
41 41
42 logging.info('Launching ' + str(cmd)) 42 logging.info('Launching ' + str(cmd))
43 43
44 env=None 44 env=None
45 if password: 45 if passphrase:
46 env=os.environ.copy() 46 env=os.environ.copy()
47 env['BORG_PASSPHRASE']=password 47 env['BORG_PASSPHRASE']=passphrase
48 48
49 self.proc=Popen(cmd, env=env, stdout=PIPE, stderr=PIPE, stdin=PIPE) 49 self.proc=Popen(cmd, env=env, stdout=PIPE, stderr=PIPE, stdin=PIPE)
50 50
51 # We don't do password input etc. 51 # We don't do passphrase input etc.
52 self.proc.stdin.close() 52 self.proc.stdin.close()
53 53
54 def read_result(self): 54 def read_result(self):
55 stream=self.proc.stdout 55 stream=self.proc.stdout
56 line=stream.read(-1) 56 line=stream.read(-1)
69 try: 69 try:
70 line=stream.readline() 70 line=stream.readline()
71 except err: 71 except err:
72 logging.debug('Pipe read failed: %s' % str(err)) 72 logging.debug('Pipe read failed: %s' % str(err))
73 73
74 return {'type': 'exception', 'exception': err} 74 return {'type': 'log_message',
75 'levelname': 'CRITICAL',
76 'name': 'borgend.instance.BorgInstance',
77 'msgid': 'Borgend.Exception',
78 'message': err}
75 79
76 if line==b'': 80 if line==b'':
77 81
78 logging.debug('Borg stderr pipe EOF?') 82 logging.debug('Borg stderr pipe EOF?')
79 83
89 93
90 errmsg=line 94 errmsg=line
91 for line in iter(stream.readline, b''): 95 for line in iter(stream.readline, b''):
92 errmsg=errmsg+line 96 errmsg=errmsg+line
93 97
94 return {'type': 'unparsed_error', 'message': str(errmsg)} 98 return {'type': 'log_message',
99 'levelname': 'ERROR',
100 'name': 'borgend.instance.BorgInstance',
101 'msgid': 'Borgend.JSONFail',
102 'message': str(errmsg)}
95 103
96 def terminate(self): 104 def terminate(self):
97 self.proc.terminate() 105 self.proc.terminate()
98 106
99 def wait(self): 107 def wait(self):

mercurial