From ac640e40541e10824950d8aa1be6f7c29a55d56e Mon Sep 17 00:00:00 2001 From: Halali Date: Fri, 2 Nov 2018 20:08:07 +0100 Subject: [PATCH] Add status page and fix for #160 --- bazarr/check_update.py | 25 ++++++++ bazarr/init.py | 5 ++ bazarr/main.py | 41 +++++++----- bazarr/scheduler.py | 8 ++- views/system.tpl | 139 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 201 insertions(+), 17 deletions(-) diff --git a/bazarr/check_update.py b/bazarr/check_update.py index d20facf80..5be9b65f6 100644 --- a/bazarr/check_update.py +++ b/bazarr/check_update.py @@ -5,6 +5,8 @@ from get_settings import get_general_settings import os import logging import sqlite3 +import json +import requests import git @@ -29,6 +31,7 @@ def gitconfig(): def check_and_apply_update(): gitconfig() + check_releases() branch = get_general_settings()[5] g = git.cmd.Git(current_working_directory) g.fetch('origin') @@ -43,6 +46,28 @@ def check_and_apply_update(): logging.info('BAZARR Updated to latest version. Restart required. ' + result) updated() + +def check_releases(): + releases = [] + url_releases = 'https://api.github.com/repos/morpheus65535/Bazarr/releases' + try: + r = requests.get(url_releases, timeout=15) + r.raise_for_status() + except requests.exceptions.HTTPError as errh: + logging.exception("Error trying to get releases from Github. Http error.") + except requests.exceptions.ConnectionError as errc: + logging.exception("Error trying to get releases from Github. Connection Error.") + except requests.exceptions.Timeout as errt: + logging.exception("Error trying to get releases from Github. Timeout Error.") + except requests.exceptions.RequestException as err: + logging.exception("Error trying to get releases from Github.") + else: + for release in r.json(): + releases.append([release['name'], release['body']]) + with open(os.path.join(config_dir, 'config', 'releases.txt'), 'w') as f: + json.dump(releases, f) + + def updated(): conn = sqlite3.connect(os.path.join(config_dir, 'db/bazarr.db'), timeout=30) c = conn.cursor() diff --git a/bazarr/init.py b/bazarr/init.py index 8078a48a1..1e07b032e 100644 --- a/bazarr/init.py +++ b/bazarr/init.py @@ -24,6 +24,11 @@ if os.path.exists(os.path.join(config_dir, 'db')) is False: if os.path.exists(os.path.join(config_dir, 'log')) is False: os.mkdir(os.path.join(config_dir, 'log')) logging.debug("BAZARR Created log folder") + +if not os.path.exists(os.path.join(config_dir, 'config', 'releases.txt')): + from check_update import check_releases + check_releases() + logging.debug("BAZARR Created releases file") config_file = os.path.normpath(os.path.join(config_dir, 'config/config.ini')) diff --git a/bazarr/main.py b/bazarr/main.py index ed698df59..8c6e18520 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -1465,24 +1465,33 @@ def system(): page_size = int(get_general_settings()[21]) max_page = int(math.ceil(row_count / (page_size + 0.0))) - releases = [] - url_releases = 'https://api.github.com/repos/morpheus65535/Bazarr/releases' + with open(os.path.join(config_dir, 'config', 'releases.txt'), 'r') as f: + releases = ast.literal_eval(f.read()) + + import platform + url_sonarr = get_sonarr_settings()[6] + apikey_sonarr = get_sonarr_settings()[4] + sv = url_sonarr + "/api/system/status?apikey=" + apikey_sonarr try: - r = requests.get(url_releases, timeout=15) - r.raise_for_status() - except requests.exceptions.HTTPError as errh: - logging.exception("BAZARR Error trying to get releases from Github. Http error.") - except requests.exceptions.ConnectionError as errc: - logging.exception("BAZARR Error trying to get releases from Github. Connection Error.") - except requests.exceptions.Timeout as errt: - logging.exception("BAZARR Error trying to get releases from Github. Timeout Error.") - except requests.exceptions.RequestException as err: - logging.exception("BAZARR Error trying to get releases from Github.") - else: - for release in r.json(): - releases.append([release['name'],release['body']]) + sonarr_version = requests.get(sv, timeout=15, verify=False) + except: + sonarr_version = '' + + url_radarr = get_radarr_settings()[6] + apikey_radarr = get_radarr_settings()[4] + sv = url_radarr + "/api/system/status?apikey=" + apikey_radarr + try: + radarr_version = requests.get(sv, timeout=15, verify=False) + except: + radarr_version = '' + + return template('system', __file__=__file__, bazarr_version=bazarr_version, + sonarr_version=sonarr_version.json()['version'], radarr_version=radarr_version.json()['version'], + operation_system=platform.platform(), python_version=platform.python_version(), + config_dir=config_dir, bazarr_dir=os.getcwd(), + base_url=base_url, task_list=task_list, row_count=row_count, max_page=max_page, page_size=page_size, + releases=releases, current_port=port) - return template('system', __file__=__file__, bazarr_version=bazarr_version, base_url=base_url, task_list=task_list, row_count=row_count, max_page=max_page, page_size=page_size, releases=releases, current_port=port) @route(base_url + 'logs/') @custom_auth_basic(check_credentials) diff --git a/bazarr/scheduler.py b/bazarr/scheduler.py index 0a2f3a351..27f5b6321 100644 --- a/bazarr/scheduler.py +++ b/bazarr/scheduler.py @@ -7,7 +7,9 @@ from get_movies import update_movies from list_subtitles import store_subtitles from get_subtitle import wanted_search_missing_subtitles if no_update is False: - from check_update import check_and_apply_update + from check_update import check_and_apply_update, check_releases +else: + from check_update import check_releases from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.triggers.interval import IntervalTrigger @@ -66,6 +68,10 @@ if no_update is False: scheduler.add_job(check_and_apply_update, IntervalTrigger(hours=6), max_instances=1, coalesce=True, misfire_grace_time=15, id='update_bazarr', name='Update bazarr from source on Github') else: scheduler.add_job(check_and_apply_update, CronTrigger(year='2100'), hour=4, id='update_bazarr', name='Update bazarr from source on Github') + scheduler.add_job(check_releases, IntervalTrigger(hours=6), max_instances=1, coalesce=True, misfire_grace_time=15, id='update_release', name='Update release info') +else: + scheduler.add_job(check_releases, IntervalTrigger(hours=6), max_instances=1, coalesce=True, misfire_grace_time=15, + id='update_release', name='Update release info') if integration[12] is True: scheduler.add_job(update_series, IntervalTrigger(minutes=1), max_instances=1, coalesce=True, misfire_grace_time=15, id='update_series', name='Update series list from Sonarr') diff --git a/views/system.tpl b/views/system.tpl index a2882b14c..b99903153 100644 --- a/views/system.tpl +++ b/views/system.tpl @@ -53,6 +53,7 @@
@@ -115,6 +116,144 @@ %end
+
+
About
+
+
+
+
+ +
+
+
+
+ {{bazarr_version}} +
+
+
+
+
+
+ +
+
+
+
+ {{operation_system}} +
+
+
+
+ % from get_settings import get_general_settings + % if get_general_settings()[12]: +
+
+ +
+
+
+
+ {{sonarr_version}} +
+
+
+
+ % end + % if get_general_settings()[13]: +
+
+ +
+
+
+
+ {{radarr_version}} +
+
+
+
+ % end +
+
+ +
+
+
+
+ {{python_version}} +
+
+
+
+
+
+ +
+
+
+
+ {{config_dir}} +
+
+
+
+
+
+ +
+
+
+
+ {{bazarr_dir}} +
+
+
+
+
+
+
More info
+
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+
+ +
+
+
+
+
+ +
+
+ +
+
+ +
+
+
%for release in releases: