CSV-Teilestammableitung aus get_sivas_teilestamm.py in update_database.py umgezogen
This commit is contained in:
+46
-3
@@ -39,7 +39,7 @@ def get_blacklist(outdir):
|
||||
fh.write('\n'.join(blacklist))
|
||||
print("done")
|
||||
|
||||
def get_rd_dbase(out_dir):
|
||||
def get_rd_dbase(out_dir=os.environ.get('CREMIG_DATA')):
|
||||
|
||||
rd_csv_source_dir = os.environ.get("RD_DATABASE_SOURCE")
|
||||
rd_csv_filename = os.environ.get("RD_DATABASE_NAME")
|
||||
@@ -59,9 +59,9 @@ def get_rd_dbase(out_dir):
|
||||
print(f"File with ruldesigner-partnumbers ${csv_source_path} doesn't exist. Check VPN connection and %RD_DATABASE_SOURCE% + %RD_DATABASE_NAME% in cremig_setenv.bat")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def get_sivas_dbase(sivas_id, out_dir):
|
||||
sivas_exe_path = os.environ.get('SIVAS_DATABASE_QUERY')
|
||||
sivas_id = sivas_id.replace(".json", "")
|
||||
|
||||
if os.path.isfile(sivas_exe_path):
|
||||
|
||||
@@ -81,12 +81,50 @@ def get_sivas_dbase(sivas_id, out_dir):
|
||||
print(f"Can't execute SIVAS-database query. Check VPN connection and check the path of %SIVAS_DATABASE_QUERY% in cremig_setenv.bat")
|
||||
sys.exit(0)
|
||||
|
||||
def get_sivas_teilestamm(sivas_ids, out_dir):
|
||||
|
||||
sivas_teilestamm_exe = os.environ.get('SIVAS_TEILESTAMM')
|
||||
|
||||
if isinstance(sivas_ids, str):
|
||||
sivas_ids = list(set(sivas_ids.strip().split(",")))
|
||||
|
||||
ids_to_generate = []
|
||||
for id in sivas_ids:
|
||||
id = id.replace(" ", "")
|
||||
out_file = os.path.join(out_dir, id + ".csv")
|
||||
if not os.path.isfile(out_file):
|
||||
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")
|
||||
|
||||
|
||||
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
|
||||
|
||||
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")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='fetches data from sivas or ruledesigner fusion', prog='update_database')
|
||||
parser.add_argument('-s', '--sivasid', 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')
|
||||
parser.add_argument('-t', '--teilestamm', action='store_true', help='fetch teilestamm-data for given partnumbers as csv')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -96,7 +134,12 @@ if __name__ == '__main__':
|
||||
get_rd_dbase(out_dir)
|
||||
|
||||
elif args.sivasid:
|
||||
get_sivas_dbase(args.sivasid, out_dir)
|
||||
|
||||
if args.teilestamm:
|
||||
get_sivas_teilestamm(args.sivasid, out_dir)
|
||||
|
||||
else:
|
||||
get_sivas_dbase(args.sivasid, out_dir)
|
||||
|
||||
elif args.blacklist:
|
||||
get_blacklist(out_dir)
|
||||
|
||||
Reference in New Issue
Block a user