Klasse für TOS Config und alle zukünftigen in eigene Datei manage_configs ausgelagert
This commit is contained in:
+3
-56
@@ -1,6 +1,6 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import json
|
import manage_configs
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Dieses Programm erzeugt aus den Angaben in der config TOS-Gruppen.json einen Export String zur Pflege des TOS im Ruledesigner Fusion
|
Dieses Programm erzeugt aus den Angaben in der config TOS-Gruppen.json einen Export String zur Pflege des TOS im Ruledesigner Fusion
|
||||||
@@ -14,63 +14,10 @@ Codebereich liegt bei Calk Link 10
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class TOSGroupsConfig:
|
|
||||||
"""Auslesen der Config Angaben zu den TOS Gruppen"""
|
|
||||||
|
|
||||||
config_dir = os.environ.get('CREMIG_CFG')
|
|
||||||
config_path = os.path.join(config_dir, 'TOS-Gruppen.json')
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.tos_hierarchy = None
|
|
||||||
|
|
||||||
def get_children_keys(self, tos_hierarchy, currentId, result):
|
|
||||||
# wenn eine Referenz nicht weiter in der TOS Hierarchy vorkommt, dann nicht mit einsammeln
|
|
||||||
if currentId not in tos_hierarchy:
|
|
||||||
return None
|
|
||||||
childIds = tos_hierarchy[currentId]["reference-ids"].values()
|
|
||||||
level = tos_hierarchy[currentId]["TOS-level"]
|
|
||||||
if len(childIds) > 0:
|
|
||||||
for cId in childIds:
|
|
||||||
# prüfen, ob die Referenz sonst noch verwendet wird
|
|
||||||
if cId in tos_hierarchy:
|
|
||||||
result[cId] = level
|
|
||||||
for cId in childIds:
|
|
||||||
self.get_children_keys(tos_hierarchy, cId, result)
|
|
||||||
|
|
||||||
def get_all_keywords(self):
|
|
||||||
"""hole alle TOS Keywords, welche in der config Datei definiert sind"""
|
|
||||||
|
|
||||||
# lazy. nur einmal laden, wenn noch nicht geschehen
|
|
||||||
if not self.tos_hierarchy:
|
|
||||||
self.load_tos_hierarchy()
|
|
||||||
|
|
||||||
# beginne mit root als ersten, vordefiniertem Keyword
|
|
||||||
rootid = self.tos_hierarchy["root"]
|
|
||||||
# und von dort aus folge dann allen Referenzen
|
|
||||||
result = dict()
|
|
||||||
# root als Nullte Ebene dazu
|
|
||||||
result[rootid] = 0
|
|
||||||
self.get_children_keys(self.tos_hierarchy, rootid, result)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def get_keywords_of_level(self, allKeywords, levelnum):
|
|
||||||
"""hole alle TOS Keywords der gegebenen Hierarchiestufe "levelnum" """
|
|
||||||
ret = list()
|
|
||||||
for kw in allKeywords:
|
|
||||||
if allKeywords[kw] == levelnum:
|
|
||||||
ret.append(kw)
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def load_tos_hierarchy(self):
|
|
||||||
"""lade die gegebenen Hierarchy aus dem Config File in eine json Objekt"""
|
|
||||||
with open(self.config_path, 'r', encoding='utf-8') as fh:
|
|
||||||
self.tos_hierarchy = json.loads(fh.read())
|
|
||||||
|
|
||||||
|
|
||||||
def create_tos_string():
|
def create_tos_string():
|
||||||
|
|
||||||
TOS_CFG = TOSGroupsConfig()
|
# hole die json Datei mit den Angaben zu allen TOS Gruppen in eine lokale Config Klasse
|
||||||
|
TOS_CFG = manage_configs.TOSGroupsConfig()
|
||||||
|
|
||||||
allKeywords = TOS_CFG.get_all_keywords()
|
allKeywords = TOS_CFG.get_all_keywords()
|
||||||
myIds = list()
|
myIds = list()
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
"""
|
||||||
|
Diese Lib verwaltet alle Config dateien (als .cfg oder als .json) von CreoMigrate
|
||||||
|
"""
|
||||||
|
|
||||||
|
class TOSGroupsConfig:
|
||||||
|
"""Auslesen der Config Angaben zu den TOS Gruppen"""
|
||||||
|
|
||||||
|
config_dir = os.environ.get('CREMIG_CFG')
|
||||||
|
config_path = os.path.join(config_dir, 'TOS-Gruppen.json')
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.tos_hierarchy = None
|
||||||
|
|
||||||
|
def get_children_keys(self, tos_hierarchy, currentId, result):
|
||||||
|
# wenn eine Referenz nicht weiter in der TOS Hierarchy vorkommt, dann nicht mit einsammeln
|
||||||
|
if currentId not in tos_hierarchy:
|
||||||
|
return None
|
||||||
|
childIds = tos_hierarchy[currentId]["reference-ids"].values()
|
||||||
|
level = tos_hierarchy[currentId]["TOS-level"]
|
||||||
|
if len(childIds) > 0:
|
||||||
|
for cId in childIds:
|
||||||
|
# prüfen, ob die Referenz sonst noch verwendet wird
|
||||||
|
if cId in tos_hierarchy:
|
||||||
|
result[cId] = level
|
||||||
|
for cId in childIds:
|
||||||
|
self.get_children_keys(tos_hierarchy, cId, result)
|
||||||
|
|
||||||
|
def get_all_keywords(self):
|
||||||
|
"""hole alle TOS Keywords, welche in der config Datei definiert sind"""
|
||||||
|
|
||||||
|
# lazy. nur einmal laden, wenn noch nicht geschehen
|
||||||
|
if not self.tos_hierarchy:
|
||||||
|
self.load_tos_hierarchy()
|
||||||
|
|
||||||
|
# beginne mit root als ersten, vordefiniertem Keyword
|
||||||
|
rootid = self.tos_hierarchy["root"]
|
||||||
|
# und von dort aus folge dann allen Referenzen
|
||||||
|
result = dict()
|
||||||
|
# root als Nullte Ebene dazu
|
||||||
|
result[rootid] = 0
|
||||||
|
self.get_children_keys(self.tos_hierarchy, rootid, result)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def get_keywords_of_level(self, allKeywords, levelnum):
|
||||||
|
"""hole alle TOS Keywords der gegebenen Hierarchiestufe "levelnum" """
|
||||||
|
ret = list()
|
||||||
|
for kw in allKeywords:
|
||||||
|
if allKeywords[kw] == levelnum:
|
||||||
|
ret.append(kw)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def load_tos_hierarchy(self):
|
||||||
|
"""lade die gegebenen Hierarchy aus dem Config File in eine json Objekt"""
|
||||||
|
with open(self.config_path, 'r', encoding='utf-8') as fh:
|
||||||
|
self.tos_hierarchy = json.loads(fh.read())
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user