From 1576d9c372a5e1d95a08924305a0c16f5dbb6fa2 Mon Sep 17 00:00:00 2001 From: "s.steuer" Date: Sun, 5 Nov 2023 23:29:02 +0100 Subject: [PATCH] =?UTF-8?q?Keine=20direkten=20funktionalen=20=C3=84nderung?= =?UTF-8?q?en=20vorgenommen.=20Vor=20allem=20Errorhandling=20erweitert=20u?= =?UTF-8?q?nd=20Code=20an=20PEP8=20angepasst.=20Zudem=20Anpassungen=20von?= =?UTF-8?q?=20Umgebungsvariablen=20in=20cremig=5Fsetenv.bat=20in=20diese?= =?UTF-8?q?=20Datei=20=C3=BCbernommen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/update_database.py | 81 +++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/lib/update_database.py b/lib/update_database.py index 4c0cc09..893af4c 100644 --- a/lib/update_database.py +++ b/lib/update_database.py @@ -2,43 +2,52 @@ import argparse import os import shutil import subprocess -# import configparser -# import json """ -Dieses Programm holt sich aus -- RD Fusion eine aktuellen Stand der exisitierenden IDS -- Sivas eine Liste der gewünschten Teile - +Dieses Programm: +- Kopiert die CSV-Datei mit allen RuleDesigner-Nummern +- Fragt Sivas ab und generiert dabei eine json-Datei, in der alle Teilenummern aufgelistet sind, + die in Verbindung mit einer angegebenen Teilenummer migriert werden müssen. """ -def get_rd_database(inPath, outDir, outFileName): - if os.path.isfile(inPath): - outFilePath = os.path.join(outDir, outFileName) - if os.path.isdir(outDir): - shutil.copyfile(inPath, outFilePath) - else: - print(f"no such directory ${outDir} of env CREMIG_DATA") - print("done") - else: - print(f"no such file ${inPath} of environment variable RD_DATABASE_SOURCE. have a look at cremig_setenv.bat") +def get_rd_dbase(out_dir): + rd_csv_source_dir = os.environ.get('RD_DATABASE_SOURCE') + rd_csv_filename = os.environ.get('RD_DATABASE_NAME') + csv_source_filepath = os.path.join(rd_csv_source_dir, rd_csv_filename) -def get_sivas_databse(exePath, sivasId, outFilePath): - if os.path.isfile(exePath): - - if os.path.isdir(outDir): - #subprocess.Popen([exePath, "-o", outDir, "--format json", "-number", sivasId ]) - cmd = ' '.join([exePath, "-o", outDir, "--format json", "-number", sivasId ]) - os.system(cmd) - else: - print(f"no such executable ${outDir} of env CREMIG_DATA") - if os.path.isfile(outFilePath): + if os.path.isfile(csv_source_filepath): + csv_out_filepath = os.path.join(out_dir, rd_csv_filename) + + if os.path.isdir(out_dir): + print("Copying CSV-file of RuleDesigner database...") + shutil.copyfile(rd_csv_source_dir, csv_out_filepath) print("done") else: - print("failure - did not get .json file") + print(f"Can't copy RuleDesigner-database, because output directory ${out_dir} doesn't exist. Check path of %CREMIG_DATA% in cremig_setenv.bat") else: - print(f"no such file ${exePath} of environment variable SIVAS_DATABASE_QUERY. have a look at cremig_setenv.bat") + print(f"no such file ${rd_csv_source_dir} of environment variable RD_DATABASE_SOURCE. Check cremig_setenv.bat") + + +def get_sivas_dbase(sivas_id, out_dir): + sivas_exe_path = os.environ.get('SIVAS_DATABASE_QUERY') + + if os.path.isfile(sivas_exe_path): + + if os.path.isdir(out_dir): + print(f"Attempting to generate a json-file of all parts to be migrated in relation with '{sivas_id}'") + subprocess.run(f"{sivas_exe_path} -o {out_dir} --format json -number {sivas_id}") + + if os.path.isfile(os.path.join(out_dir, sivas_id + ".json")): + print("done") + else: + print(f"Failure - Couldn't generate {sivas_id}.json. Check for any spelling/typing errors. Otherwise given number is a part without a BOM.") + exit() + else: + print(f"'Output directory for .json-file {out_dir}' doesn't exist.") + else: + print(f"Can't execute SIVAS-database query. Check if you have established a VPN connection to the company's network and check the path of %SIVAS_DATABASE_QUERY% in cremig_setenv.bat") + if __name__ == '__main__': parser = argparse.ArgumentParser(description='fetches data from sivas or ruledesigner fusion', prog='update_database') @@ -47,15 +56,13 @@ if __name__ == '__main__': args = parser.parse_args() - outDir = os.environ.get('CREMIG_DATA') + out_dir = os.environ.get('CREMIG_DATA') + if args.rd: - inPath = os.environ.get('RD_DATABASE_SOURCE') - outFileName = "RD_Bestandspool.csv" - get_rd_database(inPath, outDir, outFileName) + get_rd_dbase(out_dir) + elif args.sivas: + get_sivas_dbase(args.sivas, out_dir) - if args.sivas: - exePath = os.environ.get('SIVAS_DATABASE_QUERY') - sivasId = str(args.sivas) - outFilePath = os.path.join(outDir, sivasId + ".json") - get_sivas_databse(exePath, sivasId, outFilePath) + else: + print("ERROR - Missing flags!")