From 28e30c07ed3cbf4c844220ef8b737fa889b55ac7 Mon Sep 17 00:00:00 2001 From: Utkarsh Ayachit Date: Thu, 16 Nov 2017 10:48:31 -0500 Subject: [PATCH] Remove defaultProxies.json `defaultProxies.json` being a non-python file in a Python module needed special handling all over the place in superbuilds. We can avoid all that by simply making it a Python module. --- Web/Python/CMakeLists.txt | 5 ----- .../web/_default_proxies.py} | 14 ++++++++++++ Web/Python/paraview/web/protocols.py | 22 ++++++++++--------- 3 files changed, 26 insertions(+), 15 deletions(-) rename Web/Python/{defaultProxies.json => paraview/web/_default_proxies.py} (77%) diff --git a/Web/Python/CMakeLists.txt b/Web/Python/CMakeLists.txt index ce0cf602fe9..48ee6dcacf5 100644 --- a/Web/Python/CMakeLists.txt +++ b/Web/Python/CMakeLists.txt @@ -5,8 +5,3 @@ include(vtkModuleMacrosPython) # package. vtk_module_python_package(${vtk-module} "paraview/web" RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}") - -# copy some default sources and proxies for ParaViewWeb -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/defaultProxies.json" - "${VTK_BUILD_PYTHON_MODULES_DIR}/paraview/web/defaultProxies.json" - COPYONLY) diff --git a/Web/Python/defaultProxies.json b/Web/Python/paraview/web/_default_proxies.py similarity index 77% rename from Web/Python/defaultProxies.json rename to Web/Python/paraview/web/_default_proxies.py index 3835e836a57..35ecc4d8aa1 100644 --- a/Web/Python/defaultProxies.json +++ b/Web/Python/paraview/web/_default_proxies.py @@ -1,3 +1,11 @@ +r"""internal module used to get the list of default proxies. + +This is an internal module and not intended to be used by Python code outside of +this package. + +""" + +__defaultProxiesJSON = """ { "sources": [ { "name": "AnnotateTime", "label": "Annotate Time" }, @@ -32,3 +40,9 @@ { "name": "Xdmf3ReaderS", "extensions": [ "xmf", "xdmf" ] } ] } +""" + +def getDefaultProxies(): + """Returns the JSON object for the default proxies configuration""" + import json + return json.loads(__defaultProxiesJSON) diff --git a/Web/Python/paraview/web/protocols.py b/Web/Python/paraview/web/protocols.py index 56baa78d4af..ddcaf7bf4a4 100644 --- a/Web/Python/paraview/web/protocols.py +++ b/Web/Python/paraview/web/protocols.py @@ -1305,10 +1305,8 @@ class ParaViewWebProxyManager(ParaViewWebProtocol): if allowedProxiesFile: self.readAllowedProxies(allowedProxiesFile) else: - module_path = os.path.abspath(__file__) - path = os.path.dirname(module_path) - proxyFile = os.path.join(path, 'defaultProxies.json') - self.readAllowedProxies(proxyFile) + from ._default_proxies import getDefaultProxies + self.readAllowedProxies(getDefaultProxies()) if fileToLoad: if '*' in fileToLoad: @@ -1333,14 +1331,18 @@ class ParaViewWebProxyManager(ParaViewWebProtocol): #-------------------------------------------------------------------------- # Read the configured proxies json file into a dictionary and process. #-------------------------------------------------------------------------- - def readAllowedProxies(self, filepath): + def readAllowedProxies(self, filepathOrConfig): self.availableList = {} self.allowedProxies = {} - with open(filepath, 'r') as fd: - configurationData = json.load(fd) - self.configureFiltersOrSources('sources', configurationData['sources']) - self.configureFiltersOrSources('filters', configurationData['filters']) - self.configureReaders(configurationData['readers']) + configurationData = {} + if type(filepathOrConfig) == dict: + configurationData = filepathOrConfig + else: + with open(filepath, 'r') as fd: + configurationData = json.load(fd) + self.configureFiltersOrSources('sources', configurationData['sources']) + self.configureFiltersOrSources('filters', configurationData['filters']) + self.configureReaders(configurationData['readers']) #-------------------------------------------------------------------------- # Handle filters and sources sections of the proxies config file. -- GitLab