def main(args):
  """Runs the client, exits when done.

  See _CreateParser for the complete list of supported commands.

  Requires a $LAB_DEVICE_PROXY_URL environment variable (or --url argument)
  that's set to the server's URL.

  Args:
    args: List of command and arguments, e.g.
        ['./adb', 'install', 'foo.apk']
      In the expected environment, symlinks or copies of this Python file are
      created for every command:
        adb, idevice_id, ideviceinfo, ...
      so arg[0] is the command name.

      If arg[0] contains "lab_device_proxy_client", it is skipped, along with
      optional "--url URL" arguments.  This helps support unit tests and
      callers who don't want to create symlinks and/or set the
      "$LAB_DEVICE_PROXY_URL" environment variable.  E.g.:
        ['lab_device_proxy_client.py', '--url', 'http://x:8084', 'ideviceinfo']
      is equivalent to:
        os.environ['LAB_DEVICE_PROXY_URL'] = 'http://x:80804'
        ['ideviceinfo'].
  """
  signal.signal(signal.SIGINT, signal.SIG_DFL)  # Exit on Ctrl-C

  args = list(args)

  url = os.environ.get('LAB_DEVICE_PROXY_URL')

  if 'lab_device_proxy_client' in args[0]:
    args.pop(0)  # happens when there are no symlinks.
    if len(args) > 1 and args[0] == '--url':
      args.pop(0)
      url = args.pop(0)

  if args:
    args[0] = os.path.basename(args[0])

  if not url:
    sys.exit(
        'The lab device proxy server URL is not set.\n\n'
        'Either set the environment variable, e.g.:\n'
        '  export LAB_DEVICE_PROXY_URL=http://mylab:8084\n'
        'or invoke the proxy with a "--url" argument, e.g.:\n'
        '  lab_device_proxy_client.py --url http://mylab:8084 %s ...' %
        (args[0] if args else ''))

  try:
    params = PARSER.parse_args(args)
  except __HOLE__:
    sys.exit(1)

  # Make stdout and stderr unbuffered, so we could get the output
  # immediately when we redirect the output to another stream.
  sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
  sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0)

  # TODO(user) support os.environ.get('ANDROID_SERIAL')?
  exit_code = 1
  try:
    client = LabDeviceProxyClient(url, sys.stdout, sys.stderr)
    exit_code = client.Call(*params)
  except:  # pylint: disable=bare-except
    sys.stderr.write(GetStack())
  sys.exit(exit_code)
dataset/ETHPy150Open google/lab_device_proxy/lab_device_proxy_client.py/main