Example #1
0
def start(pod, host=None, port=None, open_browser=False, debug=False,
          preprocess=True):
  observer, podspec_observer = file_watchers.create_dev_server_observers(pod)
  if preprocess:
    # Run preprocessors for the first time in a thread.
    thread = threading.Thread(target=pod.preprocess)
    thread.start()

  try:
    # Create the development server.
    app = main_lib.CreateWSGIApplication(pod)
    port = 8080 if port is None else int(port)
    host = 'localhost' if host is None else host
    num_tries = 0
    while num_tries < 10:
      try:
        httpd = simple_server.make_server(host, port, app,
                                          handler_class=DevServerWSGIRequestHandler)
        num_tries = 99
      except socket.error as e:
        if e.errno == 48:
          num_tries += 1
          port += 1
        else:
          raise e

  except Exception as e:
    logging.error('Failed to start server: {}'.format(e))
    observer.stop()
    observer.join()
    sys.exit()

  try:
    root_path = pod.get_root_path()
    url = 'http://{}:{}{}'.format(host, port, root_path)
    print 'Pod: '.rjust(20) + pod.root
    print 'Address: '.rjust(20) + url
    print colorize('Server ready. '.rjust(20), ansi=47) + 'Press ctrl-c to quit.'
    def start_browser(server_ready_event):
      server_ready_event.wait()
      if open_browser:
        webbrowser.open(url)
    server_ready_event = threading.Event()
    browser_thread = threading.Thread(target=start_browser,
                                      args=(server_ready_event,))
    browser_thread.start()
    server_ready_event.set()
    httpd.serve_forever()
    browser_thread.join()

  except KeyboardInterrupt:
    logging.info('Goodbye. Shutting down.')
    httpd.server_close()
    observer.stop()
    observer.join()

  # Clean up once server exits.
  sys.exit()
Example #2
0
def start(pod, host=None, port=None, open_browser=False, debug=False):
  observer, podspec_observer = file_watchers.create_dev_server_observers(pod)
  # Run preprocessors for the first time in a thread.
  thread = threading.Thread(target=pod.preprocess)
  thread.start()

  try:
    # Create the development server.
    app = main_lib.CreateWSGIApplication(pod)
    port = 8080 if port is None else int(port)
    host = 'localhost' if host is None else host
    num_tries = 0
    while num_tries < 10:
      try:
        httpd = simple_server.make_server(host, port, app,
                                          handler_class=DevServerWSGIRequestHandler)
        num_tries = 99
      except socket.error as e:
        if e.errno == 48:
          num_tries += 1
          port += 1
        else:
          raise e

  except Exception as e:
    logging.error('Failed to start server: {}'.format(e))
    observer.stop()
    observer.join()
    sys.exit()

  try:
    root_path = pod.get_root_path()
    url = 'http://{}:{}{}'.format(host, port, root_path)
    print 'Grow SDK (growsdk.org) is in alpha. Thanks for testing and contributing.'
    print 'Pod: '.rjust(20) + pod.root
    print 'Address: '.rjust(20) + url
    print colorize('Server ready.'.rjust(19), ansi=47) + ' Press ctrl-c to quit.'
    def start_browser(server_ready_event):
      server_ready_event.wait()
      if open_browser:
        webbrowser.open(url)
    server_ready_event = threading.Event()
    browser_thread = threading.Thread(target=start_browser,
                                      args=(server_ready_event,))
    browser_thread.start()
    server_ready_event.set()
    httpd.serve_forever()
    browser_thread.join()

  except KeyboardInterrupt:
    logging.info('Goodbye. Shutting down.')
    httpd.server_close()
    observer.stop()
    observer.join()

  # Clean up once server exits.
  sys.exit()
Example #3
0
def start(pod, host=None, port=None, open_browser=False, debug=False,
          preprocess=True):
  observer, podspec_observer = file_watchers.create_dev_server_observers(pod)
  if preprocess:
    # Run preprocessors for the first time in a thread.
    thread = threading.Thread(target=pod.preprocess)
    thread.start()
  port = 8080 if port is None else int(port)
  host = 'localhost' if host is None else host
  port = find_port_and_start_server(pod, host, port, debug)
  pod.load()
  url = print_server_ready_message(pod, host, port)
  if open_browser:
    start_browser(url)
  shutdown_func = lambda *args: shutdown(pod)
  reactor.addSystemEventTrigger('during', 'shutdown', shutdown_func)
  reactor.run()