You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bazarr/bazarr/database.py

60 lines
1.9 KiB

import os
5 years ago
from sqlite3worker import Sqlite3Worker
5 years ago
from six import string_types
from get_args import args
from helper import path_replace, path_replace_movie, path_replace_reverse, path_replace_reverse_movie
5 years ago
database = Sqlite3Worker(os.path.join(args.config_dir, 'db', 'bazarr.db'), max_queue_size=256, as_dict=True)
5 years ago
class SqliteDictConverter:
def __init__(self):
5 years ago
self.keys_insert = tuple()
self.keys_update = tuple()
self.values = tuple()
self.question_marks = tuple()
5 years ago
def convert(self, values_dict):
5 years ago
if type(values_dict) is dict:
5 years ago
temp_keys = list()
temp_values = list()
for item in values_dict.items():
temp_keys.append(item[0])
temp_values.append(item[1])
self.keys_insert = ','.join(temp_keys)
self.keys_update = ','.join([k + '=?' for k in temp_keys])
self.values = tuple(temp_values)
self.question_marks = ','.join(list('?'*len(values_dict)))
5 years ago
return self
else:
pass
dict_converter = SqliteDictConverter()
5 years ago
class SqliteDictPathMapper:
def __init__(self):
pass
def path_replace(self, values_dict):
5 years ago
if type(values_dict) is list:
for item in values_dict:
item['path'] = path_replace(item['path'])
elif type(values_dict) is dict:
values_dict['path'] = path_replace(values_dict['path'])
5 years ago
else:
return path_replace(values_dict)
5 years ago
def path_replace_movie(self, values_dict):
5 years ago
if type(values_dict) is list:
for item in values_dict:
item['path'] = path_replace_movie(item['path'])
elif type(values_dict) is dict:
values_dict['path'] = path_replace_movie(values_dict['path'])
5 years ago
else:
return path_replace(values_dict)
5 years ago
dict_mapper = SqliteDictPathMapper()