Schalter -use_local dazu. Keine Datenbankabfrage vom Server, wenn die Dateien schon da sind. EInige Attribute im config manager privatisiert. In die Logik auch die Abhängigkeit der comboboxen definiert. Controller ist jetzt ein Observer (der einzige)
This commit is contained in:
+47
-38
@@ -12,11 +12,11 @@ class JsonBasedConfig:
|
||||
"""Klasse mit generellen Methoden für alle Config Objekte mit json files"""
|
||||
def __init__(self, config_dir, config_file):
|
||||
"""merke dir den Pfad zu den Configdateien"""
|
||||
self.config_path = os.path.join(config_dir, config_file)
|
||||
self._config_path = os.path.join(config_dir, config_file)
|
||||
|
||||
def load_json_from_file(self):
|
||||
"""lade das json file vom gegeben Pfad in ein json Objekt"""
|
||||
with open(self.config_path, 'r', encoding='utf-8') as fh:
|
||||
with open(self._config_path, 'r', encoding='utf-8') as fh:
|
||||
return json.loads(fh.read())
|
||||
|
||||
def from_json(self, json_str):
|
||||
@@ -28,11 +28,11 @@ class CSVBasedConfig:
|
||||
|
||||
def __init__(self, config_dir, config_file):
|
||||
"""merke dir den Pfad zu den Configdateien"""
|
||||
self.config_path = os.path.join(config_dir, config_file)
|
||||
self._config_path = os.path.join(config_dir, config_file)
|
||||
|
||||
def load_csv_from_file(self):
|
||||
"""lade die csv aus dem angegebenen Dateipfad in ein Dataframe"""
|
||||
return pd.read_csv(self.config_path, sep=";", dtype="object")
|
||||
return pd.read_csv(self._config_path, sep=";", dtype="object")
|
||||
|
||||
|
||||
class SivasAssemblyData(JsonBasedConfig):
|
||||
@@ -135,16 +135,25 @@ class RuleDesignerDatabaseConfig(CSVBasedConfig):
|
||||
|
||||
class MigrationStatus:
|
||||
def __init__(self, file_dir, assembly_json):
|
||||
self.file_dir = file_dir
|
||||
self.assembly_json = assembly_json.replace(".json", "")
|
||||
self.sivas_assembly_data = SivasAssemblyData(file_dir, assembly_json)
|
||||
self.ruledesigner_data = RuleDesignerDatabaseConfig(file_dir)
|
||||
self._file_dir = file_dir
|
||||
self._assembly_json = assembly_json
|
||||
self._uselocal = False
|
||||
|
||||
def use_local(self):
|
||||
self._uselocal = True
|
||||
|
||||
def get_migration_status(self) -> dict:
|
||||
"""Gibt zurück, ob die Teilenummern der Baugruppe bereits migriert wurden, oder nicht"""
|
||||
update_database.get_sivas_dbase(sivas_id=self.assembly_json, out_dir=self.file_dir)
|
||||
update_database.get_rd_dbase()
|
||||
out_dir = self._file_dir
|
||||
if self._uselocal == False:
|
||||
update_database.get_sivas_dbase(self._assembly_json, out_dir)
|
||||
update_database.get_rd_dbase()
|
||||
else:
|
||||
if not os.path.exists(os.path.join(out_dir, self._assembly_json)):
|
||||
raise Exception("no local file exists "+ self._assembly_json)
|
||||
self.sivas_assembly_data = SivasAssemblyData(out_dir, self._assembly_json)
|
||||
sivas_assembly_ids = self.sivas_assembly_data.get_assembly_ids()
|
||||
self.ruledesigner_data = RuleDesignerDatabaseConfig(out_dir)
|
||||
ruledesigner_ids = self.ruledesigner_data.get_ruledesigner_ids()
|
||||
|
||||
migration_status = {}
|
||||
@@ -219,28 +228,28 @@ class MaterialTransConfig(JsonBasedConfig):
|
||||
"""Auslesen der Config zu allen Materialangaben"""
|
||||
|
||||
def __init__(self, config_dir='.', config_file='Materialübersetzung.json'):
|
||||
self.materials = None
|
||||
self._materials = None
|
||||
super().__init__(config_dir, config_file)
|
||||
|
||||
def from_json(self, json_str):
|
||||
"""lade den Json String zur Initialisierung des Objektes"""
|
||||
self.materials = super().from_json(json_str)
|
||||
self._materials = super().from_json(json_str)
|
||||
|
||||
def get_all_materials(self):
|
||||
"""hole alle Materialien, welche in der config Datei definiert sind"""
|
||||
|
||||
if not self.materials:
|
||||
self.materials = super().load_json_from_file()
|
||||
if not self._materials:
|
||||
self._materials = super().load_json_from_file()
|
||||
ret = list()
|
||||
for k in self.materials.keys():
|
||||
for k in self._materials.keys():
|
||||
ret.append(k)
|
||||
return ret
|
||||
|
||||
def get_material_of_type(self, mat):
|
||||
"""hole alle Materialien, welche in der config Datei definiert sind"""
|
||||
if not self.materials:
|
||||
if not self._materials:
|
||||
self.load_materials()
|
||||
return self.materials[mat]
|
||||
return self._materials[mat]
|
||||
|
||||
|
||||
|
||||
@@ -251,39 +260,39 @@ class IniBasedConfig:
|
||||
self.config_path = os.path.join(config_dir, config_file)
|
||||
if not os.path.exists(self.config_path):
|
||||
raise Exception("path does not exist")
|
||||
self.isInitalized = False
|
||||
self.config = ConfigParser(allow_no_value=True)
|
||||
self.config.optionxform = lambda option: option # preserve case for letters
|
||||
self._isInitalized = False
|
||||
self._config = ConfigParser(allow_no_value=True)
|
||||
self._config.optionxform = lambda option: option # preserve case for letters
|
||||
|
||||
def from_cfg_str(self, cfg_str):
|
||||
"""nimm den config String zur Initialisierung des Objektes"""
|
||||
self.config.read_string(cfg_str)
|
||||
self.isInitalized = True
|
||||
self._config.read_string(cfg_str)
|
||||
self._isInitalized = True
|
||||
|
||||
def load_cfg_from_file(self):
|
||||
"""lade das config file vom gegeben Pfad"""
|
||||
self.config.read(self.config_path, encoding='utf-8')
|
||||
self.isInitalized = True
|
||||
self._config.read(self.config_path, encoding='utf-8')
|
||||
self._isInitalized = True
|
||||
|
||||
def get_section_options(self, section_name):
|
||||
if not self.isInitalized:
|
||||
if not self._isInitalized:
|
||||
self.load_cfg_from_file()
|
||||
return self.config.options(section_name)
|
||||
return self._config.options(section_name)
|
||||
|
||||
def sections(self):
|
||||
if not self.isInitalized:
|
||||
if not self._isInitalized:
|
||||
self.load_cfg_from_file()
|
||||
return self.config.sections()
|
||||
return self._config.sections()
|
||||
|
||||
def get_int(self, section_name, option):
|
||||
if not self.isInitalized:
|
||||
if not self._isInitalized:
|
||||
self.load_cfg_from_file()
|
||||
return self.config.getint(section_name, option)
|
||||
return self._config.getint(section_name, option)
|
||||
|
||||
def get_dict(self, section_name):
|
||||
if not self.isInitalized:
|
||||
if not self._isInitalized:
|
||||
self.load_cfg_from_file()
|
||||
return dict(self.config.items(section_name))
|
||||
return dict(self._config.items(section_name))
|
||||
|
||||
class AllgemeinConfig(IniBasedConfig):
|
||||
"""Auslesen der Config für alle allgemeinen Angaben"""
|
||||
@@ -429,7 +438,7 @@ class PfadConfig(IniBasedConfig):
|
||||
class Configs:
|
||||
"""Sammlung aller Configdateien """
|
||||
def __init__(self, cfg_dir):
|
||||
self.cfg_dir = cfg_dir
|
||||
self._cfg_dir = cfg_dir
|
||||
self.Allgemein = AllgemeinConfig(cfg_dir)
|
||||
self.Bezeichner = BezeichnerConfig(cfg_dir)
|
||||
self.Farben = FarbenConfig(cfg_dir)
|
||||
@@ -442,16 +451,16 @@ class Configs:
|
||||
|
||||
self.TOSGruppen = TOSGroupsConfig(cfg_dir)
|
||||
self.Materialien = MaterialTransConfig(cfg_dir)
|
||||
self.env = None
|
||||
self._env = None
|
||||
|
||||
def get_cfg_path(self):
|
||||
return self.cfg_dir
|
||||
return self._cfg_dir
|
||||
|
||||
def set_env(self, env):
|
||||
self.env = env
|
||||
self._env = env
|
||||
|
||||
def get_env(self):
|
||||
if self.env:
|
||||
return self.env
|
||||
if self._env:
|
||||
return self._env
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user