Fix for new install since peewee integration.

pull/543/head
Louis Vézina 5 years ago
parent 5fcad77383
commit 2fcf3dee08

@ -8,9 +8,9 @@ from playhouse.sqliteq import SqliteQueueDatabase
from helper import path_replace, path_replace_movie, path_replace_reverse, path_replace_reverse_movie from helper import path_replace, path_replace_movie, path_replace_reverse, path_replace_reverse_movie
database = SqliteQueueDatabase( database = SqliteQueueDatabase(
os.path.join(args.config_dir, 'db', 'bazarr.db'), None,
use_gevent=False, use_gevent=False,
autostart=True, autostart=False,
queue_max_size=256, # Max. # of pending writes that can accumulate. queue_max_size=256, # Max. # of pending writes that can accumulate.
results_timeout=30.0) # Max. time to wait for query to be executed. results_timeout=30.0) # Max. time to wait for query to be executed.
@ -168,6 +168,8 @@ class TableSettingsNotifier(BaseModel):
def database_init(): def database_init():
database.init(os.path.join(args.config_dir, 'db', 'bazarr.db'))
database.start()
database.connect() database.connect()
database.pragma('wal_checkpoint', 'TRUNCATE') # Run a checkpoint and merge remaining wal-journal. 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) 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(): def wal_cleaning():
database.pragma('wal_checkpoint', 'TRUNCATE') # Run a checkpoint and merge remaining wal-journal. 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. database.wal_autocheckpoint = 50 # Run an automatic checkpoint every 50 write transactions.
@atexit.register
def _stop_worker_threads():
database.close()
database.stop()

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

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

Loading…
Cancel
Save