| Environment Name | ",filename)
+
reportType = 1
- elif "management" in filename:
- comp_ts_env = filename.replace("management/","").replace(".html","")
- reportName = comp_ts_env
- reportType = 3
-
else:
reportType = 2
return reportName, reportType
usingGitLabCI = False
+baseOutputDir = ""
-def create_index_html(mpName, isGitLab = False):
+def create_index_html(mpName, isGitLab = False, output_dir = ""):
import pathlib
from vector.apps.DataAPI.vcproject_api import VCProjectApi
from vector.apps.ReportBuilder.custom_report import CustomReport
@@ -67,32 +101,33 @@ def create_index_html(mpName, isGitLab = False):
global usingGitLabCI
usingGitLabCI = isGitLab
- api = VCProjectApi(mpName)
- # Set custom report directory to the where this script was
- # found. Must contain sections/index_section.py
- rep_path = pathlib.Path(__file__).parent.resolve()
-
- if usingGitLabCI:
- output_file="html_reports/index.html"
- else:
- output_file="index.html"
-
- CustomReport.report_from_api(
- api=api,
- title="HTML Reports",
- report_type="INDEX_FILE",
- formats=["HTML"],
- output_file=output_file,
- sections=['CUSTOM_HEADER', 'REPORT_TITLE', 'TABLE_OF_CONTENTS','INDEX_SECTION', 'CUSTOM_FOOTER'],
- customization_dir=rep_path)
+ global baseOutputDir
+ baseOutputDir = output_dir
+
+ with VCProjectApi(mpName) as vcproj:
+ # Set custom report directory to the where this script was
+ # found. Must contain sections/index_section.py
+ rep_path = pathlib.Path(__file__).parent.resolve()
- api.close()
+ if usingGitLabCI:
+ output_file=os.path.join(baseOutputDir,"index.html")
+ else:
+ output_file=os.path.join(baseOutputDir,"index.html")
+
+ CustomReport.report_from_api(
+ api=vcproj,
+ title="HTML Reports",
+ report_type="INDEX_FILE",
+ formats=["HTML"],
+ output_file=output_file,
+ sections=['CUSTOM_HEADER', 'REPORT_TITLE', 'TABLE_OF_CONTENTS','INDEX_SECTION', 'CUSTOM_FOOTER'],
+ customization_dir=rep_path)
def create_index_html_body ():
- tempHtmlReportList = glob.glob("*.html")
- tempHtmlReportList += glob.glob("html_reports/*.html")
- tempHtmlReportList += glob.glob("management/*.html")
+ tempHtmlReportList = glob.glob(os.path.join(baseOutputDir,"*.html"))
+ tempHtmlReportList += glob.glob(os.path.join(baseOutputDir,"html_reports/*.html"))
+ tempHtmlReportList += glob.glob(os.path.join(baseOutputDir,"management/*.html"))
htmlReportList = []
try:
diff --git a/src/main/resources/scripts/fixup_reports.py b/src/main/resources/scripts/fixup_reports.py
index d0314802..c0052946 100644
--- a/src/main/resources/scripts/fixup_reports.py
+++ b/src/main/resources/scripts/fixup_reports.py
@@ -25,7 +25,7 @@
from __future__ import division
from __future__ import print_function
-import sys, os
+import sys, os, locale
# adding path
workspace = os.getenv("WORKSPACE")
if workspace is None:
@@ -41,9 +41,13 @@
sys.path.append(python_path_updates)
from bs4 import BeautifulSoup
-from safe_open import open
+try:
+ from safe_open import open
+except:
+ pass
import tee_print
+from vcast_utils import getVectorCASTEncoding
def fixup_2020_soup(main_soup):
@@ -76,6 +80,7 @@ def fixup_2020_soup(main_soup):
'col_subprogram': 'word-break:break-all;width:30%;',
'col_complexity': 'white-space:nowrap;',
'col_metric': 'white-space:nowrap;',
+ 'mcdc-all-pairs': 'white-space:nowrap;',
'i0' : 'padding-left:0.25em;min-width:11em',
'i1' : 'padding-left: 1.25em;min-width: 11em;',
'i2' : 'padding-left: 2.25em;',
@@ -107,18 +112,32 @@ def fixup_2020_soup(main_soup):
return main_soup
def fixup_2020_reports(report_name):
- with open(report_name,"r") as fd:
+
+ encFmt = getVectorCASTEncoding()
+
+ with open(report_name, "rb") as fd:
+ raw = fd.read().decode(encFmt, "replace")
+
+ try:
+ # First attempt: use whatever encoding was detected
+ main_soup = BeautifulSoup(raw, features="lxml")
+
+ except Exception as e:
try:
- main_soup = BeautifulSoup(fd,features="lxml")
- except:
- main_soup = BeautifulSoup(fd)
-
+ # Try UTF-8 first as a fallback (should rarely fail if raw is text)
+ main_soup = BeautifulSoup(raw.encode("utf-8", "replace"), "lxml")
+ except Exception:
+ # Last resort: try system default encoding (ACP on Windows, etc.)
+ main_soup = BeautifulSoup(raw.encode(encFmt, "replace"), "lxml")
+
main_soup = fixup_2020_soup(main_soup)
- with open(report_name,"w") as fd:
- fd.write(main_soup.prettify(formatter="html"))
-
+ with open(report_name, "wb") as fd:
+ fd.write(main_soup.prettify(formatter="html").encode(encFmt, "replace"))
+
+
if __name__ == '__main__':
+
report_name = sys.argv[1]
fixup_2020_reports(report_name)
diff --git a/src/main/resources/scripts/full_report_no_toc.py b/src/main/resources/scripts/full_report_no_toc.py
index ff36124f..efd84a28 100644
--- a/src/main/resources/scripts/full_report_no_toc.py
+++ b/src/main/resources/scripts/full_report_no_toc.py
@@ -36,23 +36,6 @@ def generate_full_status(manageProject):
mpName = os.path.splitext(os.path.basename(manageProject))[0]
full_report_name = mpName + "_full_report.html"
metrics_report_name = mpName + "_metrics_report.html"
-
- # try:
- # from vector.apps.DataAPI.vcproject_api import VCProjectApi
- # api = VCProjectApi(manageProject)
-
- # api.report(report_type="MANAGE_STATUS_FULL_REPORT", formats=["HTML"], output_file=full_report_name , environments=api.Environment.all(), levels = [])
- # api.report(report_type="MANAGE_METRICS_REPORT" , formats=["HTML"], output_file=metrics_report_name, environments=api.Environment.all(), levels = [])
-
- # shutil.copy(full_report_name,full_report_name + "_tmp")
- # fixup_reports.fixup_2020_reports(full_report_name + "_tmp")
-
- # shutil.copy(metrics_report_name,metrics_report_name + "_tmp")
- # fixup_reports.fixup_2020_reports(metrics_report_name + "_tmp")
-
- # api.close()
-
- # except:
from managewait import ManageWait
diff --git a/src/main/resources/scripts/generate-results.py b/src/main/resources/scripts/generate-results.py
index dc6871f9..ece2411b 100644
--- a/src/main/resources/scripts/generate-results.py
+++ b/src/main/resources/scripts/generate-results.py
@@ -38,6 +38,7 @@
import tee_print
from safe_open import open
+from vcast_utils import getVectorCASTEncoding
# adding path
workspace = os.getenv("WORKSPACE")
@@ -81,7 +82,9 @@
from vector.apps.DataAPI.vcproject_api import VCProjectApi
except:
pass
-
+
+encFmt = getVectorCASTEncoding()
+
#global variables
global verbose
global print_exc
@@ -178,11 +181,14 @@ def readManageVersion(ManageFile):
version = 14
if os.path.isfile(ManageFile + ".vcm"):
ManageFile = ManageFile + '.vcm'
- with open(ManageFile, 'r') as projFile:
- for line in projFile:
+
+ with open(ManageFile, 'rb') as projFile:
+ for raw_line in projFile: # iterates lazily, line by line
+ line = raw_line.decode(encFmt, "replace") # decode each line
if 'version' in line and 'project' in line:
version = int(re.findall(r'\d+', line)[0])
break
+
if verbose:
print("Version of VectorCAST project file = %d" % version)
print("(Levels change in version 17 (*maybe) and above)")
@@ -308,8 +314,8 @@ def fixup_css(report_name):
if not need_fixup:
return
- with open(report_name,"r") as fd:
- data = fd.read()
+ with open(report_name,"rb") as fd:
+ data = fd.read().decode(encFmt,"replace")
#fix up inline CSS because of Content Security Policy violation
newData = data[: data.index(" |
|---|