From efef1936126505b4487c4aa49e45570d6d85ba99 Mon Sep 17 00:00:00 2001 From: Simon Steuer Date: Mon, 14 Apr 2025 21:47:13 +0200 Subject: [PATCH] =?UTF-8?q?FIX=20-=20Die=20Metadaten-CSV=20von=20Teilenumm?= =?UTF-8?q?ern=20mit=20Leerzeichen,=20z.B.=20'TOS=20Auswahl=20FGN'=20wurde?= =?UTF-8?q?=20bisher=20nicht=20abgeleitet.=20Dies=20funktioniert=20nun.=20?= =?UTF-8?q?Zudem=20Denesting=20durchgef=C3=BChrt=20und=20spezifischere=20E?= =?UTF-8?q?rror-Checks=20eingebaut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/update_database.py | 46 +++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/lib/update_database.py b/lib/update_database.py index db4da19..753f23b 100644 --- a/lib/update_database.py +++ b/lib/update_database.py @@ -90,43 +90,29 @@ def get_sivas_teilestamm(sivas_ids, out_dir=os.environ.get('CREMIG_DATA'), overw """call the sivas exe for getting all csv files with the item data for the given sivas ids""" sivas_teilestamm_exe = os.environ.get('SIVAS_TEILESTAMM') + if not os.path.isfile(sivas_teilestamm_exe): + raise FileNotFoundError(f"Check VPN connection or path of %SIVAS_DATABASE_QUERY% in cremig_setenv.bat") + + if not os.path.isdir(out_dir): + raise NotADirectoryError(f"Output directory for .csv-file(s) ${out_dir} doesn't exist.") if isinstance(sivas_ids, str): sivas_ids = list(set(sivas_ids.strip().split(","))) - + ids_to_generate = [] for id in sivas_ids: - id = id.replace(" ", "") - if not overwrite: - out_file = os.path.join(out_dir, id + ".csv") - if not os.path.isfile(out_file): - ids_to_generate.append(id) - continue - else: - ids_to_generate.append(id) - - if not id.isnumeric(): - print(f"Partnumber '{id}' contains invalid characters. Please check given partnumber. Multiple partnumbers have to be specified as comma separated values without space, e.g. 200000089,200000090") - + out_file = os.path.join(out_dir, id + ".csv") + if not overwrite and os.path.isfile(out_file): + continue + ids_to_generate.append(f'"{id}"') # Anführungszeichen erforderlich, damit Art.Nr. mit Leerzeichen, z.B. "TOS Auswahl ILS" funktionieren - if os.path.isfile(sivas_teilestamm_exe): - - if os.path.isdir(out_dir): + if len(ids_to_generate) == 0: + print("CSV-file(s) already exist or given partnumber(s) are migrated.") + return - if len(ids_to_generate) == 0: - print("CSV-file(s) already exist or given partnumber(s) are migrated.") - return - - else: - print(f"Attempting to generate csv-file(s) for given partnumber(s)...") - - ids_to_generate = ",".join(ids_to_generate) - os.environ["SIVAS_EXCEL_EXPORT_DIR"] = out_dir - subprocess.run(f"{sivas_teilestamm_exe} -teilenr={ids_to_generate} -open_target_dir=n") - else: - print(f"Output directory for .csv-file(s) ${out_dir} doesn't exist.") - else: - print(f"Can't execute SIVAS-database query. Check VPN connection or check the path of %SIVAS_DATABASE_QUERY% in cremig_setenv.bat") + ids_to_generate = ",".join(ids_to_generate) + os.environ["SIVAS_EXCEL_EXPORT_DIR"] = out_dir + subprocess.run(f'{sivas_teilestamm_exe} -teilenr={ids_to_generate} -open_target_dir=n') if __name__ == '__main__':