pywebio-path-deploy 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python3
  2. import argparse
  3. from pywebio.platform import path_deploy, path_deploy_http
  4. parser = argparse.ArgumentParser(description="Deploy the PyWebIO applications from a directory", add_help=False)
  5. parser.add_argument("path", help="Base directory to load PyWebIO application")
  6. parser.add_argument("-p", "--port", help="The port the server listens on", type=int, default=8080)
  7. parser.add_argument("-h", "--host", help="The host the server listens on", default='0.0.0.0')
  8. parser.add_argument("--no-index", help="Disable default index page", action="store_true")
  9. parser.add_argument("--static-dir", help="Directory to store the application static files")
  10. parser.add_argument("--no-cdn", help="Disable front-end static resources CDN", action="store_true")
  11. parser.add_argument("-d", "--debug", help="Tornado Server's debug mode", action="store_true")
  12. parser.add_argument("--http",
  13. help="Use HTTP protocol to communication between server and browser, default use WebSocket",
  14. action="store_true")
  15. parser.add_argument("--help", help="Print help message", action='help')
  16. group = parser.add_argument_group('http arguments', 'Extra arguments when set --http')
  17. group.add_argument("--session-expire-seconds", help="Session expiration time, in seconds(default 600s)", type=int,
  18. default=None)
  19. group.add_argument("--session-cleanup-interval", help="Session cleanup interval, in seconds(default 300s)", type=int,
  20. default=None)
  21. group = parser.add_argument_group('websocket arguments', 'Extra arguments when not set --http')
  22. group.add_argument("--websocket-max-message-size", help="Max bytes of a message which Tornado can accept")
  23. group.add_argument("--websocket-ping-interval", type=int, default=None)
  24. group.add_argument("--websocket-ping-timeout", type=int, default=None)
  25. if __name__ == '__main__':
  26. args = parser.parse_args()
  27. kwargs = dict(vars(args))
  28. kwargs.pop('http')
  29. kwargs['base'] = kwargs.pop('path')
  30. kwargs['index'] = not kwargs.pop('no_index')
  31. kwargs['cdn'] = not kwargs.pop('no_cdn')
  32. if args.http:
  33. drop_key = ['websocket_max_message_size', 'websocket_ping_interval', 'websocket_ping_timeout']
  34. else:
  35. drop_key = ['session_expire_seconds', 'session_cleanup_interval']
  36. for i in drop_key:
  37. kwargs.pop(i, None)
  38. for k in list(kwargs):
  39. if kwargs[k] is None:
  40. del kwargs[k]
  41. if args.http:
  42. path_deploy_http(**kwargs)
  43. else:
  44. path_deploy(**kwargs)