bazarr/get_general_settings.py

53 lines
1.4 KiB
Python
Raw Normal View History

2017-09-16 00:49:46 +00:00
import sqlite3
import os
import ast
# Open database connection
2017-10-20 12:59:21 +00:00
db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db'))
2017-09-16 00:49:46 +00:00
c = db.cursor()
# Get general settings from database table
c.execute("SELECT * FROM table_settings_general")
general_settings = c.fetchone()
# Close database connection
db.close()
ip = general_settings[0]
port = general_settings[1]
base_url = general_settings[2]
2017-10-18 18:54:24 +00:00
if base_url.endswith('/'):
base_url = base_url[:-1]
2017-10-16 23:27:19 +00:00
if general_settings[3] is None:
path_mappings = []
else:
path_mappings = ast.literal_eval(general_settings[3])
2017-10-28 02:18:16 +00:00
log_level = general_settings[4]
branch = general_settings[5]
automatic = general_settings[6]
2017-09-16 00:49:46 +00:00
def path_replace(path):
for path_mapping in path_mappings:
path = path.replace(path_mapping[0], path_mapping[1], 1)
if '\\' in path:
path = path.replace('/', '\\')
return path
def path_replace_reverse(path):
for path_mapping in path_mappings:
if path.startswith('\\\\\\\\'):
if '\\\\' in path:
path = path.replace('\\\\', '\\')
elif '\\' in path:
path = path.replace('\\\\', '\\')
path = path.replace(path_mapping[1], path_mapping[0], 1)
elif path.startswith('\\\\'):
path = path.replace(path_mapping[1], path_mapping[0], 1)
if '\\' in path:
path = path.replace('\\', '/')
2017-10-28 02:18:16 +00:00
return path