From 750c71fb5a9fcf4a30af0700b7a09e3501988a27 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Wed, 7 Apr 2021 09:07:29 +0200 Subject: [PATCH] Minor refactoring and remove code duplication --- cdist/config.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cdist/config.py b/cdist/config.py index f7da9b1d..638fdf0e 100644 --- a/cdist/config.py +++ b/cdist/config.py @@ -699,20 +699,22 @@ class Config: check for cycles. ''' graph = {} - for cdist_object in self.object_list(): + + def _add_requirements(cdist_object, requirements): obj_name = cdist_object.name if obj_name not in graph: graph[obj_name] = [] + + for requirement in cdist_object.requirements_unfinished( + requirements): + graph[obj_name].append(requirement.name) + + for cdist_object in self.object_list(): if cdist_object.state == cdist_object.STATE_DONE: continue - for requirement in cdist_object.requirements_unfinished( - cdist_object.requirements): - graph[obj_name].append(requirement.name) - - for requirement in cdist_object.requirements_unfinished( - cdist_object.autorequire): - graph[obj_name].append(requirement.name) + _add_requirements(cdist_object, cdist_object.requirements) + _add_requirements(cdist_object, cdist_object.autorequire) return graph_check_cycle(graph) def iterate_until_finished(self):