2 import arvados.commands.put as put
6 def machine_progress(bytes_written, bytes_expected):
7 return "upload wrote {} total {}\n".format(
8 bytes_written, -1 if (bytes_expected is None) else bytes_expected)
11 def __init__(self, fn):
14 self.max_manifest_depth = 0
16 # Upload to Keep with error recovery.
17 # Return a uuid or raise an exception if there are too many failures.
18 def upload(source_dir):
19 source_dir = os.path.abspath(source_dir)
21 if 'TASK_WORK' in os.environ:
22 resume_cache = put.ResumeCache(os.path.join(arvados.current_task().tmpdir, "upload-output-checkpoint"))
24 resume_cache = put.ResumeCache(put.ResumeCache.make_path(Args(source_dir)))
25 reporter = put.progress_writer(machine_progress)
26 bytes_expected = put.expected_bytes_for([source_dir])
31 out = put.ArvPutCollectionWriter.from_cache(resume_cache, reporter, bytes_expected)
33 out.write_directory_tree(source_dir, max_manifest_depth=0)
34 outuuid = out.finish()
36 except KeyboardInterrupt as e:
37 logging.critical("caught interrupt signal 2")
39 except Exception as e:
40 logging.exception("caught exception:")
43 logging.critical("Too many upload failures, giving up")
46 logging.warning("Sleeping for %s seconds before trying again" % backoff)