github.com/osrg/gobgp/v3@v3.30.0/test/scenario_test/ci-scripts/build_embeded_go.py (about)

     1  import sys
     2  import os
     3  from subprocess import call
     4  
     5  
     6  def cut(filename, out):
     7      with open(filename, 'r') as f:
     8          flag = False
     9          codes = []
    10          for line in f.readlines():
    11              if line.strip() == '```go':
    12                  flag = True
    13              elif line.strip() == '```':
    14                  with open(out, 'w') as g:
    15                      g.write("".join(codes))
    16                  return
    17              elif flag:
    18                  codes.append(line)
    19  
    20  
    21  if __name__ == '__main__':
    22      filename = sys.argv[1]
    23      out = 'hoge.go'
    24      cut(filename, out)
    25      ret = call(['go', 'build', '-o', 'hoge', out])
    26      os.remove(out)
    27      os.remove('hoge')
    28      sys.exit(ret)