diff --git a/bazarr/database.py b/bazarr/database.py index bee060907..f5ec1d85c 100644 --- a/bazarr/database.py +++ b/bazarr/database.py @@ -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() diff --git a/bazarr/main.py b/bazarr/main.py index 33917be77..80e7f52fd 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -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: diff --git a/views/wizard_subtitles.tpl b/views/wizard_subtitles.tpl index 74f6d2de9..71e075a23 100644 --- a/views/wizard_subtitles.tpl +++ b/views/wizard_subtitles.tpl @@ -105,9 +105,9 @@ %enabled_languages = [] %for language in settings_languages: - - %if language[3] == True: - % enabled_languages.append(str(language[1])) + + %if language.enabled == True: + % enabled_languages.append(str(language.code2)) %end %end