From eff9cb7b292648dd342b429a1d31941143c193f5 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Mon, 18 Sep 2023 21:09:11 +0100 Subject: [PATCH] trivial: Print the idenities with the entities and links indented --- uswid/cli.py | 8 ++++++-- uswid/identity.py | 4 ++-- uswid/test_uswid.py | 15 ++++++++------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/uswid/cli.py b/uswid/cli.py index 54fab0b..3a5adf2 100755 --- a/uswid/cli.py +++ b/uswid/cli.py @@ -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) diff --git a/uswid/identity.py b/uswid/identity.py index 558f95d..1c7b085 100644 --- a/uswid/identity.py +++ b/uswid/identity.py @@ -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 diff --git a/uswid/test_uswid.py b/uswid/test_uswid.py index 45f0258..b42369f 100644 --- a/uswid/test_uswid.py +++ b/uswid/test_uswid.py @@ -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 @@ -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, @@ -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