github.com/tencent/goom@v1.0.1/tool/link (about)

     1  #!/usr/bin/env python3
     2  import os
     3  import sys
     4  import argparse
     5  import subprocess
     6  
     7  # renamed 'link' file
     8  original_link_file = 'original_link'
     9  
    10  # link first
    11  output=None
    12  code=0
    13  try:
    14      output = subprocess.check_output([os.path.dirname(__file__) + '/' + original_link_file] + sys.argv[1:], cwd=os.getcwd())
    15  except subprocess.CalledProcessError as e:
    16      output = e.output
    17      code = e.returncode
    18  
    19  if output:
    20      output_str = str(output, encoding='utf-8')
    21      print(output_str.replace(original_link_file, 'link'))
    22  
    23  # change max_prot value to 0x7
    24  parser = argparse.ArgumentParser()
    25  parser.add_argument('-o')
    26  args, _ = parser.parse_known_args()
    27  
    28  if args.o:
    29      binary_target = args.o
    30      # only for testing
    31      if binary_target.endswith('.test') or binary_target.endswith('_test_go'):
    32          with open(os.devnull, 'wb') as DEVNULL:
    33              try:
    34                  subprocess.check_call(["printf '\x07' | dd of=%s bs=1 seek=160 count=1 conv=notrunc" % binary_target], shell=True, stdout=DEVNULL, stderr=DEVNULL)
    35              except subprocess.CalledProcessError as e:
    36                  pass
    37  
    38  sys.exit(code)
    39