Skip to content

Commit

Permalink
Sort the unit list before returning it
Browse files Browse the repository at this point in the history
Sort the unit list by id/template-id before printing it out. In
addition, sort the keys inside each JSON record for easier comparison.
  • Loading branch information
pieqq committed Mar 20, 2024
1 parent 8f31fe8 commit 8fa2195
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions checkbox-ng/checkbox_ng/launcher/subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ def invoked(self, ctx):
[tp.get_mandatory_qualifier()] + [tp.get_qualifier()],
)

list_obj = []
obj_list = []
for unit in jobs_and_templates_list:
obj = unit._raw_data.copy()
obj["unit"] = unit.unit
Expand All @@ -1330,11 +1330,12 @@ def invoked(self, ctx):
] = self.get_effective_certification_status(unit)
if unit.template_id:
obj["template-id"] = unit.template_id
list_obj.append(obj)
obj_list.append(obj)
obj_list.sort(key=lambda x: x.get("template-id", x["id"]))
if ctx.args.format == "json":
print(json.dumps(list_obj))
print(json.dumps(obj_list, sort_keys=True))
else:
for obj in list_obj:
for obj in obj_list:
if obj["unit"] == "template":
print("Template '{}'".format(obj["template-id"]))
else:
Expand Down

0 comments on commit 8fa2195

Please sign in to comment.