Fix for new install since peewee integration.

This commit is contained in:
Louis Vézina 2019-09-13 21:53:12 -04:00
parent 5fcad77383
commit 2fcf3dee08
3 changed files with 32 additions and 42 deletions

View file

@ -8,9 +8,9 @@ from playhouse.sqliteq import SqliteQueueDatabase
from helper import path_replace, path_replace_movie, path_replace_reverse, path_replace_reverse_movie
database = SqliteQueueDatabase(
os.path.join(args.config_dir, 'db', 'bazarr.db'),
None,
use_gevent=False,
autostart=True,
autostart=False,
queue_max_size=256, # Max. # of pending writes that can accumulate.
results_timeout=30.0) # Max. time to wait for query to be executed.
@ -168,6 +168,8 @@ class TableSettingsNotifier(BaseModel):
def database_init():
database.init(os.path.join(args.config_dir, 'db', 'bazarr.db'))
database.start()
database.connect()
database.pragma('wal_checkpoint', 'TRUNCATE') # Run a checkpoint and merge remaining wal-journal.
@ -180,22 +182,7 @@ def database_init():
database.create_tables(models_list, safe=True)
# Insert default values
if System.select().count() == 0:
System.insert(
{
System.updated: 0,
System.configured: 0
}
).execute()
def wal_cleaning():
database.pragma('wal_checkpoint', 'TRUNCATE') # Run a checkpoint and merge remaining wal-journal.
database.wal_autocheckpoint = 50 # Run an automatic checkpoint every 50 write transactions.
@atexit.register
def _stop_worker_threads():
database.close()
database.stop()

View file

@ -88,10 +88,16 @@ else:
bottle.ERROR_PAGE_TEMPLATE = bottle.ERROR_PAGE_TEMPLATE.replace('if DEBUG and', 'if')
# Reset restart required warning on start
System.update({
System.configured: 0,
System.updated: 0
}).execute()
if System.select().count():
System.update({
System.configured: 0,
System.updated: 0
}).execute()
else:
System.insert({
System.configured: 0,
System.updated: 0
}).execute()
# Load languages in database
load_language_in_db()
@ -188,32 +194,29 @@ def shutdown():
except Exception as e:
logging.error('BAZARR Cannot create bazarr.stop file.')
else:
stop_file.write('')
stop_file.close()
server.stop()
database.close()
database.stop()
server.stop()
stop_file.write('')
stop_file.close()
sys.exit(0)
@route(base_url + 'restart')
def restart():
try:
server.stop()
except:
logging.error('BAZARR Cannot stop CherryPy.')
restart_file = open(os.path.join(args.config_dir, "bazarr.restart"), "w")
except Exception as e:
logging.error('BAZARR Cannot create bazarr.restart file.')
else:
try:
restart_file = open(os.path.join(args.config_dir, "bazarr.restart"), "w")
except Exception as e:
logging.error('BAZARR Cannot create bazarr.restart file.')
else:
# print 'Bazarr is being restarted...'
logging.info('Bazarr is being restarted...')
restart_file.write('')
restart_file.close()
database.close()
database.stop()
# print 'Bazarr is being restarted...'
logging.info('Bazarr is being restarted...')
server.stop()
database.close()
database.stop()
restart_file.write('')
restart_file.close()
sys.exit(0)
@route(base_url + 'wizard')
@ -439,7 +442,7 @@ def save_wizard():
settings_movie_default_hi = 'True'
settings.general.movie_default_hi = text_type(settings_movie_default_hi)
settings_movie_default_forced = str(request.forms.getall('settings_movie_default_forced'))
settings_movie_default_forced = str(request.forms.get('settings_movie_default_forced'))
settings.general.movie_default_forced = text_type(settings_movie_default_forced)
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:

View file

@ -105,9 +105,9 @@
<option value="">Languages</option>
%enabled_languages = []
%for language in settings_languages:
<option value="{{language[1]}}">{{language[2]}}</option>
%if language[3] == True:
% enabled_languages.append(str(language[1]))
<option value="{{language.code2}}">{{language.name}}</option>
%if language.enabled == True:
% enabled_languages.append(str(language.code2))
%end
%end
</select>