parameters: (
          src_folder,
          src_proto_file,
          dst_py_file)
docstring: Generates pb2.py files from corresponding .proto files
docstring_summary: Generates pb2.py files from corresponding .proto files
docstring_tokens: Generates pb2 . py files from corresponding . proto files
function: def generate_proto_files(
          src_folder,
          src_proto_file,
          dst_py_file):
      """
      Generates pb2.py files from corresponding .proto files
      """
  
      source_file = os.path.join(src_folder, src_proto_file)
      output_file = dst_py_file
  
      if (not os.path.exists(output_file) or
              os.path.exists(output_file) and
              os.path.getmtime(source_file) > os.path.getmtime(output_file)):
          print("Generating {}...".format(dst_py_file))
  
          if not os.path.exists(source_file):
              sys.stderr.write("Can't find required file: {}\n".format(
                  source_file))
              sys.exit(-1)
  
          if not protoc_exec:
              raise ValueError("No protobuf compiler executable was found!")
  
          try:
              tmp_dir = tempfile.mkdtemp(dir="./")
              protoc_command = [
                  protoc_exec,
                  "-I" + src_folder,
                  "--python_out=" + tmp_dir,
                  source_file]
              print("Executing {}...".format(protoc_command))
              if subprocess.call(protoc_command):
                  raise
              src_py_file = src_proto_file.replace(".proto", "_pb2.py")
              if os.path.exists(dst_py_file):
                  os.remove(dst_py_file)
              os.rename(os.path.join(tmp_dir, src_py_file), dst_py_file)
          finally:
              if os.path.exists(tmp_dir):
                  shutil.rmtree(tmp_dir)
function_tokens: def generate_proto_files ( src_folder , src_proto_file , dst_py_file ) : source_file = os . path . join ( src_folder , src_proto_file ) output_file = dst_py_file if ( not os . path . exists ( output_file ) or os . path . exists ( output_file ) and os . path . getmtime ( source_file ) > os . path . getmtime ( output_file ) ) : print ( "Generating {}..." . format ( dst_py_file ) ) if not os . path . exists ( source_file ) : sys . stderr . write ( "Can't find required file: {}\n" . format ( source_file ) ) sys . exit ( - 1 ) if not protoc_exec : raise ValueError ( "No protobuf compiler executable was found!" ) try : tmp_dir = tempfile . mkdtemp ( dir = "./" ) protoc_command = [ protoc_exec , "-I" + src_folder , "--python_out=" + tmp_dir , source_file ] print ( "Executing {}..." . format ( protoc_command ) ) if subprocess . call ( protoc_command ) : raise src_py_file = src_proto_file . replace ( ".proto" , "_pb2.py" ) if os . path . exists ( dst_py_file ) : os . remove ( dst_py_file ) os . rename ( os . path . join ( tmp_dir , src_py_file ) , dst_py_file ) finally : if os . path . exists ( tmp_dir ) : shutil . rmtree ( tmp_dir )