|
| 1 | +# Python Tools for Visual Studio |
| 2 | +# Copyright(c) Microsoft Corporation |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the License); you may not use |
| 6 | +# this file except in compliance with the License. You may obtain a copy of the |
| 7 | +# License at http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS |
| 10 | +# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY |
| 11 | +# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, |
| 12 | +# MERCHANTABLITY OR NON-INFRINGEMENT. |
| 13 | +# |
| 14 | +# See the Apache Version 2.0 License for specific language governing |
| 15 | +# permissions and limitations under the License. |
| 16 | + |
| 17 | +__author__ = "Microsoft Corporation <[email protected]>" |
| 18 | +__version__ = "3.0.0.0" |
| 19 | + |
| 20 | +import os |
| 21 | +import sys |
| 22 | +from optparse import OptionParser |
| 23 | +from ptvsd.visualstudio_py_util import exec_file |
| 24 | +from ptvsd.visualstudio_py_debugger import DONT_DEBUG |
| 25 | +from ptvsd.attach_server import PTVS_VER, DEFAULT_PORT, enable_attach, wait_for_attach |
| 26 | + |
| 27 | +parser = OptionParser(prog = 'ptvsd', usage = 'Usage: %prog [<option>]... <file> [- <args>]', version = '%prog ' + PTVS_VER) |
| 28 | +parser.add_option('-s', '--secret', metavar = '<secret>', help = 'restrict server to only allow clients that specify <secret> when connecting') |
| 29 | +parser.add_option('-i', '--interface', default = '0.0.0.0', metavar = '<ip-address>', help = 'listen for debugger connections on interface <ip-address>') |
| 30 | +parser.add_option('-p', '--port', type='int', default = DEFAULT_PORT, metavar = '<port>', help = 'listen for debugger connections on <port>') |
| 31 | +parser.add_option('--certfile', metavar = '<file>', help = 'Enable SSL and use PEM certificate from <file> to secure connection') |
| 32 | +parser.add_option('--keyfile', metavar = '<file>', help = 'Use private key from <file> to secure connection (requires --certfile)') |
| 33 | +parser.add_option('--no-output-redirection', dest = 'redirect_output', action = 'store_false', default = True, help = 'do not redirect stdout and stderr to debugger') |
| 34 | +parser.add_option('--wait', dest = 'wait', action = 'store_true', default = False, help = 'wait for a debugger to attach before executing') |
| 35 | + |
| 36 | +argv = sys.argv[1:] |
| 37 | +script_argv = [] |
| 38 | +if '-' in argv: |
| 39 | + script_argv = argv[argv.index('-') + 1:] |
| 40 | + del argv[argv.index('-'):] |
| 41 | + |
| 42 | +(opts, args) = parser.parse_args(argv) |
| 43 | +if not args and not script_argv: |
| 44 | + parser.error('<file> not specified') |
| 45 | +if args: |
| 46 | + script_argv.insert(0, args[0]) |
| 47 | +if opts.keyfile and not opts.certfile: |
| 48 | + parser.error('--keyfile requires --certfile') |
| 49 | + |
| 50 | +enable_attach(opts.secret, (opts.interface, opts.port), opts.certfile, opts.keyfile, opts.redirect_output) |
| 51 | +if opts.wait: |
| 52 | + wait_for_attach() |
| 53 | + |
| 54 | +DONT_DEBUG.append(os.path.normcase(__file__)) |
| 55 | + |
| 56 | +sys.argv = script_argv |
| 57 | +exec_file(script_argv[0], {'__name__': '__main__'}) |
0 commit comments