From 248b524b92d960bd9a75b43c7abf1469d90b3de3 Mon Sep 17 00:00:00 2001 From: Bazarr user Date: Tue, 5 Dec 2017 23:07:37 -0500 Subject: [PATCH] Improve logging --- bazarr.py | 5 +++-- check_update.py | 11 +++++------ get_episodes.py | 5 +++++ get_subtitle.py | 3 +++ init_db.py | 5 ++++- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/bazarr.py b/bazarr.py index f5ba0342b..a29123562 100644 --- a/bazarr.py +++ b/bazarr.py @@ -290,6 +290,8 @@ def save_settings(): conn.commit() c.close() + + logging.info('Settings saved succefully. You must restart Bazarr.') redirect(ref) @@ -297,8 +299,7 @@ def save_settings(): def check_update(): ref = request.environ['HTTP_REFERER'] - result = check_and_apply_update() - logging.info(result) + check_and_apply_update() redirect(ref) diff --git a/check_update.py b/check_update.py index 99cf747a3..5a4854063 100644 --- a/check_update.py +++ b/check_update.py @@ -2,6 +2,7 @@ from get_general_settings import * import os import pygit2 +import logging current_working_directory = os.path.dirname(__file__) repository_path = pygit2.discover_repository(current_working_directory) @@ -20,7 +21,7 @@ def check_and_apply_update(repo=local_repo, remote_name='origin'): merge_result, _ = repo.merge_analysis(remote_id) # Up to date, do nothing if merge_result & pygit2.GIT_MERGE_ANALYSIS_UP_TO_DATE: - result = 'No new version of Bazarr available.' + logging.info('No new version of Bazarr available.') pass # We can just fastforward elif merge_result & pygit2.GIT_MERGE_ANALYSIS_FASTFORWARD: @@ -28,7 +29,7 @@ def check_and_apply_update(repo=local_repo, remote_name='origin'): master_ref = repo.lookup_reference('refs/remotes/origin/' + str(branch)) master_ref.set_target(remote_id) repo.head.set_target(remote_id) - result = 'Bazarr updated to latest version and restarting.' + logging.info('Bazarr updated to latest version and restarting.') os.execlp('python', 'python', os.path.join(os.path.dirname(__file__), 'bazarr.py')) # We can just do it normally elif merge_result & pygit2.GIT_MERGE_ANALYSIS_NORMAL: @@ -45,10 +46,8 @@ def check_and_apply_update(repo=local_repo, remote_name='origin'): tree, [repo.head.target, remote_id]) repo.state_cleanup() - result = 'Conflict detected when trying to update.' + logging.error('Conflict detected when trying to update.') os.execlp('python', 'python', os.path.join(os.path.dirname(__file__), 'bazarr.py')) # We can't do it else: - result = 'Bazarr cannot be updated: Unknown merge analysis result' - - return result + logging.error('Bazarr cannot be updated: Unknown merge analysis result') diff --git a/get_episodes.py b/get_episodes.py index 6f869a3d9..786aaf3ee 100644 --- a/get_episodes.py +++ b/get_episodes.py @@ -1,6 +1,7 @@ import os import sqlite3 import requests +import logging from get_general_settings import * from list_subtitles import * @@ -60,10 +61,14 @@ def update_all_episodes(): # Close database connection c.close() + + logging.info('All episodes updated in database.') # Store substitles for all episodes full_scan_subtitles() + logging.info('All existing subtitles indexed from disk.') list_missing_subtitles() + logging.info('All missing subtitles updated in database.') def add_new_episodes(): # Open database connection diff --git a/get_subtitle.py b/get_subtitle.py index 45d7402f2..65a26def6 100644 --- a/get_subtitle.py +++ b/get_subtitle.py @@ -1,6 +1,7 @@ import os import sqlite3 import ast +import logging from babelfish import * from subliminal import * from pycountry import * @@ -79,3 +80,5 @@ def wanted_search_missing_subtitles(): for episode in data: wanted_download_subtitles(episode[0]) + + logging.info('Finished searching for missing subtitles. Check history for more information.') \ No newline at end of file diff --git a/init_db.py b/init_db.py index 5b8e92f93..01d3b7145 100644 --- a/init_db.py +++ b/init_db.py @@ -1,5 +1,6 @@ import os import sqlite3 +import logging # Check if database exist if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) == True: @@ -41,4 +42,6 @@ else: c.executescript(script) # Close database connection - db.close() \ No newline at end of file + db.close() + + logging.info('Database created successfully') \ No newline at end of file