• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 the gRPC authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""A dummy plugin for testing"""
15
16import sys
17
18from google.protobuf.compiler.plugin_pb2 import CodeGeneratorRequest
19from google.protobuf.compiler.plugin_pb2 import CodeGeneratorResponse
20
21
22def main(input_file=sys.stdin, output_file=sys.stdout):
23    request = CodeGeneratorRequest.FromString(input_file.buffer.read())
24    answer = []
25    for fname in request.file_to_generate:
26        answer.append(CodeGeneratorResponse.File(
27            name=fname.replace('.proto', '_pb2.py'),
28            insertion_point='module_scope',
29            content="# Hello {}, I'm a dummy plugin!".format(fname),
30        ))
31
32    cgr = CodeGeneratorResponse(file=answer)
33    output_file.buffer.write(cgr.SerializeToString())
34
35
36if __name__ == '__main__':
37    main()
38