8937: Return True for Head requests in KeepClients. The tests in KeepClientRetryHeadT...
[arvados.git] / sdk / python / arvados / crunch.py
1 import json
2 import os
3
4 class TaskOutputDir(object):
5     """Keep-backed directory for staging outputs of Crunch tasks.
6
7     Example, in a crunch task whose output is a file called "out.txt"
8     containing "42":
9
10         import arvados
11         import arvados.crunch
12         import os
13
14         out = arvados.crunch.TaskOutputDir()
15         with open(os.path.join(out.path, 'out.txt'), 'w') as f:
16             f.write('42')
17         arvados.current_task().set_output(out.manifest_text())
18     """
19     def __init__(self):
20         self.path = os.environ['TASK_KEEPMOUNT_TMP']
21
22     def __str__(self):
23         return self.path
24
25     def manifest_text(self):
26         snapshot = os.path.join(self.path, '.arvados#collection')
27         return json.load(open(snapshot))['manifest_text']