Skip to content

Commit dda401f

Browse files
committed
Inline CSV table into RST page
1 parent 2e67a32 commit dda401f

File tree

2 files changed

+55
-57
lines changed

2 files changed

+55
-57
lines changed

.github/workflows/csv-coverage.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,4 @@ jobs:
6666
name: rst-flow-model-coverage
6767
path: |
6868
flow-model-coverage.rst
69-
rst-csv-flow-model-coverage-*.csv
7069

misc/scripts/generate-csv-coverage-report.py

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,12 @@ def __init__(self, lang, capitalized_lang, ext, ql_path):
136136

137137
# The names of input and output files. The placeholder {language} is replaced with the language name.
138138
output_rst = "flow-model-coverage.rst"
139-
output_rst_csv = "rst-csv-flow-model-coverage-{language}.csv"
140139
output_ql_csv = "output-{language}.csv"
141140
output_csv = "csv-flow-model-coverage-{language}.csv"
142141
input_framework_csv = data_prefix + "misc/scripts/frameworks-{language}.csv"
143142
input_cwe_sink_csv = data_prefix + "misc/scripts/cwe-sink-{language}.csv"
144143

145-
with open(output_rst, 'w') as rst_file:
144+
with open(output_rst, 'w', newline='') as rst_file:
146145
for config in configs:
147146
lang = config.lang
148147
db = "empty-" + lang
@@ -230,81 +229,81 @@ def __init__(self, lang, capitalized_lang, ext, ql_path):
230229

231230
sorted_cwes = sorted(cwes)
232231

233-
file_name = output_rst_csv.format(language=lang)
234-
235232
rst_file.write(
236233
config.capitalized_lang + " framework & library support\n")
237234
rst_file.write("================================\n\n")
238235
rst_file.write(".. csv-table:: \n")
239-
rst_file.write(" :file: " + file_name + "\n")
240-
rst_file.write(" :header-rows: 1\n")
241-
rst_file.write(" :class: fullWidthTable\n")
242-
rst_file.write(" :widths: auto\n\n")
236+
rst_file.write(" :header-rows: 1\n")
237+
rst_file.write(" :class: fullWidthTable\n")
238+
rst_file.write(" :widths: auto\n\n")
239+
240+
row_prefix = " "
243241

244242
# Write CSV file with package statistics and framework data to be used in RST file.
245-
with open(file_name, 'w', newline='') as csvfile:
246-
csvwriter = csv.writer(csvfile)
243+
csvwriter = csv.writer(rst_file)
247244

248-
# Write CSV header.
249-
headers = ["Framework / library",
250-
"Package",
251-
"Remote flow sources",
252-
"Taint & value steps",
253-
"Sinks (total)"]
254-
for cwe in sorted_cwes:
255-
headers.append(
256-
"`{0}` :sub:`{1}`".format(cwe, cwes[cwe]["label"]))
257-
csvwriter.writerow(headers)
245+
# Write CSV header.
246+
headers = [row_prefix + "Framework / library",
247+
"Package",
248+
"Remote flow sources",
249+
"Taint & value steps",
250+
"Sinks (total)"]
251+
for cwe in sorted_cwes:
252+
headers.append(
253+
"`{0}` :sub:`{1}`".format(cwe, cwes[cwe]["label"]))
254+
csvwriter.writerow(headers)
258255

259-
processed_packages = set()
256+
processed_packages = set()
260257

261-
# Write a row for each framework.
262-
for framework in sorted(frameworks):
263-
row = []
258+
# Write a row for each framework.
259+
for framework in sorted(frameworks):
260+
row = []
264261

265-
# Add the framework name to the row
266-
if not frameworks[framework]["url"]:
267-
row.append(framework)
268-
else:
269-
row.append(
270-
"`" + framework + " <" + frameworks[framework]["url"] + ">`_")
262+
# Add the framework name to the row
263+
if not frameworks[framework]["url"]:
264+
row.append(row_prefix + framework)
265+
else:
266+
row.append(
267+
row_prefix + "`" + framework + " <" + frameworks[framework]["url"] + ">`_")
271268

272-
# Add the package name to the row
273-
row.append("``" + frameworks[framework]["package"] + "``")
269+
# Add the package name to the row
270+
row.append("``" + frameworks[framework]["package"] + "``")
274271

275-
prefix = frameworks[framework]["package"]
272+
prefix = frameworks[framework]["package"]
276273

277-
# Collect statistics on the current framework
278-
# package name is either full name, such as "org.hibernate", or a prefix, such as "java.*"
279-
def collect_framework(): return collect_package_stats(
280-
packages, cwes, lambda p: (prefix.endswith("*") and p.startswith(prefix[:-1])) or (not prefix.endswith("*") and prefix == p))
274+
# Collect statistics on the current framework
275+
# package name is either full name, such as "org.hibernate", or a prefix, such as "java.*"
276+
def collect_framework(): return collect_package_stats(
277+
packages, cwes, lambda p: (prefix.endswith("*") and p.startswith(prefix[:-1])) or (not prefix.endswith("*") and prefix == p))
281278

282-
row, f_processed_packages = add_package_stats_to_row(
283-
row, sorted_cwes, collect_framework)
279+
row, f_processed_packages = add_package_stats_to_row(
280+
row, sorted_cwes, collect_framework)
284281

285-
csvwriter.writerow(row)
286-
processed_packages.update(f_processed_packages)
282+
csvwriter.writerow(row)
283+
processed_packages.update(f_processed_packages)
287284

288-
# Collect statistics on all packages that are not part of a framework
289-
row = ["Others", None]
285+
# Collect statistics on all packages that are not part of a framework
286+
row = [row_prefix + "Others", None]
290287

291-
def collect_others(): return collect_package_stats(
292-
packages, cwes, lambda p: p not in processed_packages)
288+
def collect_others(): return collect_package_stats(
289+
packages, cwes, lambda p: p not in processed_packages)
293290

294-
row, other_packages = add_package_stats_to_row(
295-
row, sorted_cwes, collect_others)
291+
row, other_packages = add_package_stats_to_row(
292+
row, sorted_cwes, collect_others)
296293

297-
row[1] = ", ".join("``{0}``".format(p)
298-
for p in sorted(other_packages))
294+
row[1] = ", ".join("``{0}``".format(p)
295+
for p in sorted(other_packages))
299296

300-
csvwriter.writerow(row)
297+
csvwriter.writerow(row)
301298

302-
# Collect statistics on all packages
303-
row = ["Totals", None]
299+
# Collect statistics on all packages
300+
row = [row_prefix + "Totals", None]
304301

305-
def collect_total(): return collect_package_stats(packages, cwes, lambda p: True)
302+
def collect_total(): return collect_package_stats(packages, cwes, lambda p: True)
306303

307-
row, _ = add_package_stats_to_row(
308-
row, sorted_cwes, collect_total)
304+
row, _ = add_package_stats_to_row(
305+
row, sorted_cwes, collect_total)
309306

310-
csvwriter.writerow(row)
307+
csvwriter.writerow(row)
308+
309+
rst_file.write("\n\n")

0 commit comments

Comments
 (0)