-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvxlink_sqlite2conf_v1.py
41 lines (31 loc) · 1.37 KB
/
svxlink_sqlite2conf_v1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
import sqlite3
db_path = 'svxlink_conf_v1.db' # Path to your SQLite database
config_file_path = 'svxlink_conf_v1.txt' # Output configuration file
def write_config_from_db(db_path, file_path):
"""
Write a configuration file from an SQLite database, excluding system tables.
"""
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Retrieve the list of tables (sections), excluding system tables
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'")
tables = cursor.fetchall()
with open(file_path, 'w') as file:
for table_name in tables:
# Write the section header
section = table_name[0]
file.write(f'[{section}]\n')
print(f"Writing section: [{section}]")
# Query key-value pairs for the current table
cursor.execute(f'SELECT key, value FROM "{section}"')
key_values = cursor.fetchall()
# Write the key-value pairs
for key, value in key_values:
file.write(f'{key}={value}\n')
# Add a newline for readability between sections
file.write('\n')
conn.close()
print("Configuration file has been created from the SQLite database.")
# Generate the configuration file from the database
write_config_from_db(db_path, config_file_path)