Commit cdb6c7ca authored by David Adam's avatar David Adam
Browse files

Return a dictionary rather than a string from each run

(allows us to return metadata like the success or failure of the job)
parent 54a23841
......@@ -43,20 +43,22 @@ class Host(object):
self.include_file, '[email protected]%s::/' % (self.hostname), self.destination ] ) )
def run_all(self):
result = ''
output = ''
success = False
try:
# only add output if error occurs
self.test_server()
self.test_directory()
# always print output
result += self.remove_old()
result += self.run_backup()
output += self.remove_old()
output += self.run_backup()
success = True
except subprocess.CalledProcessError as e:
result += e.output.decode('utf-8')
result += 'Backup failed with error %d' % e.returncode
output += e.output.decode('utf-8')
output += 'Backup failed with error %d' % e.returncode
except OSError as e:
result += 'Backup failed: %s (%d)' % (e.strerror, e.errno)
return result
output += 'Backup failed: %s (%d)' % (e.strerror, e.errno)
return {'success': success, 'output': output}
def rdiff_backup(config):
target = Host(config)
......@@ -82,12 +84,12 @@ if __name__ == '__main__':
pool = Pool(concurrent_num)
# Start the work and wait for it to finish
results = [ (host, pool.apply_async(rdiff_backup, (host, )) ) for host in hosts ]
results = { host['hostname']: pool.apply_async(rdiff_backup, (host, )) for host in hosts }
pool.close()
pool.join()
for host, r in results:
print("Backup results for", host['hostname'])
print(r.get())
for host, r in results.items():
print("Backup results for", host)
print(r.get()['output'])
print('-' * 40)
print()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment