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