SHARE
TWEET

Untitled

a guest Oct 15th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import ptvsd
  2. import argparse
  3. import os
  4. import sys
  5. import json
  6.  
  7. if __name__ == "__main__":
  8.     # Parse arguments.
  9.     parser = argparse.ArgumentParser()
  10.     parser.add_argument('script')
  11.     parser.add_argument('--host', default='0.0.0.0')
  12.     parser.add_argument('--port', default=8899, type=int)
  13.     parser.add_argument('--json_list_args', default='[]')
  14.     parser.add_argument('--current_working_directory', default=None, type=str)
  15.     args = parser.parse_args()
  16.  
  17.     # Wait for debug client.
  18.     print('Waiting for debug client...')
  19.     ptvsd.enable_attach(address=(args.host, args.port), redirect_output=True)
  20.     ptvsd.wait_for_attach()
  21.  
  22.     # Prepare environment and run the script.
  23.     print('Client connected. Debugging...')
  24.  
  25.     # Empty the command line arguments.
  26.     sys.argv = [args.script]
  27.  
  28.     # Set the current working directory.
  29.     if args.current_working_directory == None:
  30.         os.chdir(os.path.realpath(os.path.dirname(args.script)))
  31.     else:
  32.         os.chdir(os.path.realpath(args.current_working_directory))
  33.    
  34.     # Append the script path to "sys.path".
  35.     sys.path.insert(0, os.path.realpath(os.path.dirname(args.script)))
  36.  
  37.     # Append the custom script arguments.
  38.     args_list = json.loads(args.json_list_args)
  39.     for arg in args_list:
  40.         sys.argv.append(arg)
  41.    
  42.     # Execute the script.
  43.     execfile(args.script)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top