Fix filter() usage for Py 3
The use of filter() within the codebase expected the output to be an interator, but the filter function in Python 3 now returns a lazy loading generator and resulted in stack traces. This commit replaces the use of filter() (+ lambdas) with more readable list comprehension to be compatible with Python 2 and 3. Change-Id: I56af1dc1f6648ec334f901cb59893240b0125031
This commit is contained in:
parent
d73912d385
commit
5f297e0079
|
@ -120,7 +120,7 @@ class CopyClusterTemplate(create_flow.ConfigureClusterTemplate):
|
||||||
values = dict()
|
values = dict()
|
||||||
for i, choice in enumerate(choices):
|
for i, choice in enumerate(choices):
|
||||||
share_id = choice[0]
|
share_id = choice[0]
|
||||||
s = filter(lambda s: s['id'] == share_id, self.template.shares)
|
s = [s for s in self.template.shares if s['id'] == share_id]
|
||||||
if len(s) > 0:
|
if len(s) > 0:
|
||||||
path = s[0]["path"] if "path" in s[0] else ""
|
path = s[0]["path"] if "path" in s[0] else ""
|
||||||
values["share_id_{0}".format(i)] = {
|
values["share_id_{0}".format(i)] = {
|
||||||
|
|
|
@ -53,7 +53,7 @@ class SelectSharesAction(workflows.Action):
|
||||||
choices = share_field.choices
|
choices = share_field.choices
|
||||||
for i, choice in enumerate(choices):
|
for i, choice in enumerate(choices):
|
||||||
share_id = choice[0]
|
share_id = choice[0]
|
||||||
s = filter(lambda s: s['id'] == share_id, cluster_shares)
|
s = [s for s in cluster_shares if s['id'] == share_id]
|
||||||
if len(s) > 0:
|
if len(s) > 0:
|
||||||
path = s[0]["path"] if "path" in s[0] else ""
|
path = s[0]["path"] if "path" in s[0] else ""
|
||||||
values["share_id_{0}".format(i)] = {
|
values["share_id_{0}".format(i)] = {
|
||||||
|
|
|
@ -130,7 +130,7 @@ class CopyNodegroupTemplate(create_flow.ConfigureNodegroupTemplate):
|
||||||
choices = share_fields['shares'].choices
|
choices = share_fields['shares'].choices
|
||||||
for i, choice in enumerate(choices):
|
for i, choice in enumerate(choices):
|
||||||
share_id = choice[0]
|
share_id = choice[0]
|
||||||
s = filter(lambda s: s['id'] == share_id, self.template.shares)
|
s = [s for s in self.template.shares if s['id'] == share_id]
|
||||||
if len(s) > 0:
|
if len(s) > 0:
|
||||||
path = s[0].get('path', '')
|
path = s[0].get('path', '')
|
||||||
values["share_id_{0}".format(i)] = {
|
values["share_id_{0}".format(i)] = {
|
||||||
|
|
|
@ -251,8 +251,8 @@ def populate_image_choices(self, request, context, empty_choice=False):
|
||||||
|
|
||||||
class PluginAndVersionMixin(object):
|
class PluginAndVersionMixin(object):
|
||||||
def _generate_plugin_version_fields(self, sahara):
|
def _generate_plugin_version_fields(self, sahara):
|
||||||
plugins = sahara.plugins.list()
|
plugins = [p for p in sahara.plugins.list()
|
||||||
plugins = filter(is_plugin_not_hidden_for_user, plugins)
|
if is_plugin_not_hidden_for_user(p)]
|
||||||
plugin_choices = [(plugin.name, plugin.title) for plugin in plugins]
|
plugin_choices = [(plugin.name, plugin.title) for plugin in plugins]
|
||||||
|
|
||||||
self.fields["plugin_name"] = forms.ChoiceField(
|
self.fields["plugin_name"] = forms.ChoiceField(
|
||||||
|
|
Loading…
Reference in New Issue