Fix software list order

Currently the 'software list' output may show strange
order of the releases, such as:

$ software list
+------------------+-------+-----------+
| Release          | RR    |   State   |
+------------------+-------+-----------+
| STX-8.0          | True  | deployed  |
| STX-10.1         | True  | available |
| STX_8_PATCH_0001 | True  | deployed  |
| STX_8_PATCH_0002 | True  | deployed  |
| STX_8_PATCH_0003 | True  | deployed  |
| STX_8_PATCH_0004 | True  | deployed  |
| STX_8_PATCH_0005 | True  | deployed  |
| STX_8_PATCH_0006 | False | deployed  |
+------------------+-------+-----------+

This commit fixes the release order, showing from the
oldest (top) to the newest (bottom):

$ software list
+------------------+-------+-----------+
| Release          | RR    |   State   |
+------------------+-------+-----------+
| STX-8.0          | True  | deployed  |
| STX_8_PATCH_0001 | True  | deployed  |
| STX_8_PATCH_0002 | True  | deployed  |
| STX_8_PATCH_0003 | True  | deployed  |
| STX_8_PATCH_0004 | True  | deployed  |
| STX_8_PATCH_0005 | True  | deployed  |
| STX_8_PATCH_0006 | False | deployed  |
| STX-10.1         | True  | deploying |
+------------------+-------+-----------+

Test Plan
PASS: run software list and verify the output shows the
      new order

Story: 2010676
Task: 51540

Change-Id: I517de30cdc3383654e332303fbc0036836a6114a
Signed-off-by: Heitor Matsui <heitorvieira.matsui@windriver.com>
This commit is contained in:
Heitor Matsui 2025-01-10 15:50:28 -03:00
parent cc6f01639b
commit 62812a6cec

View File

@ -28,7 +28,9 @@ def do_list(cc, args):
rc = utils.check_rc(resp, data)
if rc == 0:
header_data_list = {"Release": "release_id", "RR": "reboot_required", "State": "state"}
utils.display_result_list(header_data_list, data)
sorted_data = sorted(data, key=lambda x: x['release_id'].translate(
dict.fromkeys(map(ord, "-_."), "-")))
utils.display_result_list(header_data_list, sorted_data)
else:
utils.display_info(resp)