_internals.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from vtkmodules.vtkCommonMisc import vtkResourceFileLocator
  2. import os.path, sys, platform
  3. def find_webapp(appname):
  4. """Returns the path to the is web app with given name is found in the package."""
  5. if platform.system() == "Darwin":
  6. root = "Resources/"
  7. else:
  8. from paraview.servermanager import vtkSMProxyManager
  9. pv_version= "%d.%d" % (vtkSMProxyManager.GetVersionMajor(), vtkSMProxyManager.GetVersionMinor())
  10. root = "share/paraview-%s/" % pv_version
  11. filename = root + "web/%s/server/pvw-%s.py" % (appname, appname)
  12. locator = vtkResourceFileLocator()
  13. result = locator.Locate(os.path.dirname(os.path.abspath(__file__)), filename)
  14. if result:
  15. return os.path.join(result, filename)
  16. return None
  17. def find_webappcontents(appname):
  18. path = find_webapp(appname)
  19. if not path:
  20. return None
  21. root = os.path.dirname(os.path.dirname(path))
  22. return os.path.join(root, "www")
  23. def load_webapp(appname):
  24. path = find_webapp(appname)
  25. if not path:
  26. return None
  27. # the web-apps are not proper packages right now, which makes it a little
  28. # ugly to import them.
  29. sys.path.insert(0, os.path.dirname(path))
  30. packagename = os.path.splitext(os.path.basename(path))[0]
  31. return __import__(packagename)
  32. def get_commandline_args(appname):
  33. clargs = sys.argv[1:]
  34. if not "-c" in clargs and not "--content" in clargs:
  35. clargs.append("-c")
  36. clargs.append(find_webappcontents(appname))
  37. return clargs
  38. def start_server(appname, description, module, protocol):
  39. import argparse
  40. # Create argument parser
  41. parser = argparse.ArgumentParser(description=description)
  42. # Add arguments
  43. module.server.add_arguments(parser)
  44. protocol.add_arguments(parser)
  45. args = parser.parse_args(get_commandline_args(appname))
  46. protocol.configure(args)
  47. # Start server
  48. module.server.start_webserver(options=args, protocol=protocol)