Debian: sw-patch show implementation

This commit ensures that sw-patch show command gives details about
the contents of a Debian patch i.e. number of ostree commits,
the base commit on which the patch can be applied, and the commit
IDs that are associated with the patch.

Test:
sw-patch show <PATCH-ID>

Story: 2009969
Task: 45536
Signed-off-by: Jessica Castelino <jessica.castelino@windriver.com>
Change-Id: I1c7e48f299e566fea9c2ee4069a44580052df8f5
This commit is contained in:
Jessica Castelino 2022-06-02 22:02:03 +00:00
parent ee8a4edf4b
commit 9342be978b
2 changed files with 21 additions and 5 deletions

View File

@ -302,6 +302,7 @@ def print_patch_show_result(req):
if 'metadata' in data:
pd = data['metadata']
contents = data['contents']
for patch_id in sorted(list(pd)):
print("%s:" % patch_id)
@ -375,9 +376,21 @@ def print_patch_show_result(req):
print(' ' * 20 + req_patch)
if "contents" in data and patch_id in data["contents"]:
print(" Contents:")
for pkg in sorted(data["contents"][patch_id]):
print(' ' * 20 + pkg)
print(" Contents:\n")
if "number_of_commits" in contents[patch_id] and \
contents[patch_id]["number_of_commits"] != "":
print(textwrap.fill(" {0:<15} ".format("No. of commits:") +
contents[patch_id]["number_of_commits"],
width=TERM_WIDTH, subsequent_indent=' ' * 20))
if "base" in contents[patch_id] and \
contents[patch_id]["base"]["commit"] != "":
print(textwrap.fill(" {0:<15} ".format("Base commit:") +
contents[patch_id]["base"]["commit"],
width=TERM_WIDTH, subsequent_indent=' ' * 20))
for i in range(int(contents[patch_id]["number_of_commits"])):
print(textwrap.fill(" {0:<15} ".format("Commit%s:" % (i + 1)) +
contents[patch_id]["commit%s" % (i + 1)]["commit"],
width=TERM_WIDTH, subsequent_indent=' ' * 20))
print("\n")

View File

@ -1049,8 +1049,11 @@ class PatchController(PatchService):
LOG.exception("Failure during commit consistency check for %s.", patch_id)
if self.patch_data.contents[patch_id]["base"]["commit"] != latest_commit:
msg = "The base commit for %s do not match the latest commit " \
"on this system." % (patch_id)
msg = "The base commit %s for %s does not match the latest commit %s" \
"on this system." \
% (self.patch_data.contents[patch_id]["base"]["commit"],
patch_id,
latest_commit)
LOG.info(msg)
msg_info += msg + "\n"
continue