2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: Apache-2.0
9 # Decompress all compressed files in the collection using the "dtrx" tool and
10 # produce a new collection with the contents. Uncompressed files
14 # A collection at script_parameters["input"]
17 # A manifest of the uncompressed contents of the input collection.
24 import crunchutil.robust_put as robust_put
26 arvados.job_setup.one_task_per_input_file(if_sequence=0, and_end_task=True,
29 task = arvados.current_task()
31 input_file = task['parameters']['input']
33 infile_parts = re.match(r"(^[a-f0-9]{32}\+\d+)(\+\S+)*(/.*)?(/[^/]+)$", input_file)
35 outdir = os.path.join(task.tmpdir, "output")
39 if infile_parts is None:
40 print >>sys.stderr, "Failed to parse input filename '%s' as a Keep file\n" % input_file
43 cr = arvados.CollectionReader(infile_parts.group(1))
44 streamname = infile_parts.group(3)[1:]
45 filename = infile_parts.group(4)[1:]
47 if streamname is not None:
48 subprocess.call(["mkdir", "-p", streamname])
53 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)
56 rc = subprocess.call(["dtrx", "-r", "-n", "-q", arvados.get_task_param_mount('input')])
58 task.set_output(robust_put.upload(outdir))
62 streamreader = filter(lambda s: s.name() == streamname, cr.all_streams())[0]
63 filereader = streamreader.files()[filename]
64 task.set_output(streamname + filereader.as_manifest()[1:])