Merge branch 'master' into 3699-arv-copy
[arvados.git] / doc / _includes / _0_filter_py.liquid
1 #!/usr/bin/env python
2
3 # Import the Arvados sdk module
4 import arvados
5
6 # Get information about the task from the environment
7 this_task = arvados.current_task()
8
9 this_task_input = arvados.current_job()['script_parameters']['input']
10
11 # Create the object access to the collection referred to in the input
12 collection = arvados.CollectionReader(this_task_input)
13
14 # Create an object to write a new collection as output
15 out = arvados.CollectionWriter()
16
17 # Set the name of output file within the collection
18 out.set_current_file_name("0-filter.txt")
19
20 # Get an iterator over the files listed in the collection
21 all_files = collection.all_files()
22
23 # Iterate over each file
24 for input_file in all_files:
25     for ln in input_file.readlines():
26         if ln[0] == '0':
27             out.write(ln)
28
29 # Commit the output to keep.  This returns a Keep id.
30 output_id = out.finish()
31
32 # Set the output for this task to the Keep id
33 this_task.set_output(output_id)
34
35 # Done!