mirror of https://github.com/mongodb/mongo
SERVER-103143 Silence cheetah namemapper warning (#36148)
GitOrigin-RevId: d1449bf2f467f7589b6f0c268820433e9a2f22ca
This commit is contained in:
parent
c92c4464a4
commit
797aff2c14
|
|
@ -30,6 +30,9 @@
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
warnings.filterwarnings("ignore", message="\nYou don't have the C version of NameMapper installed")
|
||||||
|
|
||||||
from Cheetah.Template import Template
|
from Cheetah.Template import Template
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,9 @@
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
warnings.filterwarnings("ignore", message="\nYou don't have the C version of NameMapper installed")
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from Cheetah.Template import Template
|
from Cheetah.Template import Template
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,9 @@
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
warnings.filterwarnings("ignore", message="\nYou don't have the C version of NameMapper installed")
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from Cheetah.Template import Template
|
from Cheetah.Template import Template
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,19 @@
|
||||||
from Cheetah.Template import Template
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
import bisect
|
import bisect
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
from functools import reduce
|
import os
|
||||||
|
import sys
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
warnings.filterwarnings("ignore", message="\nYou don't have the C version of NameMapper installed")
|
||||||
|
|
||||||
|
from Cheetah.Template import Template
|
||||||
|
|
||||||
SBOM_PATH = "../../../sbom.json"
|
SBOM_PATH = "../../../sbom.json"
|
||||||
TEMPLATE_PATH = "README.third_party.md.template"
|
TEMPLATE_PATH = "README.third_party.md.template"
|
||||||
README_PATH = "../../../README.third_party.md"
|
README_PATH = "../../../README.third_party.md"
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO,
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
||||||
format='%(asctime)s - %(levelname)s - %(message)s')
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
@ -31,7 +33,7 @@ def main():
|
||||||
template_data = {
|
template_data = {
|
||||||
"component_chart": component_chart_string,
|
"component_chart": component_chart_string,
|
||||||
"component_links": component_links_string,
|
"component_links": component_links_string,
|
||||||
"wiredtiger_chart": wiredtiger_chart_string
|
"wiredtiger_chart": wiredtiger_chart_string,
|
||||||
}
|
}
|
||||||
create_markdown_with_template(template_data)
|
create_markdown_with_template(template_data)
|
||||||
|
|
||||||
|
|
@ -45,7 +47,7 @@ def test_filepaths() -> None:
|
||||||
|
|
||||||
def load_sbom() -> dict:
|
def load_sbom() -> dict:
|
||||||
try:
|
try:
|
||||||
with open(SBOM_PATH, 'r') as file:
|
with open(SBOM_PATH, "r") as file:
|
||||||
sbom = json.load(file)
|
sbom = json.load(file)
|
||||||
logging.info("%s JSON data loaded.", SBOM_PATH)
|
logging.info("%s JSON data loaded.", SBOM_PATH)
|
||||||
return sbom
|
return sbom
|
||||||
|
|
@ -73,26 +75,30 @@ def sbom_to_component_chart(sbom: dict) -> list[list[str]]:
|
||||||
k, v = prop["name"], prop["value"]
|
k, v = prop["name"], prop["value"]
|
||||||
if k == "emits_persisted_data":
|
if k == "emits_persisted_data":
|
||||||
emits_persisted_data = ("", "✗")[v == "true"]
|
emits_persisted_data = ("", "✗")[v == "true"]
|
||||||
distributed_in_release_binaries = (
|
distributed_in_release_binaries = ("", "✗")[component["scope"] == "required"]
|
||||||
"", "✗")[component["scope"] == "required"]
|
|
||||||
|
|
||||||
row = [
|
row = [
|
||||||
item.replace(
|
item.replace("|", "")
|
||||||
"|",
|
for item in [
|
||||||
"") for item in [
|
|
||||||
f"[{name}]",
|
f"[{name}]",
|
||||||
license_string,
|
license_string,
|
||||||
version,
|
version,
|
||||||
emits_persisted_data,
|
emits_persisted_data,
|
||||||
distributed_in_release_binaries]]
|
distributed_in_release_binaries,
|
||||||
|
]
|
||||||
|
]
|
||||||
bisect.insort(component_chart, row, key=lambda c: c[0].lower())
|
bisect.insort(component_chart, row, key=lambda c: c[0].lower())
|
||||||
|
|
||||||
component_chart.insert(0,
|
component_chart.insert(
|
||||||
["Name",
|
0,
|
||||||
|
[
|
||||||
|
"Name",
|
||||||
"License",
|
"License",
|
||||||
"Vendored Version",
|
"Vendored Version",
|
||||||
"Emits persisted data",
|
"Emits persisted data",
|
||||||
"Distributed in Release Binaries"])
|
"Distributed in Release Binaries",
|
||||||
|
],
|
||||||
|
)
|
||||||
return component_chart
|
return component_chart
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -103,9 +109,7 @@ def sbom_to_component_links_string(sbom: dict) -> list[list[str]]:
|
||||||
for component in components:
|
for component in components:
|
||||||
check_component_validity(component)
|
check_component_validity(component)
|
||||||
info_link = get_component_info_link(component)
|
info_link = get_component_info_link(component)
|
||||||
bisect.insort(
|
bisect.insort(link_list, f"[{component['name'].replace('|','')}]: {info_link}")
|
||||||
link_list,
|
|
||||||
f"[{component['name'].replace('|','')}]: {info_link}")
|
|
||||||
|
|
||||||
return "\n".join(link_list)
|
return "\n".join(link_list)
|
||||||
|
|
||||||
|
|
@ -119,10 +123,7 @@ def sbom_to_wiredtiger_chart(sbom: dict) -> list[list[str]]:
|
||||||
locations = get_component_locations(component)
|
locations = get_component_locations(component)
|
||||||
for location in locations:
|
for location in locations:
|
||||||
if location.startswith("src/third_party/wiredtiger/"):
|
if location.startswith("src/third_party/wiredtiger/"):
|
||||||
bisect.insort(
|
bisect.insort(wiredtiger_chart, [component["name"].replace("|", "")])
|
||||||
wiredtiger_chart, [
|
|
||||||
component["name"].replace(
|
|
||||||
"|", "")])
|
|
||||||
|
|
||||||
return wiredtiger_chart
|
return wiredtiger_chart
|
||||||
|
|
||||||
|
|
@ -130,9 +131,7 @@ def sbom_to_wiredtiger_chart(sbom: dict) -> list[list[str]]:
|
||||||
def check_component_validity(component) -> None:
|
def check_component_validity(component) -> None:
|
||||||
for required_key in ["name", "version", "licenses"]:
|
for required_key in ["name", "version", "licenses"]:
|
||||||
if required_key not in component:
|
if required_key not in component:
|
||||||
logging.error(
|
logging.error("Error: no key %s found in json. Exiting. JSON dump:", required_key)
|
||||||
"Error: no key %s found in json. Exiting. JSON dump:",
|
|
||||||
required_key)
|
|
||||||
logging.error(json.dumps(component))
|
logging.error(json.dumps(component))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
@ -145,17 +144,12 @@ def get_component_info_link(component) -> str:
|
||||||
if k == "info_link":
|
if k == "info_link":
|
||||||
links.append(v)
|
links.append(v)
|
||||||
if len(links) != 1:
|
if len(links) != 1:
|
||||||
logging.warning(
|
logging.warning("Warning: Expected 1 info_link for %s. Got %d:", name, len(links))
|
||||||
"Warning: Expected 1 info_link for %s. Got %d:",
|
|
||||||
name,
|
|
||||||
len(links))
|
|
||||||
if len(links) > 1:
|
if len(links) > 1:
|
||||||
logging.warning(" ".join(links))
|
logging.warning(" ".join(links))
|
||||||
logging.warning("Using first link only.")
|
logging.warning("Using first link only.")
|
||||||
else:
|
else:
|
||||||
logging.warning(
|
logging.warning("Falling back to `purl` value: %s", component["purl"])
|
||||||
"Falling back to `purl` value: %s",
|
|
||||||
component['purl'])
|
|
||||||
links.append(component["purl"])
|
links.append(component["purl"])
|
||||||
return links[0]
|
return links[0]
|
||||||
|
|
||||||
|
|
@ -163,8 +157,7 @@ def get_component_info_link(component) -> str:
|
||||||
def get_component_locations(component) -> list[str]:
|
def get_component_locations(component) -> list[str]:
|
||||||
if "evidence" not in component or "occurrences" not in component["evidence"]:
|
if "evidence" not in component or "occurrences" not in component["evidence"]:
|
||||||
return []
|
return []
|
||||||
return [occurence["location"]
|
return [occurence["location"] for occurence in component["evidence"]["occurrences"]]
|
||||||
for occurence in component["evidence"]["occurrences"]]
|
|
||||||
|
|
||||||
|
|
||||||
def right_pad_chart_values(chart: list[list[str]]) -> list[list[str]]:
|
def right_pad_chart_values(chart: list[list[str]]) -> list[list[str]]:
|
||||||
|
|
@ -187,15 +180,21 @@ def chart_to_string(chart: list[list[str]]) -> str:
|
||||||
|
|
||||||
|
|
||||||
def create_markdown_with_template(data):
|
def create_markdown_with_template(data):
|
||||||
output = str(Template.compile(file=TEMPLATE_PATH,
|
output = str(
|
||||||
|
Template.compile(
|
||||||
|
file=TEMPLATE_PATH,
|
||||||
compilerSettings={
|
compilerSettings={
|
||||||
'commentStartToken': '//',
|
"commentStartToken": "//",
|
||||||
'directiveStartToken': '!!',
|
"directiveStartToken": "!!",
|
||||||
'directiveEndToken': '!!',
|
"directiveEndToken": "!!",
|
||||||
})(namespaces=[data]))
|
},
|
||||||
|
)(namespaces=[data])
|
||||||
|
)
|
||||||
|
|
||||||
with open(README_PATH, 'w') as f:
|
with open(README_PATH, "w") as f:
|
||||||
f.write("[DO NOT MODIFY THIS FILE MANUALLY. It is generated by src/third_party/tools/gen_thirdpartyreadme.py]: #\n\n")
|
f.write(
|
||||||
|
"[DO NOT MODIFY THIS FILE MANUALLY. It is generated by src/third_party/tools/gen_thirdpartyreadme.py]: #\n\n"
|
||||||
|
)
|
||||||
f.write(output)
|
f.write(output)
|
||||||
|
|
||||||
logging.info("Markdown file created successfully.")
|
logging.info("Markdown file created successfully.")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue