test_server.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. r"""
  2. This module is a ParaViewWeb server application used only for automated testing
  3. """
  4. import os
  5. # import paraview modules.
  6. from paraview.web import pv_wslink
  7. from paraview.web import protocols as pv_protocols
  8. from wslink import server
  9. import argparse
  10. # =============================================================================
  11. # Create custom Pipeline Manager class to handle clients requests
  12. # =============================================================================
  13. class _TestServer(pv_wslink.PVServerProtocol):
  14. dataDir = os.getcwd()
  15. canFile = None
  16. authKey = "wslink-secret"
  17. dsHost = None
  18. dsPort = 11111
  19. rsHost = None
  20. rsPort = 11111
  21. rcPort = -1
  22. fileToLoad = None
  23. groupRegex = "[0-9]+\\.[0-9]+\\.|[0-9]+\\."
  24. excludeRegex = "^\\.|~$|^\\$"
  25. plugins = None
  26. filterFile = None
  27. colorPalette = None
  28. proxies = None
  29. allReaders = True
  30. saveDataDir = os.getcwd()
  31. viewportScale = 1.0
  32. viewportMaxWidth = 2560
  33. viewportMaxHeight = 1440
  34. def initialize(self):
  35. # Bring used components
  36. self.registerVtkWebProtocol(
  37. pv_protocols.ParaViewWebStartupRemoteConnection(
  38. _TestServer.dsHost,
  39. _TestServer.dsPort,
  40. _TestServer.rsHost,
  41. _TestServer.rsPort,
  42. _TestServer.rcPort,
  43. )
  44. )
  45. self.registerVtkWebProtocol(
  46. pv_protocols.ParaViewWebStartupPluginLoader(_TestServer.plugins)
  47. )
  48. self.registerVtkWebProtocol(
  49. pv_protocols.ParaViewWebFileListing(
  50. _TestServer.dataDir,
  51. "Home",
  52. _TestServer.excludeRegex,
  53. _TestServer.groupRegex,
  54. )
  55. )
  56. self.registerVtkWebProtocol(
  57. pv_protocols.ParaViewWebProxyManager(
  58. allowedProxiesFile=_TestServer.proxies,
  59. baseDir=_TestServer.dataDir,
  60. fileToLoad=_TestServer.fileToLoad,
  61. allowUnconfiguredReaders=_TestServer.allReaders,
  62. )
  63. )
  64. self.registerVtkWebProtocol(
  65. pv_protocols.ParaViewWebColorManager(
  66. pathToColorMaps=_TestServer.colorPalette
  67. )
  68. )
  69. self.registerVtkWebProtocol(pv_protocols.ParaViewWebMouseHandler())
  70. self.registerVtkWebProtocol(
  71. pv_protocols.ParaViewWebViewPort()
  72. ) # _TestServer.viewportScale, _TestServer.viewportMaxWidth, _TestServer.viewportMaxHeight
  73. self.registerVtkWebProtocol(pv_protocols.ParaViewWebViewPortImageDelivery())
  74. self.registerVtkWebProtocol(pv_protocols.ParaViewWebViewPortGeometryDelivery())
  75. self.registerVtkWebProtocol(pv_protocols.ParaViewWebTimeHandler())
  76. self.registerVtkWebProtocol(pv_protocols.ParaViewWebSelectionHandler())
  77. self.registerVtkWebProtocol(pv_protocols.ParaViewWebWidgetManager())
  78. self.registerVtkWebProtocol(pv_protocols.ParaViewWebKeyValuePairStore())
  79. self.registerVtkWebProtocol(
  80. pv_protocols.ParaViewWebSaveData(baseSavePath=_TestServer.saveDataDir)
  81. )
  82. # Update authentication key to use
  83. self.updateSecret(_TestServer.authKey)
  84. # =============================================================================
  85. # Main: Parse args and start server
  86. # =============================================================================
  87. if __name__ == "__main__":
  88. # Create argument parser
  89. parser = argparse.ArgumentParser(description="ParaView Web Test Server")
  90. # Add arguments
  91. server.add_arguments(parser)
  92. args = parser.parse_args()
  93. # Start server
  94. server.start_webserver(options=args, protocol=_TestServer)