scripts: west_commands: zspdx: writer: Fix linter issues
Fix issues reported by ruff. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
This commit is contained in:
parent
01bfd2600d
commit
88d7715a29
2 changed files with 15 additions and 15 deletions
|
@ -1190,11 +1190,6 @@
|
||||||
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
|
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
|
||||||
"UP032", # https://docs.astral.sh/ruff/rules/f-string
|
"UP032", # https://docs.astral.sh/ruff/rules/f-string
|
||||||
]
|
]
|
||||||
"./scripts/west_commands/zspdx/writer.py" = [
|
|
||||||
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
|
|
||||||
"F541", # https://docs.astral.sh/ruff/rules/f-string-missing-placeholders
|
|
||||||
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
|
|
||||||
]
|
|
||||||
"./scripts/zephyr_module.py" = [
|
"./scripts/zephyr_module.py" = [
|
||||||
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
|
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
|
||||||
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
|
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
|
||||||
|
|
|
@ -2,14 +2,13 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from west import log
|
from west import log
|
||||||
|
|
||||||
from zspdx.util import getHashes
|
from zspdx.util import getHashes
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
CPE23TYPE_REGEX = (
|
CPE23TYPE_REGEX = (
|
||||||
r'^cpe:2\.3:[aho\*\-](:(((\?*|\*?)([a-zA-Z0-9\-\._]|(\\[\\\*\?!"#$$%&\'\(\)\+,\/:;<=>@\[\]\^'
|
r'^cpe:2\.3:[aho\*\-](:(((\?*|\*?)([a-zA-Z0-9\-\._]|(\\[\\\*\?!"#$$%&\'\(\)\+,\/:;<=>@\[\]\^'
|
||||||
r"`\{\|}~]))+(\?*|\*?))|[\*\-])){5}(:(([a-zA-Z]{2,3}(-([a-zA-Z]{2}|[0-9]{3}))?)|[\*\-]))(:(((\?*"
|
r"`\{\|}~]))+(\?*|\*?))|[\*\-])){5}(:(([a-zA-Z]{2,3}(-([a-zA-Z]{2}|[0-9]{3}))?)|[\*\-]))(:(((\?*"
|
||||||
|
@ -26,7 +25,10 @@ def _normalize_spdx_name(name):
|
||||||
# 1) f: file handle for SPDX document
|
# 1) f: file handle for SPDX document
|
||||||
# 2) rln: Relationship object being described
|
# 2) rln: Relationship object being described
|
||||||
def writeRelationshipSPDX(f, rln):
|
def writeRelationshipSPDX(f, rln):
|
||||||
f.write(f"Relationship: {_normalize_spdx_name(rln.refA)} {rln.rlnType} {_normalize_spdx_name(rln.refB)}\n")
|
f.write(
|
||||||
|
f"Relationship: {_normalize_spdx_name(rln.refA)} {rln.rlnType} "
|
||||||
|
f"{_normalize_spdx_name(rln.refB)}\n"
|
||||||
|
)
|
||||||
|
|
||||||
# Output tag-value SPDX 2.3 content for the given File object.
|
# Output tag-value SPDX 2.3 content for the given File object.
|
||||||
# Arguments:
|
# Arguments:
|
||||||
|
@ -45,7 +47,7 @@ FileChecksum: SHA1: {bf.sha1}
|
||||||
f.write(f"FileChecksum: MD5: {bf.md5}\n")
|
f.write(f"FileChecksum: MD5: {bf.md5}\n")
|
||||||
f.write(f"LicenseConcluded: {bf.concludedLicense}\n")
|
f.write(f"LicenseConcluded: {bf.concludedLicense}\n")
|
||||||
if len(bf.licenseInfoInFile) == 0:
|
if len(bf.licenseInfoInFile) == 0:
|
||||||
f.write(f"LicenseInfoInFile: NONE\n")
|
f.write("LicenseInfoInFile: NONE\n")
|
||||||
else:
|
else:
|
||||||
for licInfoInFile in bf.licenseInfoInFile:
|
for licInfoInFile in bf.licenseInfoInFile:
|
||||||
f.write(f"LicenseInfoInFile: {licInfoInFile}\n")
|
f.write(f"LicenseInfoInFile: {licInfoInFile}\n")
|
||||||
|
@ -111,10 +113,10 @@ PackageCopyrightText: {pkg.cfg.copyrightText}
|
||||||
for licFromFiles in pkg.licenseInfoFromFiles:
|
for licFromFiles in pkg.licenseInfoFromFiles:
|
||||||
f.write(f"PackageLicenseInfoFromFiles: {licFromFiles}\n")
|
f.write(f"PackageLicenseInfoFromFiles: {licFromFiles}\n")
|
||||||
else:
|
else:
|
||||||
f.write(f"PackageLicenseInfoFromFiles: NOASSERTION\n")
|
f.write("PackageLicenseInfoFromFiles: NOASSERTION\n")
|
||||||
f.write(f"FilesAnalyzed: true\nPackageVerificationCode: {pkg.verificationCode}\n\n")
|
f.write(f"FilesAnalyzed: true\nPackageVerificationCode: {pkg.verificationCode}\n\n")
|
||||||
else:
|
else:
|
||||||
f.write(f"FilesAnalyzed: false\nPackageComment: Utility target; no files\n\n")
|
f.write("FilesAnalyzed: false\nPackageComment: Utility target; no files\n\n")
|
||||||
|
|
||||||
# write package relationships
|
# write package relationships
|
||||||
if len(pkg.rlns) > 0:
|
if len(pkg.rlns) > 0:
|
||||||
|
@ -162,14 +164,17 @@ Created: {datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")}
|
||||||
extDocs = list(doc.externalDocuments)
|
extDocs = list(doc.externalDocuments)
|
||||||
extDocs.sort(key = lambda x: x.cfg.docRefID)
|
extDocs.sort(key = lambda x: x.cfg.docRefID)
|
||||||
for extDoc in extDocs:
|
for extDoc in extDocs:
|
||||||
f.write(f"ExternalDocumentRef: {extDoc.cfg.docRefID} {extDoc.cfg.namespace} SHA1: {extDoc.myDocSHA1}\n")
|
f.write(
|
||||||
f.write(f"\n")
|
f"ExternalDocumentRef: {extDoc.cfg.docRefID} {extDoc.cfg.namespace} "
|
||||||
|
f"SHA1: {extDoc.myDocSHA1}\n"
|
||||||
|
)
|
||||||
|
f.write("\n")
|
||||||
|
|
||||||
# write relationships owned by this Document (not by its Packages, etc.), if any
|
# write relationships owned by this Document (not by its Packages, etc.), if any
|
||||||
if len(doc.relationships) > 0:
|
if len(doc.relationships) > 0:
|
||||||
for rln in doc.relationships:
|
for rln in doc.relationships:
|
||||||
writeRelationshipSPDX(f, rln)
|
writeRelationshipSPDX(f, rln)
|
||||||
f.write(f"\n")
|
f.write("\n")
|
||||||
|
|
||||||
# write packages
|
# write packages
|
||||||
for pkg in doc.pkgs.values():
|
for pkg in doc.pkgs.values():
|
||||||
|
@ -198,7 +203,7 @@ def writeSPDX(spdxPath, doc):
|
||||||
# calculate hash of the document we just wrote
|
# calculate hash of the document we just wrote
|
||||||
hashes = getHashes(spdxPath)
|
hashes = getHashes(spdxPath)
|
||||||
if not hashes:
|
if not hashes:
|
||||||
log.err(f"Error: created document but unable to calculate hash values")
|
log.err("Error: created document but unable to calculate hash values")
|
||||||
return False
|
return False
|
||||||
doc.myDocSHA1 = hashes[0]
|
doc.myDocSHA1 = hashes[0]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue