Files
VOREStation/tools/convert_whitelists_to_sql.py
T
Selis 315fbb415f Load alien/job whitelists from database, if enabled (#17952)
* Load alien/job whitelists from database, if enabled

* SQL Template for Table

* Fixes

* Commands

* .

* .

* fix

* cannot be a list

* .

* .

* embed

* .

* .

* query test

* query test

* query test

* .

* fix
2025-09-28 10:28:55 +02:00

50 lines
1.7 KiB
Python

input_file = 'config/alienwhitelist.txt'
output_file = 'whitelist.sql'
table_name = 'whitelist'
with open(input_file, 'r', encoding='utf-8') as infile, \
open(output_file, 'w', encoding='utf-8') as outfile:
for line in infile:
line = line.strip()
if not line:
continue
if "#" in line:
print(f"Skipping commented line: {line}")
continue
# Split on ' - ', expecting exactly two parts
parts = line.split(' - ')
if len(parts) != 2:
print(f"Skipping invalid line: {line}")
continue
username, entry = (p.replace("'", "''") for p in parts) # Escape single quotes
kind = "species"
sql = (
f"INSERT INTO {table_name} (ckey, entry, kind) "
f"VALUES ('{username}', '{entry}', '{kind}');\n"
)
outfile.write(sql)
input_file = 'config/jobwhitelist.txt'
with open(input_file, 'r', encoding='utf-8') as infile, \
open(output_file, 'a', encoding='utf-8') as outfile:
for line in infile:
line = line.strip()
if not line:
continue
if "#" in line:
print(f"Skipping commented line: {line}")
continue
# Split on ' - ', expecting exactly two parts
parts = line.split(' - ')
if len(parts) != 2:
print(f"Skipping invalid line: {line}")
continue
username, entry = (p.replace("'", "''") for p in parts) # Escape single quotes
kind = "job"
sql = (
f"INSERT INTO {table_name} (ckey, entry, kind) "
f"VALUES ('{username}', '{entry}', '{kind}');\n"
)
outfile.write(sql)