Skip to content

Commit f37ec03

Browse files
authored
Merge pull request #3 from sw360/2-do-not-add-empty-acknowlegments-files-and-filehashes
Do not add empty acknowlegments files and filehashes
2 parents b602247 + d08ce0e commit f37ec03

File tree

8 files changed

+55
-44
lines changed

8 files changed

+55
-44
lines changed

ChangeLog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Python library to read Component License Information (CLI) files
22

3+
## NEXT
4+
5+
* do not add empty acknowledgments, files and filehashes.
6+
37
## V2.0.1
48

5-
* remove requests dependency (has never been used...)
9+
* remove requests dependency (has never been used...).
610

711
## V2.0.0
812

RunChecks.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22
# Run quality checks
33
# ------------------
44

5-
# 2023-12-24, T. Graf
5+
# 2024-05-07, T. Graf
66

7+
Write-Host "flake8 ..."
78
poetry run flake8
9+
10+
Write-Host "markdownlint ..."
811
npx -q markdownlint-cli *.md
12+
13+
Write-Host "isort ..."
914
poetry run isort .
15+
16+
Write-Host "mypy ..."
1017
poetry run mypy .
1118

19+
Write-Host "Done."
1220

1321
# -----------------------------------
1422
# -----------------------------------

cli_support/CLI.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------------
2-
# (c) 2019-2023 Siemens AG
2+
# (c) 2019-2024 Siemens AG
33
# All Rights Reserved.
44
# Author: thomas.graf@siemens.com
55
#
@@ -197,8 +197,9 @@ def write_to_file(self, filename: str) -> None:
197197
tags.text = ",".join(str(x) for x in self.tags)
198198

199199
comment = ET.SubElement(root, "Comment")
200-
cdata = self.CDATA(self.comment)
201-
comment.append(cdata)
200+
if self.comment:
201+
cdata = self.CDATA(self.comment)
202+
comment.append(cdata)
202203

203204
tree = ET.ElementTree(root)
204205
if not sys.version_info < (3, 9):

cli_support/cli_assessment_summary.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------------
2-
# (c) 2023 Siemens AG
2+
# (c) 2023-2024 Siemens AG
33
# All Rights Reserved.
44
# Author: thomas.graf@siemens.com
55
#
@@ -59,9 +59,11 @@ def _read_from_element(self, element: ET.Element) -> None:
5959
def _append_to_xml(self, parent: ET.Element) -> None:
6060
"""Write assessment summary to XML element."""
6161
gi = ET.SubElement(parent, "AssessmentSummary")
62+
6263
node = ET.SubElement(gi, "GeneralAssessment")
63-
cdata = self.CDATA(self.general_assessment)
64-
node.append(cdata)
64+
if self.general_assessment:
65+
cdata = self.CDATA(self.general_assessment)
66+
node.append(cdata)
6567

6668
node = ET.SubElement(gi, "CriticalFilesFound")
6769
node.text = self.critical_files_found
@@ -76,5 +78,6 @@ def _append_to_xml(self, parent: ET.Element) -> None:
7678
node.text = self.usage_restrictions_found
7779

7880
node = ET.SubElement(gi, "AdditionalNotes")
79-
cdata = self.CDATA(self.additional_notes)
80-
node.append(cdata)
81+
if self.additional_notes:
82+
cdata = self.CDATA(self.additional_notes)
83+
node.append(cdata)

cli_support/cli_file_item_base.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------------
2-
# (c) 2019-2023 Siemens AG
2+
# (c) 2019-2024 Siemens AG
33
# All Rights Reserved.
44
# Author: thomas.graf@siemens.com
55
#
@@ -40,10 +40,12 @@ def _read_files_from_element(self, element: ET.Element) -> None:
4040

4141
def _append_to_xml(self, parent: ET.Element) -> None:
4242
"""Write files and hashes to XML element."""
43-
file_data = ET.SubElement(parent, "Files")
44-
cdata = self.CDATA("\n".join(str(x) for x in self.files))
45-
file_data.append(cdata)
46-
47-
hash_data = ET.SubElement(parent, "FileHash")
48-
cdata = self.CDATA("\n".join(str(x) for x in self.hashes))
49-
hash_data.append(cdata)
43+
if len(self.files) > 0:
44+
file_data = ET.SubElement(parent, "Files")
45+
cdata = self.CDATA("\n".join(str(x) for x in self.files))
46+
file_data.append(cdata)
47+
48+
if len(self.hashes) > 0:
49+
hash_data = ET.SubElement(parent, "FileHash")
50+
cdata = self.CDATA("\n".join(str(x) for x in self.hashes))
51+
hash_data.append(cdata)

