8784: Fix test for latest firefox.
[arvados.git] / crunch_scripts / collection-merge
1 #!/usr/bin/env python
2
3 # collection-merge
4 #
5 # Merge two or more collections together.  Can also be used to extract specific
6 # files from a collection to produce a new collection.
7 #
8 # input:
9 # An array of collections or collection/file paths in script_parameter["input"]
10 #
11 # output:
12 # A manifest with the collections merged.  Duplicate file names will
13 # have their contents concatenated in the order that they appear in the input
14 # array.
15
16 import arvados
17 import md5
18 import crunchutil.subst as subst
19 import subprocess
20 import os
21 import hashlib
22
23 p = arvados.current_job()['script_parameters']
24
25 merged = ""
26 src = []
27 for c in p["input"]:
28     c = subst.do_substitution(p, c)
29     i = c.find('/')
30     if i == -1:
31         src.append(c)
32         merged += arvados.CollectionReader(c).manifest_text()
33     else:
34         src.append(c[0:i])
35         cr = arvados.CollectionReader(c[0:i])
36         j = c.rfind('/')
37         stream = c[i+1:j]
38         if stream == "":
39             stream = "."
40         fn = c[(j+1):]
41         for s in cr.all_streams():
42             if s.name() == stream:
43                 if fn in s.files():
44                     merged += s.files()[fn].as_manifest()
45
46 arvados.current_task().set_output(merged)