diff --git a/src/ansys/dynamicreporting/core/adr_report.py b/src/ansys/dynamicreporting/core/adr_report.py
index f064486e..f2c0e032 100644
--- a/src/ansys/dynamicreporting/core/adr_report.py
+++ b/src/ansys/dynamicreporting/core/adr_report.py
@@ -310,6 +310,7 @@ def export_html(
query=query,
filename=filename,
no_inline_files=no_inline_files,
+ ansys_version=self.service._ansys_version,
)
success = True
except Exception as e: # pragma: no cover
diff --git a/src/ansys/dynamicreporting/core/adr_service.py b/src/ansys/dynamicreporting/core/adr_service.py
index 4688e1c1..67875aef 100755
--- a/src/ansys/dynamicreporting/core/adr_service.py
+++ b/src/ansys/dynamicreporting/core/adr_service.py
@@ -310,7 +310,9 @@ def connect(
if self._url is not None: # pragma: no cover
self.logger.warning("Already connected to a dynamic reporting service.\n")
return
- self.serverobj = report_remote_server.Server(url=url, username=username, password=password)
+ self.serverobj = report_remote_server.Server(
+ url=url, username=username, password=password, ansys_version=self._ansys_version
+ )
try:
self.serverobj.validate()
except Exception:
@@ -471,7 +473,10 @@ def start(
self.logger.error(f"Service started on port {self._port}")
raise StartingServiceError
self.serverobj = report_remote_server.Server(
- url=f"http://127.0.0.1:{self._port}", username=username, password=password
+ url=f"http://127.0.0.1:{self._port}",
+ username=username,
+ password=password,
+ ansys_version=self._ansys_version,
)
else: # pragma: no cover
diff --git a/src/ansys/dynamicreporting/core/utils/report_download_html.py b/src/ansys/dynamicreporting/core/utils/report_download_html.py
index f0ca8a27..9b6bdca3 100644
--- a/src/ansys/dynamicreporting/core/utils/report_download_html.py
+++ b/src/ansys/dynamicreporting/core/utils/report_download_html.py
@@ -1,6 +1,9 @@
import base64
import os
import os.path
+import pathlib
+import platform
+import re
from typing import Optional
import urllib.parse
@@ -8,11 +11,18 @@
# TODO:
# Improve MathJax download
+ANSYS_VERSION_FALLBACK = "242"
class ReportDownloadHTML:
def __init__(
- self, url=None, directory=None, debug=False, filename="index.html", no_inline_files=False
+ self,
+ url=None,
+ directory=None,
+ debug=False,
+ filename="index.html",
+ no_inline_files=False,
+ ansys_version=None,
):
# Make sure that the print query has been specified. Set it to html if not set
if url:
@@ -25,7 +35,11 @@ def __init__(
query = "print=html"
parsed._replace(query=query)
url = urllib.parse.urlunparse(parsed)
-
+ self._ansys_version = str(ANSYS_VERSION_FALLBACK)
+ if ansys_version:
+ self._ansys_version = str(ansys_version)
+ if int(self._ansys_version) < 242:
+ self._ansys_version = ""
self._url = url
self._directory = directory
self._filename = filename
@@ -73,7 +87,7 @@ def _replace_files(self, text: str, inline: bool = False, size_check: bool = Fal
current = 0
while True:
try:
- idx1 = text.index("/static/ansys/", current)
+ idx1 = text.index(f"/static/ansys{self._ansys_version}/", current)
except ValueError:
try:
idx1 = text.index("/static/", current)
@@ -82,7 +96,7 @@ def _replace_files(self, text: str, inline: bool = False, size_check: bool = Fal
idx1 = text.index("/media/", current)
except ValueError:
try:
- idx1 = text.index("/ansys/", current)
+ idx1 = text.index(f"/ansys{self._ansys_version}/", current)
except ValueError:
return text
quote = text[idx1 - 1]
@@ -187,15 +201,24 @@ def _download_special_files(self):
"play.png",
]
self._download_static_files(
- images, "/ansys/nexus/images/", "ansys/nexus/images/", "viewer images II"
+ images,
+ f"/ansys{self._ansys_version}/nexus/images/",
+ f"ansys{self._ansys_version}/nexus/images/",
+ "viewer images II",
)
images = ["js-inflate.js", "js-unzip.js", "jquery.min.js"]
self._download_static_files(
- images, "/ansys/nexus/utils/", "ansys/nexus/utils/", "viewer javascript support"
+ images,
+ f"/ansys{self._ansys_version}/nexus/utils/",
+ f"ansys{self._ansys_version}/nexus/utils/",
+ "viewer javascript support",
)
images = ["ANSYSViewer_min.js", "viewer-loader.js"]
self._download_static_files(
- images, "/ansys/nexus/", "ansys/nexus/", "ansys-nexus-viewer js"
+ images,
+ f"/ansys{self._ansys_version}/nexus/",
+ f"ansys{self._ansys_version}/nexus/",
+ "ansys-nexus-viewer js",
)
images = [
"jquery.contextMenu.min.css",
@@ -204,8 +227,8 @@ def _download_special_files(self):
]
self._download_static_files(
images,
- "/ansys/nexus/novnc/vendor/jQuery-contextMenu/",
- "ansys/nexus/novnc/vendor/jQuery-contextMenu",
+ f"/ansys{self._ansys_version}/nexus/novnc/vendor/jQuery-contextMenu/",
+ f"ansys{self._ansys_version}/nexus/novnc/vendor/jQuery-contextMenu",
"ansys-nexus-viewer vnc js",
)
@@ -217,7 +240,10 @@ def _download_special_files(self):
"three.js",
]
self._download_static_files(
- image, "/ansys/nexus/threejs/", "ansys/nexus/threejs", "threejs core"
+ image,
+ f"/ansys{self._ansys_version}/nexus/threejs/",
+ f"ansys{self._ansys_version}/nexus/threejs",
+ "threejs core",
)
image = [
@@ -228,14 +254,14 @@ def _download_special_files(self):
]
self._download_static_files(
image,
- "/ansys/nexus/threejs/libs/draco/",
- "ansys/nexus/threejs/libs/draco",
+ f"/ansys{self._ansys_version}/nexus/threejs/libs/draco/",
+ f"ansys{self._ansys_version}/nexus/threejs/libs/draco",
"threejs draco",
)
self._download_static_files(
image,
- "/ansys/nexus/threejs/libs/draco/gltf/",
- "ansys/nexus/threejs/libs/draco/gltf",
+ f"/ansys{self._ansys_version}/nexus/threejs/libs/draco/gltf/",
+ f"ansys{self._ansys_version}/nexus/threejs/libs/draco/gltf",
"threejs draco gltf",
)
@@ -250,7 +276,7 @@ def _download_special_files(self):
self._download_static_files(fonts, "/static/website/webfonts/", "webfonts", "fonts")
@staticmethod
- def _fix_viewer_component_paths(filename, data):
+ def _fix_viewer_component_paths(filename, data, ansys_version):
# Special case for AVZ viewer: ANSYSViewer_min.js to set the base path for images
if filename.endswith("ANSYSViewer_min.js"):
data = data.decode("utf-8")
@@ -258,7 +284,9 @@ def _fix_viewer_component_paths(filename, data):
'"/static/website/images/"',
r'document.URL.replace(/\\/g, "/").replace("index.html", "media/")',
)
- data = data.replace('"/ansys/nexus/images/', '"./ansys/nexus/images/')
+ data = data.replace(
+ f'"/ansys{ansys_version}/nexus/images/', f'"./ansys{ansys_version}//nexus/images/'
+ )
# this one is interesting. by default, AVZ will throw an error if you attempt to read
# a "file://" protocol src. In offline mode, if we are not using data URIs, then we
# need to lie to the AVZ core and tell it to go ahead and try.
@@ -267,7 +295,9 @@ def _fix_viewer_component_paths(filename, data):
# Special case for the AVZ viewer web component (loading proxy images and play arrow)
elif filename.endswith("viewer-loader.js"):
data = data.decode("utf-8")
- data = data.replace('"/ansys/nexus/images/', '"./ansys/nexus/images/')
+ data = data.replace(
+ f'"/ansys{ansys_version}/nexus/images/', f'"./ansys{ansys_version}//nexus/images/'
+ )
data = data.encode("utf-8")
return data
@@ -277,9 +307,12 @@ def _download_static_files(self, files, source_path, target_path, comment):
url = tmp.scheme + "://" + tmp.netloc + source_path + f
resp = requests.get(url, allow_redirects=True)
if resp.status_code == requests.codes.ok:
- filename = os.path.join(self._directory, target_path, f)
+ filename = self._directory + os.sep + target_path + os.sep + f
+ filename = os.path.normpath(filename)
try:
- data = self._fix_viewer_component_paths(filename, resp.content)
+ data = self._fix_viewer_component_paths(
+ str(filename), resp.content, self._ansys_version
+ )
open(filename, "wb").write(data)
except Exception:
print(f"Unable to download {comment}: {f}")
@@ -329,9 +362,9 @@ def _get_file(self, path_plus_queries: str, pathname: str, inline: bool = False)
# we need to prefix the .bin file and scene.js file with the GUID
basename = f"{os.path.basename(os.path.dirname(pathname))}_{basename}"
else:
- tmp = self._fix_viewer_component_paths(basename, tmp)
+ tmp = self._fix_viewer_component_paths(basename, tmp, self._ansys_version)
# get the output filename
- if pathname.startswith("/static/ansys/"):
+ if pathname.startswith(f"/static/ansys{self._ansys_version}/"):
# if the content is part of the /ansys/ namespace, we keep the namespace,
# but remove the /static prefix
local_pathname = os.path.dirname(pathname).replace("/static/", "./")
@@ -361,7 +394,11 @@ def _find_block(text: str, start: int, prefix: int, suffix: str) -> (int, int, s
return -1, -1, ""
idx2 += len(suffix)
block = text[idx1:idx2]
- if ("/media/" in block) or ("/static/" in block) or ("/ansys/" in block):
+ if (
+ ("/media/" in block)
+ or ("/static/" in block)
+ or (re.match(r"/ansys([0-9]+)", block))
+ ):
return idx1, idx2, text[idx1:idx2]
start = idx2
@@ -452,10 +489,29 @@ def _download(self):
self._make_dir([self._directory, "media", "jax", "input", "AsciiMath"])
self._make_dir([self._directory, "media", "images"])
self._make_dir([self._directory, "webfonts"])
- self._make_dir([self._directory, "ansys", "nexus", "images"])
- self._make_dir([self._directory, "ansys", "nexus", "utils"])
- self._make_dir([self._directory, "ansys", "nexus", "threejs", "libs", "draco", "gltf"])
- self._make_dir([self._directory, "ansys", "nexus", "novnc", "vendor", "jQuery-contextMenu"])
+ self._make_dir([self._directory, f"ansys{self._ansys_version}", "nexus", "images"])
+ self._make_dir([self._directory, f"ansys{self._ansys_version}", "nexus", "utils"])
+ self._make_dir(
+ [
+ self._directory,
+ f"ansys{self._ansys_version}",
+ "nexus",
+ "threejs",
+ "libs",
+ "draco",
+ "gltf",
+ ]
+ )
+ self._make_dir(
+ [
+ self._directory,
+ f"ansys{self._ansys_version}",
+ "nexus",
+ "novnc",
+ "vendor",
+ "jQuery-contextMenu",
+ ]
+ )
# get the webpage html source
resp = requests.get(self._url)
@@ -480,7 +536,7 @@ def _download(self):
#
# in viewer-loader.js - this is handled in a special way
- #
+ #
# video
#
# slider template
diff --git a/src/ansys/dynamicreporting/core/utils/report_remote_server.py b/src/ansys/dynamicreporting/core/utils/report_remote_server.py
index 68ea04f3..6b452fa0 100755
--- a/src/ansys/dynamicreporting/core/utils/report_remote_server.py
+++ b/src/ansys/dynamicreporting/core/utils/report_remote_server.py
@@ -103,7 +103,7 @@ class Server:
Implements REST protocols.
"""
- def __init__(self, url=None, username=None, password=None):
+ def __init__(self, url=None, username=None, password=None, ansys_version=None):
# Check on the validity of url formatting
if url is not None:
o = urlparse(url)
@@ -112,6 +112,7 @@ def __init__(self, url=None, username=None, password=None):
if print_allowed():
print("Error: invalid URL. Setting it to None")
url = None
+ self._ansys_version = ansys_version
self.cur_url = url
self.cur_username = username
self.cur_password = password
@@ -858,7 +859,13 @@ def build_url_with_query(self, report_guid, query, rest_api=False):
return url
def export_report_as_html(
- self, report_guid, directory_name, query=None, filename="index.html", no_inline_files=False
+ self,
+ report_guid,
+ directory_name,
+ query=None,
+ filename="index.html",
+ no_inline_files=False,
+ ansys_version=None,
):
if query is None:
query = {}
@@ -867,8 +874,15 @@ def export_report_as_html(
from ansys.dynamicreporting.core.utils.report_download_html import ReportDownloadHTML
url = self.build_url_with_query(report_guid, query)
+ _ansys_version = self._ansys_version
+ if ansys_version:
+ _ansys_version = ansys_version
worker = ReportDownloadHTML(
- url=url, directory=directory_path, filename=filename, no_inline_files=no_inline_files
+ url=url,
+ directory=directory_path,
+ filename=filename,
+ no_inline_files=no_inline_files,
+ ansys_version=_ansys_version,
)
worker.download()
@@ -1491,7 +1505,12 @@ def launch_local_database_server(
# Check to see if there is already a server running on this URI
# build a server and try it
- tmp_server = Server(url=f"http://127.0.0.1:{port}", username=username, password=password)
+ tmp_server = Server(
+ url=f"http://127.0.0.1:{port}",
+ username=username,
+ password=password,
+ ansys_version=ansys_version,
+ )
try:
# validate will throw exceptions or return a float.
_ = tmp_server.validate()