Skip to content

Commit

Permalink
trivial: Print the idenities with the entities and links indented
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsie committed Sep 18, 2023
1 parent b59eecd commit eff9cb7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
8 changes: 6 additions & 2 deletions uswid/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,15 @@ def main():
sys.exit(1)
# debug
if load_filepaths and args.verbose:
print("Loaded:\n{}".format(container))
print("Loaded:")
for identity in container:
print(f"{identity}")

# optional save
if save_filepaths and args.verbose:
print("Saving:\n{}".format(container))
print("Saving:")
for identity in container:
print(f"{identity}")
for filepath in save_filepaths:
try:
fmt = _detect_format(filepath)
Expand Down
4 changes: 2 additions & 2 deletions uswid/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ def __repr__(self) -> str:
tmp += ":"
if self._links:
tmp += "\n{}".format(
"\n".join([str(e) for e in self._links.values()]),
"\n".join([f" - {str(e)}" for e in self._links.values()]),
)
if self._entities:
tmp += "\n{}".format(
"\n".join([str(e) for e in self._entities.values()]),
"\n".join([f" - {str(e)}" for e in self._entities.values()]),
)
return tmp
15 changes: 8 additions & 7 deletions uswid/test_uswid.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def test_identity(self):
identity.add_entity(entity)
self.assertEqual(
str(identity),
"uSwidIdentity(foobarbaz,5,foo,1.2.3):\nuSwidEntity(test,example.com->MAINTAINER)",
"uSwidIdentity(foobarbaz,5,foo,1.2.3):\n"
" - uSwidEntity(test,example.com->MAINTAINER)",
)

# SWID XML import
Expand All @@ -176,9 +177,9 @@ def test_identity(self):
self.assertEqual(
str(identity),
"uSwidIdentity(acbd84ff-9898-4922-8ade-dd4bbe2e40ba,1,DellBiosConnectNetwork,1.5.2):\n"
"uSwidLink(http://hughsie.com,see-also)\n"
"uSwidLink(www.gnu.org/licenses/gpl.txt,license)\n"
"uSwidEntity(Dell Technologies,dell.com->SOFTWARE_CREATOR,TAG_CREATOR)",
" - uSwidLink(http://hughsie.com,see-also)\n"
" - uSwidLink(www.gnu.org/licenses/gpl.txt,license)\n"
" - uSwidEntity(Dell Technologies,dell.com->SOFTWARE_CREATOR,TAG_CREATOR)",
)
self.assertEqual(
identity.summary,
Expand Down Expand Up @@ -214,9 +215,9 @@ def test_identity(self):
self.assertEqual(
str(identity),
"uSwidIdentity(acbd84ff-9898-4922-8ade-dd4bbe2e40ba,1,HughskiColorHug.efi,1.0.0):\n"
"uSwidLink(https://hughski.com/,see-also)\n"
"uSwidEntity(Richard Hughes,hughsie.com->TAG_CREATOR)\n"
"uSwidEntity(Hughski Limited,hughski.com->AGGREGATOR)",
" - uSwidLink(https://hughski.com/,see-also)\n"
" - uSwidEntity(Richard Hughes,hughsie.com->TAG_CREATOR)\n"
" - uSwidEntity(Hughski Limited,hughski.com->AGGREGATOR)",
)

# INI export
Expand Down

0 comments on commit eff9cb7

Please sign in to comment.