loadtest_concat_yaml.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # Copyright 2021 The gRPC Authors
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 # Helper script to concatenate YAML files.
17 #
18 # This script concatenates multiple YAML files into a single multipart file.
19 # Input files are not parsed but processed as strings. This is a convenience
20 # script to concatenate output files generated by multiple runs of
21 # loadtest_config.py.
22 
23 import argparse
24 import sys
25 from typing import Iterable
26 
27 
28 def gen_content_strings(input_files: Iterable[str]) -> Iterable[str]:
29  if not input_files:
30  return
31 
32  with open(input_files[0]) as f:
33  content = f.read()
34  yield content
35 
36  for input_file in input_files[1:]:
37  with open(input_file) as f:
38  content = f.read()
39  yield '---\n'
40  yield content
41 
42 
43 def main() -> None:
44  argp = argparse.ArgumentParser(description='Concatenates YAML files.')
45  argp.add_argument('-i',
46  '--inputs',
47  action='extend',
48  nargs='+',
49  type=str,
50  required=True,
51  help='Input files.')
52  argp.add_argument(
53  '-o',
54  '--output',
55  type=str,
56  help='Concatenated output file. Output to stdout if not set.')
57  args = argp.parse_args()
58 
59  with open(args.output, 'w') if args.output else sys.stdout as f:
60  for content in gen_content_strings(args.inputs):
61  print(content, file=f, sep='', end='')
62 
63 
64 if __name__ == '__main__':
65  main()
performance.loadtest_concat_yaml.gen_content_strings
Iterable[str] gen_content_strings(Iterable[str] input_files)
Definition: loadtest_concat_yaml.py:28
performance.loadtest_concat_yaml.main
None main()
Definition: loadtest_concat_yaml.py:43
main
Definition: main.py:1
open
#define open
Definition: test-fs.c:46


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:16