From e34ebd1d5358f05ee0e368a23fc0b8f03c0e3021 Mon Sep 17 00:00:00 2001 From: mistangl Date: Mon, 11 Dec 2023 16:09:55 +0100 Subject: [PATCH] blackliste wird geholt und geschrieben --- .vscode/launch.json | 4 ++-- bin/03_get_blacklist_dbase.bat | 3 +-- bin/cremig_setenv.bat | 2 ++ lib/update_database.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index b25fd18..52a004a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -37,14 +37,14 @@ ], } { - "name": "Python: TOS string to file", + "name": "fetch blacklist from server", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": true, "args": [ - "--outfile=blubb.txt" + "--blacklist" ], } diff --git a/bin/03_get_blacklist_dbase.bat b/bin/03_get_blacklist_dbase.bat index 4babafb..863fa3d 100644 --- a/bin/03_get_blacklist_dbase.bat +++ b/bin/03_get_blacklist_dbase.bat @@ -2,6 +2,5 @@ CALL cremig_setenv.bat IF NOT EXIST %CREMIG%\.venv CALL %CREMIG_BIN%\install_py.bat CALL %CREMIG%\.venv\Scripts\activate.bat -IF "%1" == "-s" (set SIVAS_ID=%2) else (set /p SIVAS_ID=Enter Sivas ID:) -python %CREMIG_LIB%\update_database.py --sivas=%SIVAS_ID% +python %CREMIG_LIB%\update_database.py --blacklist deactivate diff --git a/bin/cremig_setenv.bat b/bin/cremig_setenv.bat index d6dabbd..321ca4d 100644 --- a/bin/cremig_setenv.bat +++ b/bin/cremig_setenv.bat @@ -16,6 +16,8 @@ set PATH=%CREMIG%\bin;%PATH% set RD_DATABASE_SOURCE=\\ssg.local\freigaben\SIVAS_CAD_EDM\Migration\07_RD_Teilenummern set RD_DATABASE_NAME=RD_Teilenummern.csv +set BLACKLIST_DATABASE_SOURCE=\\ruledesigner\RDF_Daten\Konfigurator\CustomVaulting +set BLACKLIST_DATABASE_NAME=ERP_BOM.ini set VBA_MACRO_NAME=vba_format_excel.xlsm set SIVAS_DATABASE_QUERY=Y:\jit\programme\Sivas2json.exe REM set SIVAS_TEILESTAMM=\\195.243.223.3\sivas\NetEnv\Sivas4.exe diff --git a/lib/update_database.py b/lib/update_database.py index c9a5bc9..3acc2fc 100644 --- a/lib/update_database.py +++ b/lib/update_database.py @@ -2,6 +2,7 @@ import argparse import os import shutil import subprocess +import configparser """ Dieses Programm: @@ -9,6 +10,31 @@ Dieses Programm: - 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_blacklist(outdir): + """read out list of sivas Ids which are not allowed from network drive + '//ruledesigner//DF_Daten//onfigurator//ustomVaulting//RP_BOM.ini' + within the section 'Settings' + in the key 'PartNumbersToDrop' + """ + blacklist_net_share = os.environ.get("BLACKLIST_DATABASE_SOURCE") + blacklist_ini_filename = os.environ.get("BLACKLIST_DATABASE_NAME") + blacklist_source_path = os.path.join(blacklist_net_share, blacklist_ini_filename) + config = configparser.RawConfigParser() + try: + config.read(blacklist_source_path) + except configparser.DuplicateOptionError: + pass + content = config.get('Settings','PartNumbersToDrop') + blacklist_str = content[0] # warum das als Liste erkannt wird wissen die Götter... + if len(blacklist_str) == 0 or len(content) == 0: + print(f"import of '{blacklist_ini_filename}' from '{blacklist_net_share}' failed") + exit + + blacklist = blacklist_str.split(';') + + outfile = os.path.join(outdir, 'blacklist.txt') + with open(outfile, 'w', encoding='utf-8') as fh: + fh.write('\n'.join(blacklist)) def get_rd_dbase(out_dir): @@ -53,6 +79,7 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description='fetches data from sivas or ruledesigner fusion', prog='update_database') parser.add_argument('-s', '--sivas', action='store', help='fetch data of this id from sivas fo local database folder', metavar='id') parser.add_argument('-r', '--rd', action='store_true', help='fetch list of existing parts from network drive') + parser.add_argument('-b', '--blacklist', action='store_true', help='fetch list of not allowed parts from network drive') args = parser.parse_args() @@ -64,5 +91,8 @@ if __name__ == '__main__': elif args.sivas: get_sivas_dbase(args.sivas, out_dir) + elif args.blacklist: + get_blacklist(out_dir) + else: parser.print_help()