cli_support/cli_general_information.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------------
2-
# (c) 2023 Siemens AG
2+
# (c) 2023-2024 Siemens AG
33
# All Rights Reserved.
44
# Author: thomas.graf@siemens.com
55
#
@@ -115,12 +115,14 @@ def _append_to_xml(self, parent: ET.Element) -> None:
115115
node.text = self.component_release_date
116116

117117
hash_data = ET.SubElement(gi, "LinkComponentManagement")
118-
cdata = self.CDATA(self.link_component_management)
119-
hash_data.append(cdata)
118+
if self.link_component_management:
119+
cdata = self.CDATA(self.link_component_management)
120+
hash_data.append(cdata)
120121

121122
hash_data = ET.SubElement(gi, "LinkScanTool")
122-
cdata = self.CDATA(self.link_scan_tool)
123-
hash_data.append(cdata)
123+
if self.link_scan_tool:
124+
cdata = self.CDATA(self.link_scan_tool)
125+
hash_data.append(cdata)
124126

125127
ci = ET.SubElement(gi, "ComponentId")
126128

cli_support/cli_license.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------------
2-
# (c) 2019-2023 Siemens AG
2+
# (c) 2019-2024 Siemens AG
33
# All Rights Reserved.
44
# Author: thomas.graf@siemens.com
55
#
@@ -77,9 +77,10 @@ def _append_to_xml(self, parent: ET.Element) -> None:
7777

7878
CliFileItemBase._append_to_xml(self, lic)
7979

80-
ack = ET.SubElement(lic, "Acknowledgements")
81-
cdata = self.CDATA("\n".join(str(x) for x in self.acknowledgements))
82-
ack.append(cdata)
80+
if len(self.acknowledgements) > 0:
81+
ack = ET.SubElement(lic, "Acknowledgements")
82+
cdata = self.CDATA("\n".join(str(x) for x in self.acknowledgements))
83+
ack.append(cdata)
8384

8485
tags = ET.SubElement(lic, "Tags")
8586
tags.text = ",".join(str(x) for x in self.tags)

tests/test_cli_clifile.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------------
2-
# (c) 2022-2023 Siemens AG
2+
# (c) 2022-2024 Siemens AG
33
# All Rights Reserved.
44
# Author: thomas.graf@siemens.com
55
#
@@ -179,35 +179,25 @@ def test_write_file_minimal(self) -> None:
179179
<ComponentVersion />
180180
<ComponentHash />
181181
<ComponentReleaseDate />
182-
<LinkComponentManagement>
183-
<![CDATA[]]></LinkComponentManagement>
184-
<LinkScanTool>
185-
<![CDATA[]]></LinkScanTool>
182+
<LinkComponentManagement />
183+
<LinkScanTool />
186184
<ComponentId>
187185
<Type />
188186
<Id />
189187
</ComponentId>
190188
</GeneralInformation>
191189
<AssessmentSummary>
192-
<GeneralAssessment>
193-
<![CDATA[]]></GeneralAssessment>
190+
<GeneralAssessment />
194191
<CriticalFilesFound>None</CriticalFilesFound>
195192
<DependencyNotes>None</DependencyNotes>
196193
<ExportRestrictionsFound>None</ExportRestrictionsFound>
197194
<UsageRestrictionsFound>None</UsageRestrictionsFound>
198-
<AdditionalNotes>
199-
<![CDATA[]]></AdditionalNotes>
195+
<AdditionalNotes />
200196
</AssessmentSummary>
201-
<IrrelevantFiles>
202-
<Files>
203-
<![CDATA[]]></Files>
204-
<FileHash>
205-
<![CDATA[]]></FileHash>
206-
</IrrelevantFiles>
197+
<IrrelevantFiles />
207198
<ExternalIds />
208199
<Tags />
209-
<Comment>
210-
<![CDATA[]]></Comment>
200+
<Comment />
211201
</ComponentLicenseInformation>'''
212202

213203
self.delete_file(self.TESTFILE4)

0 commit comments

Comments
 (0)