From 77112199be91e3fc95a2e5fea9edd65bd1aad1f9 Mon Sep 17 00:00:00 2001 From: "SLW\\ARNAUA" Date: Thu, 20 Jan 2022 14:49:25 +0100 Subject: [PATCH] resourceName used to create folders and management_zones used to compare. --- adapter.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/adapter.py b/adapter.py index 914365c..dc8fed7 100644 --- a/adapter.py +++ b/adapter.py @@ -49,30 +49,31 @@ def createFolderStructure(): # [AA 2022.01.20] Create direcotires and copy associated files resourcePath = os.path.join(outputFolder + environment + "/", resourceName) - if not resourcePath in resourcePaths.keys(): - resourcePaths.setdefault("resourcePaths", []) - resourcePaths["resourcePaths"].append(resourcePath) + # if not resourcePath in resourcePaths.keys(): + # resourcePaths.setdefault("resourcePaths", []) + # resourcePaths["resourcePaths"].append(resourcePath) createDir(resourcePath) copyFile(file, os.path.join(resourcePath, os.path.basename(file))) - return resourcePaths + return management_zones def filterCondition(filename): return '/dashboards/' in filename or '/alerting_profiles/' in filename; #'/dashboards/' in filename or -def fillOtherResources(resourcePaths): +def fillOtherResources(management_zones): otherResources = [os.path.normpath(f).replace('\\', '/') for f in glob(sourceFolder + "**/**.tf", recursive=True)] otherResources_iterator= filter(filterCondition, otherResources) otherResource_filterd=list(otherResources_iterator) - for resourcePath in resourcePaths["resourcePaths"]: + for management_zone in management_zones: for element in otherResource_filterd: elementName = os.path.basename(element).split(".")[0].split(" ")[0] - resourceName = os.path.basename(resourcePath) - if elementName == resourceName: - copyFile("./" + element, resourcePath + "/" + os.path.basename(element)) - print("[DEBUG]", "File %s copied to %s." % (os.path.basename(element), resourcePath)) + management_zone_name = os.path.basename(management_zone).split(".")[0].split(" ")[0] + folder = os.path.dirname(os.path.dirname(management_zone)).replace("export","") + if elementName == management_zone_name: + copyFile("./" + element, "./output" + folder + "/" + os.path.basename(element)) + print("[DEBUG]", "File %s copied to %s." % (os.path.basename(element), "./output" + folder + "/" + os.path.basename(element))) # [AA, EW 2022.01.20] Set global variables