6 # Decompress all compressed files in the collection using the "dtrx" tool and
7 # produce a new collection with the contents. Uncompressed files
11 # A collection at script_parameters["input"]
14 # A manifest of the uncompressed contents of the input collection.
22 arvados.job_setup.one_task_per_input_file(if_sequence=0, and_end_task=True,
25 task = arvados.current_task()
27 input_file = task['parameters']['input']
29 infile_parts = re.match(r"(^[a-f0-9]{32}\+\d+)(\+\S+)*(/.*)?(/[^/]+)$", input_file)
31 outdir = os.path.join(task.tmpdir, "output")
35 if infile_parts == None:
36 print >>sys.stderr, "Failed to parse input filename '%s' as a Keep file\n" % input_file
39 cr = arvados.CollectionReader(infile_parts.group(1))
40 streamname = infile_parts.group(3)[1:]
41 filename = infile_parts.group(4)[1:]
43 if streamname != None:
44 subprocess.call(["mkdir", "-p", streamname])
49 m = re.match(r'\.(gz|Z|bz2|tgz|tbz|zip|rar|7z|cab|deb|rpm|cpio|gem)$', arvados.get_task_param_mount('input'), re.IGNORECASE)
52 rc = subprocess.call(["dtrx", "-r", "-n", "-q", arvados.get_task_param_mount('input')])
54 out = arvados.CollectionWriter()
55 out.write_directory_tree(outdir, max_manifest_depth=0)
56 task.set_output(out.finish())
60 streamreader = filter(lambda s: s.name() == streamname, cr.all_streams())[0]
61 filereader = streamreader.files()[filename]
62 task.set_output(streamname + filereader.as_manifest()[1:])