Skip to content

Instantly share code, notes, and snippets.

@adam-stokes
Created March 18, 2015 19:26
Show Gist options
  • Save adam-stokes/94dd3787372c72d37c41 to your computer and use it in GitHub Desktop.
Save adam-stokes/94dd3787372c72d37c41 to your computer and use it in GitHub Desktop.
def update(self):
for cc in self.controller.charm_classes():
if self.machine:
if not satisfies(self.machine, cc.constraints)[0] \
or not self.controller.is_assigned(cc, self.machine):
self.remove_service_widget(cc)
continue
if self.unplaced_only:
n_units = self.controller.machine_count_for_charm(cc)
if n_units == cc.required_num_units() \
and cc not in self.controller.unplaced_services:
self.remove_service_widget(cc)
continue
is_required = self.controller.get_charm_state(cc)[0]
print(is_required)
if self.show_type == 'required':
if is_required[0] != CharmState.REQUIRED:
self.remove_service_widget(cc)
continue
elif self.show_type == 'non-required':
if is_required[0] == CharmState.REQUIRED:
self.remove_service_widget(cc)
continue
if not cc.allow_multi_units and \
cc not in self.controller.unplaced_services:
self.remove_service_widget(cc)
continue
sw = self.find_service_widget(cc)
if sw is None:
sw = self.add_service_widget(cc)
sw.update()
@mikemccracken
Copy link

in line 17 you're getting just the state from the tuple with the [0] at the end, then in line 20 you're trying to subscript a CharmState enum. you only need one of those subsets. (same issue with 24 as 20)

@mikemccracken
Copy link

also I'd rename 'is_required' to 'state', since it isn't a bool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment