major search and replace from python to python3
[arvados.git] / doc / _includes / _0_filter_py.liquid
1 #!/usr/bin/env python3
2 {% comment %}
3 Copyright (C) The Arvados Authors. All rights reserved.
4
5 SPDX-License-Identifier: CC-BY-SA-3.0
6 {% endcomment %}
7
8 # Import the Arvados sdk module
9 import arvados
10
11 # Get information about the task from the environment
12 this_task = arvados.current_task()
13
14 this_task_input = arvados.current_job()['script_parameters']['input']
15
16 # Create the object access to the collection referred to in the input
17 collection = arvados.CollectionReader(this_task_input)
18
19 # Create an object to write a new collection as output
20 out = arvados.CollectionWriter()
21
22 # Create a new file in the output collection
23 with out.open('0-filter.txt') as out_file:
24     # Iterate over every input file in the input collection
25     for input_file in collection.all_files():
26         # Output every line in the file that starts with '0'
27         out_file.writelines(line for line in input_file if line.startswith('0'))
28
29 # Commit the output to Keep.
30 output_locator = out.finish()
31
32 # Use the resulting locator as the output for this task.
33 this_task.set_output(output_locator)
34
35 # Done!