Skip to content

Commit 8c538fa

Browse files
optimized the sort_loops in module.py and also improved readability (#1150)
Co-authored-by: Sam Stepanyan <[email protected]>
1 parent e2b4d7c commit 8c538fa

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

nettacker/core/module.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,25 @@ def generate_loops(self):
118118
self.module_content["payloads"] = expand_module_steps(self.module_content["payloads"])
119119

120120
def sort_loops(self):
121-
steps = []
122121
for index in range(len(self.module_content["payloads"])):
123-
for step in copy.deepcopy(self.module_content["payloads"][index]["steps"]):
124-
if "dependent_on_temp_event" not in step[0]["response"]:
125-
steps.append(step)
122+
steps_without_dependencies = []
123+
steps_with_temp_dependencies = []
124+
steps_with_normal_dependencies = []
126125

127126
for step in copy.deepcopy(self.module_content["payloads"][index]["steps"]):
128-
if (
129-
"dependent_on_temp_event" in step[0]["response"]
130-
and "save_to_temp_events_only" in step[0]["response"]
131-
):
132-
steps.append(step)
127+
resp = step[0]["response"]
128+
if "dependent_on_temp_event" not in resp:
129+
steps_without_dependencies.append(step)
130+
elif "save_to_temp_events_only" in resp:
131+
steps_with_temp_dependencies.append(step)
132+
else:
133+
steps_with_normal_dependencies.append(step)
133134

134-
for step in copy.deepcopy(self.module_content["payloads"][index]["steps"]):
135-
if (
136-
"dependent_on_temp_event" in step[0]["response"]
137-
and "save_to_temp_events_only" not in step[0]["response"]
138-
):
139-
steps.append(step)
140-
self.module_content["payloads"][index]["steps"] = steps
135+
self.module_content["payloads"][index]["steps"] = (
136+
steps_without_dependencies
137+
+ steps_with_temp_dependencies
138+
+ steps_with_normal_dependencies
139+
)
141140

142141
def start(self):
143142
active_threads = []

0 commit comments

Comments
 (0)