eclair/relativize_urls.py: Script to relativize URLs in ECLAIR reports

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Change-Id: I51316496463666a24f24972b4d66fa2f22d6ec32
diff --git a/eclair/relativize_urls.py b/eclair/relativize_urls.py
new file mode 100755
index 0000000..3e300b8
--- /dev/null
+++ b/eclair/relativize_urls.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2022 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+
+# Script to replace absolute paths in ECLAIR HTML reports, pointing to
+# "dependency" files like CSS & JS, to relative paths, pointing to
+# those files copied alongside the report.
+
+import sys
+import re
+import os
+import glob
+
+
+os.chdir(sys.argv[1])
+for fn in glob.iglob("**/*.html", recursive=True):
+    depth = fn.count("/")
+    relp = "/".join([".."] * depth)
+    if relp:
+        relp += "/"
+    #print(fn, relp)
+    with open(fn) as f:
+        txt = f.read()
+    txt = txt.replace("/opt/bugseng/eclair-3.12.0/", relp)
+    #os.rename(fn, fn + ".bak")
+    with open(fn, "w") as f:
+        f.write(txt)