Skip to content

Commit 1d9a41c

Browse files
committed
Updates from Jenkins 0.79 scripts
1 parent 3c3bb04 commit 1d9a41c

14 files changed

+207
-180
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.idea
2+
**/__pycache__
3+
/*.log
4+
/*.pyc

cobertura.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
except:
3333
pass
3434

35-
from vector.apps.DataAPI.cover_api import CoverApi
35+
try:
36+
from vector.apps.DataAPI.cover_api import CoverApi
37+
except:
38+
pass
3639

3740
try:
3841
from vector.apps.DataAPI.unit_test_api import UnitTestApi
@@ -393,10 +396,10 @@ def procesCoverage(coverXML, coverApi, extended = False, source_root = ""):
393396

394397
def runCoverageResultsMP(packages, mpFile, verbose = False, extended=False, source_root = ""):
395398

396-
with VCProjectApi(mpFile) as vcproj:
397-
api = vcproj.project.cover_api
398-
399-
results = runCoberturaResults(packages, api, verbose = False, extended = extended, source_root = source_root)
399+
vcproj = VCProjectApi(mpFile)
400+
api = vcproj.project.cover_api
401+
results = runCoberturaResults(packages, api, verbose = False, extended = extended, source_root = source_root)
402+
vcproj.close()
400403

401404
return results
402405

copy_build_dir.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
import shutil
3131
import argparse
3232

33+
from vcast_utils import dump, checkVectorCASTVersion, getVectorCASTEncoding
34+
35+
if not checkVectorCASTVersion(19):
36+
print ("Copy build directory for pipelines not supported. Please upgrade VectorCAST")
37+
sys.exit(0)
38+
3339
try:
3440
## This tests to see if 2018 is present.
3541
from vector.apps.ReportBuilder.custom_report import CustomReport
@@ -43,7 +49,7 @@
4349
try:
4450
from vector.apps.DataAPI.vcproject_api import VCProjectApi
4551
except:
46-
pass
52+
raise ImportError("Full reports generated by previous call to generate-results.py")
4753

4854
def make_relative(path, workspace, vCastProjectWorkspace, ManageProjectName):
4955

@@ -237,14 +243,17 @@ def run(ManageProjectName, Level, BaseName, Env, workspace, vCastProjectWorkspac
237243

238244
def getVcastProjectWorkspace(args):
239245

240-
with VCProjectApi(args.ManageProject) as vcproj:
241-
vCastProjectWorkspace = vcproj.project.workspace
242-
246+
vcproj = VCProjectApi(args.ManageProject)
247+
vCastProjectWorkspace = vcproj.project.workspace
248+
vcproj.close()
243249
return vCastProjectWorkspace
244250

245251
if __name__ == '__main__':
246252

247-
253+
if not checkVectorCASTVersion(19):
254+
print ("Pipeline's copy build directory not supported under. Please upgrade VectorCAST")
255+
sys.exit(0)
256+
248257
parser = argparse.ArgumentParser()
249258
parser.add_argument('ManageProject', help='Manager Project Name')
250259
parser.add_argument('-l', '--level', help='Environment Name if only doing single environment. Should be in the form of level/env', default="NotProvided/NotProvided")

create_index_html.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ def getReportName(filename):
117117
baseOutputDir = ""
118118

119119
def create_index_html(mpName, isGitLab = False, output_dir = ""):
120-
import pathlib
121120
from vector.apps.DataAPI.vcproject_api import VCProjectApi
122121
from vector.apps.ReportBuilder.custom_report import CustomReport
123122

@@ -127,25 +126,24 @@ def create_index_html(mpName, isGitLab = False, output_dir = ""):
127126
global baseOutputDir
128127
baseOutputDir = output_dir
129128

130-
with VCProjectApi(mpName) as vcproj:
131-
# Set custom report directory to the where this script was
132-
# found. Must contain sections/index_section.py
133-
rep_path = pathlib.Path(__file__).parent.resolve()
134-
135-
if usingGitLabCI:
136-
output_file=os.path.join(baseOutputDir,"index.html")
137-
else:
138-
output_file=os.path.join(baseOutputDir,"index.html")
139-
140-
CustomReport.report_from_api(
141-
api=vcproj,
142-
title="HTML Reports",
143-
report_type="INDEX_FILE",
144-
formats=["HTML"],
145-
output_file=output_file,
146-
sections=['CUSTOM_HEADER', 'REPORT_TITLE', 'TABLE_OF_CONTENTS','INDEX_SECTION', 'CUSTOM_FOOTER'],
147-
customization_dir=rep_path)
129+
vcproj = VCProjectApi(mpName)
148130

131+
# Set custom report directory to the where this script was
132+
# found. Must contain sections/index_section.py
133+
rep_path = os.path.abspath(os.path.dirname(__file__))
134+
135+
output_file=os.path.join(baseOutputDir,"index.html")
136+
137+
CustomReport.report_from_api(
138+
api=vcproj,
139+
title="HTML Reports",
140+
report_type="INDEX_FILE",
141+
formats=["HTML"],
142+
output_file=output_file,
143+
sections=['CUSTOM_HEADER', 'REPORT_TITLE', 'TABLE_OF_CONTENTS','INDEX_SECTION', 'CUSTOM_FOOTER'],
144+
customization_dir=rep_path)
145+
vcproj.close()
146+
149147
def create_index_html_body ():
150148

151149
tempHtmlReportList = glob.glob(os.path.join(baseOutputDir,"*.html"))

generate_lcov.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ def get_function_name_line_number(file_path, function, initial_guess):
144144

145145
def runCoverageResultsMP(mpFile, verbose = False, testName = "", source_root = ""):
146146

147-
with VCProjectApi(mpFile) as vcproj:
148-
api = vcproj.project.cover_api
149-
results = runGcovResults(api, verbose = verbose, testName = vcproj.project.name, source_root=source_root)
147+
vcproj = VCProjectApi(mpFile)
148+
api = vcproj.project.cover_api
149+
results = runGcovResults(api, verbose = verbose, testName = vcproj.project.name, source_root=source_root)
150+
vcproj.close()
150151

151152
return results
152153

generate_pclp_reports.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ def generate_html_report(mpName, input_xml, output_html):
330330
print("{} was not found. Skipping PCLP HTML reporting".format(input_xml))
331331
return
332332

333-
import pathlib
334333
from vector.apps.DataAPI.vcproject_api import VCProjectApi
335334
from vector.apps.ReportBuilder.custom_report import CustomReport
336335

@@ -340,19 +339,21 @@ def generate_html_report(mpName, input_xml, output_html):
340339
if output_html is None:
341340
output_html = "pclp_findings.html"
342341

343-
with VCProjectApi(mpName) as vcproj:
344-
345-
# Set custom report directory to the where this script was
346-
# found. Must contain sections/index_section.py
347-
rep_path = pathlib.Path(__file__).parent.resolve()
348-
CustomReport.report_from_api(
349-
api=vcproj,
350-
title="PC-Lint Plus Results",
351-
report_type="INDEX_FILE",
352-
formats=["HTML"],
353-
output_file=output_html,
354-
sections=['CUSTOM_HEADER', 'REPORT_TITLE', 'TABLE_OF_CONTENTS','PCLP_SUMMARY_SECTION','PCLP_DETAILS_SECTION','PCLP_SOURCE_SECTION', 'CUSTOM_FOOTER'],
355-
customization_dir=rep_path)
342+
vcproj = VCProjectApi(mpName)
343+
344+
# Set custom report directory to the where this script was
345+
# found. Must contain sections/index_section.py
346+
rep_path = os.path.abspath(os.path.dirname(__file__))
347+
CustomReport.report_from_api(
348+
api=vcproj,
349+
title="PC-Lint Plus Results",
350+
report_type="INDEX_FILE",
351+
formats=["HTML"],
352+
output_file=output_html,
353+
sections=['CUSTOM_HEADER', 'REPORT_TITLE', 'TABLE_OF_CONTENTS','PCLP_SUMMARY_SECTION','PCLP_DETAILS_SECTION','PCLP_SOURCE_SECTION', 'CUSTOM_FOOTER'],
354+
customization_dir=rep_path)
355+
356+
vcproj.close()
356357

357358
def has_any_coverage(line):
358359

generate_qa_results_xml.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
#
2424

2525
from __future__ import print_function
26-
27-
# adding path
28-
2926
import datetime
3027
try:
3128
from html import escape
@@ -210,36 +207,31 @@ def processSystemTestResultsData(lines, encoding = 'utf-8'):
210207

211208
return passed, failed
212209

213-
def saveQATestStatus(mp):
214-
callStr = os.environ.get('VECTORCAST_DIR') + os.sep + "manage -p " + mp + " --system-tests-status=" + os.path.basename(mp)[:-4] + "_system_tests_status.html"
215-
p = subprocess.Popen(callStr, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
216-
out, err = p.communicate()
217-
218210
def genQATestResults(mp, level = None, envName = None, verbose = False, encoding = 'utf-8'):
211+
passed_count = 0
212+
failed_count = 0
213+
219214
try:
220215
from vector.apps.DataAPI.manage_models import SystemTest
221-
if verbose:
222-
print("No need to process system test results using --system-tests-status")
223-
return
224216
except:
225-
pass
226-
227-
print(" Processing QA test results for " + mp)
228-
callStr = os.environ.get('VECTORCAST_DIR') + os.sep + "manage -p " + mp + " --system-tests-status"
229-
if level:
230-
callStr += " --level " + level
231-
if envName:
232-
callStr += " -e " + envName
233-
234-
p = subprocess.Popen(callStr, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
235-
out, err = p.communicate()
217+
if verbose:
218+
print("No QA Environment that can be processed using --system-tests-status")
219+
return passed_count, failed_count
220+
221+
if level and envName:
222+
nameLevel = level + "_" + envName
223+
nameLevel = nameLevel.replace("\\","/").replace("/","_")
224+
report_name = "{}_{}_system_tests_status.html".format(os.path.basename(mp)[:-4], nameLevel)
225+
else:
226+
report_name = os.path.basename(mp)[:-4] + "_system_tests_status.html"
227+
228+
if os.path.exists(report_name):
229+
with open(report_name,"rb") as fd:
230+
raw = fd.read()
231+
out = raw.decode(encoding, 'replace')
232+
233+
passed_count, failed_count = processSystemTestResultsData(out.splitlines(), encoding)
236234

237-
if err:
238-
print("{} {}".format(out, err))
239-
passed_count, failed_count = processSystemTestResultsData(out.splitlines(), encoding)
240-
241-
saveQATestStatus(mp)
242-
243235
return passed_count, failed_count
244236

245237
if __name__ == '__main__':

generate_sonarqube_testresults.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,11 @@ def generate_unit(self):
558558
if isinstance(self.api, CoverApi):
559559
try:
560560
if self.topLevelAPI == None:
561-
api = VCProjectApi(self.FullManageProjectName)
561+
vcproj = VCProjectApi(self.FullManageProjectName)
562562
else:
563-
api = self.topLevelAPI
563+
vcproj = self.topLevelAPI
564564

565-
for env in api.Environment.all():
565+
for env in vcproj.Environment.all():
566566
if env.compiler.name == self.compiler and env.testsuite.name == self.testsuite and env.name == self.env and env.system_tests:
567567
for st in env.system_tests:
568568
pass_fail_rerun = ""
@@ -580,12 +580,8 @@ def generate_unit(self):
580580
print ("{} {} {}".format(level, st.name, pass_fail_rerun))
581581
self.write_testcase(st, level, st.name, env.definition.is_monitored)
582582

583-
# callStr = os.getenv('VECTORCAST_DIR') + os.sep + "manage -p " + self.FullManageProjectName + " --system-tests-status=" + self.manageProjectName + "_system_tests_status.html"
584-
# p = subprocess.Popen(callStr, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
585-
# out, err = p.communicate()
586-
587583
if self.topLevelAPI == None:
588-
api.close()
584+
vcproj.close()
589585

590586
except ImportError as e:
591587
from generate_qa_results_xml import genQATestResults

generate_xml.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,32 @@ def __init__(self, cover_report_name, verbose, use_ci):
8282
self.use_ci = " --ci "
8383
else:
8484
self.use_ci = ""
85+
self.system_tests_status_report_generated = False
8586

87+
def generate_system_test_status_report(self):
88+
if self.system_tests_status_report_generated:
89+
return
90+
91+
report_name = os.path.basename(self.FullManageProjectName)[:-4] + "_system_tests_status.html"
92+
93+
print(" Creating System Test Status " + self.FullManageProjectName)
94+
callStr = os.environ.get('VECTORCAST_DIR') + os.sep + "manage -p " + self.FullManageProjectName + " --system-tests-status=" + report_name
95+
96+
import subprocess
97+
98+
print(callStr)
99+
p = subprocess.Popen(callStr, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
100+
out, err = p.communicate()
101+
102+
if os.path.exists(report_name):
103+
print("File exists: " + report_name)
104+
else:
105+
print("File not exists: " + report_name)
106+
107+
if err:
108+
print("Cannot create system test status report{} {}".format(out, err))
109+
110+
self.system_tests_status_report_generated = True
86111
#
87112
# BaseGenerateXml - calculate coverage value
88113
#
@@ -542,7 +567,8 @@ def __init__(self, FullManageProjectName, build_dir, env, compiler, testsuite, c
542567
self.cbtDict = None
543568

544569
if os.path.exists(cov_path) and os.path.exists(cov_path[:-4]):
545-
self.using_cover = True
570+
self.using_cover = True
571+
self.generate_system_test_status_report()
546572
try:
547573
self.api = CoverApi(cov_path)
548574
except:
@@ -621,18 +647,16 @@ def generate_unit(self):
621647
if self.verbose:
622648
print (level, st.name, pass_fail_rerun)
623649
self.write_testcase(st, level, st.name)
624-
from generate_qa_results_xml import saveQATestStatus
625-
saveQATestStatus(self.FullManageProjectName)
626-
627650
api.close()
628651

629652
except ImportError as e:
630-
from generate_qa_results_xml import genQATestResults
631-
pc,fc = genQATestResults(self.FullManageProjectName, self.compiler+ "/" + self.testsuite, self.env, True, self.encFmt)
632-
self.failed_count += fc
633-
self.passed_count += pc
634-
return
653+
pass
635654

655+
from generate_qa_results_xml import genQATestResults
656+
pc,fc = genQATestResults(self.FullManageProjectName, self.compiler + "/" + self.testsuite, self.env, True, self.encFmt)
657+
self.failed_count += fc
658+
self.passed_count += pc
659+
636660
else:
637661

638662
try:

getjobs.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,14 @@ def printEnvInfoNoDataAPI(ManageProjectName, printData = True, printEnvType = Fa
162162

163163
max_indent = 0
164164
veryMax = 8
165-
165+
last_index_max_line = 0
166+
166167
for line in enabledList:
167168
indent = len(line) - len(line.lstrip())
168169

169170
if indent > max_indent and indent <= veryMax:
170171
max_indent = indent
172+
last_index_max_line = line
171173

172174
if max_indent == 8:
173175
source_match_string = "^ [^\s]"
@@ -190,6 +192,9 @@ def printEnvInfoNoDataAPI(ManageProjectName, printData = True, printEnvType = Fa
190192
group_match_string = None
191193
env_match_string = "^ [^\s]"
192194
else:
195+
print("[DEBUG] Error with full-status report")
196+
print("[DEBUG] Highest indent is with this line\n" + str(last_index_max_line))
197+
print("\n".join(enabledList))
193198
raise ValueError("Error deciphering max_index: " + str(max_indent))
194199

195200
source = None
@@ -234,12 +239,12 @@ def printEnvironmentInfo(ManageProjectName, printData = True, printEnvType = Fal
234239
try:
235240

236241
from vector.apps.DataAPI.vcproject_api import VCProjectApi
237-
api = VCProjectApi(ManageProjectName)
238-
ret_info = printEnvInfoDataAPI(api, printData, printEnvType)
239-
api.close()
242+
243+
vcproj = VCProjectApi(ManageProjectName)
244+
ret_info = printEnvInfoDataAPI(vcproj, printData, printEnvType)
245+
vcproj.close()
240246
return ret_info
241247

242-
243248
except:
244249
return printEnvInfoNoDataAPI(ManageProjectName, printData, printEnvType)
245250

0 commit comments

Comments
 (0)