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__':