X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/18258f6a3762ba7d83b05260b3c22f71423c0373..bd8bdd90055d61263eff5bdb9a953c57319aa83d:/doc/_includes/_0_filter_py.liquid diff --git a/doc/_includes/_0_filter_py.liquid b/doc/_includes/_0_filter_py.liquid index 035c4818c9..ff055dbb59 100644 --- a/doc/_includes/_0_filter_py.liquid +++ b/doc/_includes/_0_filter_py.liquid @@ -1,4 +1,9 @@ #!/usr/bin/env python +{% comment %} +Copyright (C) The Arvados Authors. All rights reserved. + +SPDX-License-Identifier: CC-BY-SA-3.0 +{% endcomment %} # Import the Arvados sdk module import arvados @@ -14,22 +19,17 @@ collection = arvados.CollectionReader(this_task_input) # Create an object to write a new collection as output out = arvados.CollectionWriter() -# Set the name of output file within the collection -out.set_current_file_name("0-filter.txt") - -# Get an iterator over the files listed in the collection -all_files = collection.all_files() - -# Iterate over each file -for input_file in all_files: - for ln in input_file.readlines(): - if ln[0] == '0': - out.write(ln) +# Create a new file in the output collection +with out.open('0-filter.txt') as out_file: + # Iterate over every input file in the input collection + for input_file in collection.all_files(): + # Output every line in the file that starts with '0' + out_file.writelines(line for line in input_file if line.startswith('0')) -# Commit the output to keep. This returns a Keep id. -output_id = out.finish() +# Commit the output to Keep. +output_locator = out.finish() -# Set the output for this task to the Keep id -this_task.set_output(output_id) +# Use the resulting locator as the output for this task. +this_task.set_output(output_locator) # Done!