Ejemplo n.º 1
0
        usage='usage: %prog [option]...')
    parser.add_option('-p',
                      '--port',
                      default='8000',
                      help='port to run the server on')

    (opts, argv) = parser.parse_args()

    try:
        print('Starting previewserver on port %s' % opts.port)
        print('The extension documentation can be found at:')
        print('')
        print('  http://localhost:%s/chrome/common/extensions/api' % opts.port)
        print('')

        highlighters = {
            'hilite': hilite_me_highlighter.HiliteMeHighlighter(),
            'none': none_highlighter.NoneHighlighter()
        }
        try:
            highlighters[
                'pygments'] = pygments_highlighter.PygmentsHighlighter()
        except ImportError as e:
            pass

        server = PreviewHTTPServer(('', int(opts.port)), CompilerHandler,
                                   highlighters)
        server.serve_forever()
    except KeyboardInterrupt:
        server.socket.close()
Ejemplo n.º 2
0
class PreviewHTTPServer(HTTPServer, object):
  def __init__(self, server_address, handler, highlighters):
    super(PreviewHTTPServer, self).__init__(server_address, handler)
    self.highlighters = highlighters


if __name__ == '__main__':
  parser = optparse.OptionParser(
      description='Runs a server to preview the json_schema_compiler output.',
      usage='usage: %prog [option]...')
  parser.add_option('-p', '--port', default=8000,
      help='port to run the server on')

  (opts, argv) = parser.parse_args()

  try:
    print('Starting previewserver on port %d' % opts.port)
    print('The extension documentation can be found at:')
    print('')
    print('  http://localhost:%d/chrome/common/extensions/api' % opts.port)
    print('')
    server = PreviewHTTPServer(('', int(opts.port)), CompilerHandler,
      {
        'pygments': pygments_highlighter.PygmentsHighlighter(),
        'hilite': hilite_me_highlighter.HiliteMeHighlighter(),
        'none': none_highlighter.NoneHighlighter(),
      })
    server.serve_forever()
  except KeyboardInterrupt:
    server.socket.close()