Skip to content

Commit 30adcbd

Browse files
authored
[fwutil]: Fix component table layout. (#831)
Signed-off-by: Nazarii Hnydyn <[email protected]>
1 parent 6e3679b commit 30adcbd

File tree

1 file changed

+55
-78
lines changed

1 file changed

+55
-78
lines changed

fwutil/lib.py

Lines changed: 55 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ def get_status(self, force):
552552

553553
append_chassis_name = self.is_chassis_has_components()
554554
append_module_na = not self.is_modular_chassis()
555+
module_name = NA
555556

556557
for chassis_name, chassis_component_map in self.chassis_component_map.items():
557558
for chassis_component_name, chassis_component in chassis_component_map.items():
@@ -565,17 +566,6 @@ def get_status(self, force):
565566
status = self.FW_STATUS_UP_TO_DATE
566567
info = NA
567568

568-
if append_chassis_name:
569-
append_chassis_name = False
570-
else:
571-
chassis_name = EMPTY
572-
573-
if append_module_na:
574-
module_name = NA
575-
append_module_na = False
576-
else:
577-
module_name = EMPTY
578-
579569
if component:
580570
firmware_path = component[self.__pcp.FIRMWARE_KEY]
581571
firmware_version_available = component[self.__pcp.VERSION_KEY]
@@ -590,8 +580,8 @@ def get_status(self, force):
590580

591581
status_table.append(
592582
[
593-
chassis_name,
594-
module_name,
583+
chassis_name if append_chassis_name else EMPTY,
584+
module_name if append_module_na else EMPTY,
595585
chassis_component_name,
596586
firmware_path,
597587
firmware_version,
@@ -600,11 +590,19 @@ def get_status(self, force):
600590
]
601591
)
602592

593+
if append_chassis_name:
594+
append_chassis_name = False
595+
596+
if append_module_na:
597+
append_module_na = False
598+
603599
append_chassis_name = not self.is_chassis_has_components()
600+
chassis_name = self.chassis.get_name()
604601

605602
if self.is_modular_chassis():
606603
for module_name, module_component_map in self.module_component_map.items():
607604
append_module_name = True
605+
608606
for module_component_name, module_component in module_component_map.items():
609607
component = self.__pcp.module_component_map[module_name][module_component_name]
610608

@@ -616,17 +614,6 @@ def get_status(self, force):
616614
status = self.FW_STATUS_UP_TO_DATE
617615
info = NA
618616

619-
if append_chassis_name:
620-
chassis_name = self.chassis.get_name()
621-
append_chassis_name = False
622-
else:
623-
chassis_name = EMPTY
624-
625-
if append_module_name:
626-
append_module_name = False
627-
else:
628-
module_name = EMPTY
629-
630617
if component:
631618
firmware_path = component[self.__pcp.FIRMWARE_KEY]
632619
firmware_version_available = component[self.__pcp.VERSION_KEY]
@@ -641,8 +628,8 @@ def get_status(self, force):
641628

642629
status_table.append(
643630
[
644-
chassis_name,
645-
module_name,
631+
chassis_name if append_chassis_name else EMPTY,
632+
module_name if append_module_name else EMPTY,
646633
module_component_name,
647634
firmware_path,
648635
firmware_version,
@@ -651,13 +638,20 @@ def get_status(self, force):
651638
]
652639
)
653640

641+
if append_chassis_name:
642+
append_chassis_name = False
643+
644+
if append_module_name:
645+
append_module_name = False
646+
654647
return tabulate(status_table, self.STATUS_HEADER, tablefmt=self.FORMAT)
655648

656649
def update_firmware(self, force):
657650
status_table = [ ]
658651

659652
append_chassis_name = self.is_chassis_has_components()
660653
append_module_na = not self.is_modular_chassis()
654+
module_name = NA
661655

662656
for chassis_name, chassis_component_map in self.chassis_component_map.items():
663657
for chassis_component_name, chassis_component in chassis_component_map.items():
@@ -672,17 +666,6 @@ def update_firmware(self, force):
672666

673667
status = self.FW_STATUS_UP_TO_DATE
674668

675-
if append_chassis_name:
676-
append_chassis_name = False
677-
else:
678-
chassis_name = EMPTY
679-
680-
if append_module_na:
681-
module_name = NA
682-
append_module_na = False
683-
else:
684-
module_name = EMPTY
685-
686669
if component:
687670
firmware_path = component[self.__pcp.FIRMWARE_KEY]
688671
firmware_version_available = component[self.__pcp.VERSION_KEY]
@@ -712,14 +695,21 @@ def update_firmware(self, force):
712695

713696
status_table.append(
714697
[
715-
chassis_name,
716-
module_name,
698+
chassis_name if append_chassis_name else EMPTY,
699+
module_name if append_module_na else EMPTY,
717700
chassis_component_name,
718701
status,
719702
]
720703
)
721704

705+
if append_chassis_name:
706+
append_chassis_name = False
707+
708+
if append_module_na:
709+
append_module_na = False
710+
722711
append_chassis_name = not self.is_chassis_has_components()
712+
chassis_name = self.chassis.get_name()
723713

724714
if self.is_modular_chassis():
725715
for module_name, module_component_map in self.module_component_map.items():
@@ -738,17 +728,6 @@ def update_firmware(self, force):
738728

739729
status = self.FW_STATUS_UP_TO_DATE
740730

741-
if append_chassis_name:
742-
chassis_name = self.chassis.get_name()
743-
append_chassis_name = False
744-
else:
745-
chassis_name = EMPTY
746-
747-
if append_module_name:
748-
append_module_name = False
749-
else:
750-
module_name = EMPTY
751-
752731
if component:
753732
firmware_path = component[self.__pcp.FIRMWARE_KEY]
754733
firmware_version_available = component[self.__pcp.VERSION_KEY]
@@ -778,13 +757,19 @@ def update_firmware(self, force):
778757

779758
status_table.append(
780759
[
781-
chassis_name,
782-
module_name,
760+
chassis_name if append_chassis_name else EMPTY,
761+
module_name if append_module_name else EMPTY,
783762
module_component_name,
784763
status,
785764
]
786765
)
787766

767+
if append_chassis_name:
768+
append_chassis_name = False
769+
770+
if append_module_name:
771+
append_module_name = False
772+
788773
return tabulate(status_table, self.RESULT_HEADER, tablefmt=self.FORMAT)
789774

790775

@@ -803,34 +788,31 @@ def get_status(self):
803788

804789
append_chassis_name = self.is_chassis_has_components()
805790
append_module_na = not self.is_modular_chassis()
791+
module_name = NA
806792

807793
for chassis_name, chassis_component_map in self.chassis_component_map.items():
808794
for chassis_component_name, chassis_component in chassis_component_map.items():
809795
firmware_version = chassis_component.get_firmware_version()
810796
description = chassis_component.get_description()
811797

812-
if append_chassis_name:
813-
append_chassis_name = False
814-
else:
815-
chassis_name = EMPTY
816-
817-
if append_module_na:
818-
module_name = NA
819-
append_module_na = False
820-
else:
821-
module_name = EMPTY
822-
823798
status_table.append(
824799
[
825-
chassis_name,
826-
module_name,
800+
chassis_name if append_chassis_name else EMPTY,
801+
module_name if append_module_na else EMPTY,
827802
chassis_component_name,
828803
firmware_version,
829804
description
830805
]
831806
)
832807

808+
if append_chassis_name:
809+
append_chassis_name = False
810+
811+
if append_module_na:
812+
append_module_na = False
813+
833814
append_chassis_name = not self.is_chassis_has_components()
815+
chassis_name = self.chassis.get_name()
834816

835817
if self.is_modular_chassis():
836818
for module_name, module_component_map in self.module_component_map.items():
@@ -840,25 +822,20 @@ def get_status(self):
840822
firmware_version = module_component.get_firmware_version()
841823
description = module_component.get_description()
842824

843-
if append_chassis_name:
844-
chassis_name = self.chassis.get_name()
845-
append_chassis_name = False
846-
else:
847-
chassis_name = EMPTY
848-
849-
if append_module_name:
850-
append_module_name = False
851-
else:
852-
module_name = EMPTY
853-
854825
status_table.append(
855826
[
856-
chassis_name,
857-
module_name,
827+
chassis_name if append_chassis_name else EMPTY,
828+
module_name if append_module_name else EMPTY,
858829
module_component_name,
859830
firmware_version,
860831
description
861832
]
862833
)
863834

835+
if append_chassis_name:
836+
append_chassis_name = False
837+
838+
if append_module_name:
839+
append_module_name = False
840+
864841
return tabulate(status_table, self.HEADER, tablefmt=self.FORMAT)

0 commit comments

Comments
 (0)