89 lines
2.9 KiB
Python
89 lines
2.9 KiB
Python
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())
|
|
|
|
|
|
class MaterialConfig:
|
|
"""Auslesen der Config Angaben zu allen Materialangaben"""
|
|
|
|
config_dir = os.environ.get('CREMIG_CFG')
|
|
config_path = os.path.join(config_dir, 'Materialübersetzung.json')
|
|
|
|
def __init__(self):
|
|
self.materials = None
|
|
|
|
def load_materials(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.materials = json.loads(fh.read())
|
|
|
|
def get_all_materials(self):
|
|
"""hole alle Materialien, welche in der config Datei definiert sind"""
|
|
|
|
if not self.materials:
|
|
self.load_materials()
|
|
ret = list()
|
|
for k in self.materials.keys():
|
|
ret.append(k)
|
|
return ret
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
pass |