From 630f7e8394b487504bc1c9990d0ea60bd8330a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Sun, 16 Feb 2020 19:38:10 -0500 Subject: [PATCH] WIP --- bazarr/api.py | 39 +++++++++++- bazarr/main.py | 33 +++------- views/_main.html | 4 +- views/systemreleases.html | 42 +++++++++++++ views/systemstatus.html | 129 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 218 insertions(+), 29 deletions(-) create mode 100644 views/systemreleases.html create mode 100644 views/systemstatus.html diff --git a/bazarr/api.py b/bazarr/api.py index e413ca7a0..1e0a1e01c 100644 --- a/bazarr/api.py +++ b/bazarr/api.py @@ -6,7 +6,10 @@ import datetime import pretty import time from operator import itemgetter +import platform +import io +from get_args import args from config import settings, base_url from init import * @@ -21,7 +24,7 @@ from get_subtitle import download_subtitle, series_download_subtitles, movies_do from notifier import send_notifications, send_notifications_movie from list_subtitles import store_subtitles, store_subtitles_movie, series_scan_subtitles, movies_scan_subtitles, \ list_missing_subtitles, list_missing_subtitles_movies -from utils import history_log, history_log_movie +from utils import history_log, history_log_movie, get_sonarr_version, get_radarr_version from get_providers import get_providers, get_providers_auth, list_throttled_providers from websocket_handler import event_stream @@ -57,6 +60,37 @@ class Languages(Resource): return jsonify(result) +class SystemStatus(Resource): + def get(self): + system_status = {} + system_status.update({'bazarr_version': os.environ["BAZARR_VERSION"]}) + system_status.update({'sonarr_version': get_sonarr_version()}) + system_status.update({'radarr_version': get_radarr_version()}) + system_status.update({'operating_system': platform.platform()}) + system_status.update({'python_version': platform.python_version()}) + system_status.update({'bazarr_directory': os.path.dirname(os.path.dirname(__file__))}) + system_status.update({'bazarr_config_directory': args.config_dir}) + return jsonify(data=system_status) + + +class SystemReleases(Resource): + def get(self): + releases = [] + try: + with io.open(os.path.join(args.config_dir, 'config', 'releases.txt'), 'r', encoding='UTF-8') as f: + releases = ast.literal_eval(f.read()) + for release in releases: + release[1] = release[1].replace('- ', '') + release[1] = release[1].split('\r\n') + release[1].pop(0) + release.append(True if release[0].lstrip('v') == os.environ["BAZARR_VERSION"] else False) + + except Exception as e: + logging.exception( + 'BAZARR cannot parse releases caching file: ' + os.path.join(args.config_dir, 'config', 'releases.txt')) + return jsonify(data=releases) + + class Series(Resource): def get(self): start = request.args.get('start') or 0 @@ -1044,6 +1078,9 @@ class SearchWantedMovies(Resource): api.add_resource(Badges, '/badges') api.add_resource(Languages, '/languages') +api.add_resource(SystemStatus, '/systemstatus') +api.add_resource(SystemReleases, '/systemreleases') + api.add_resource(Series, '/series') api.add_resource(SeriesEditSave, '/series_edit_save') api.add_resource(Episodes, '/episodes') diff --git a/bazarr/main.py b/bazarr/main.py index 416061a98..33db2a595 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -1016,35 +1016,16 @@ def check_update(): redirect(ref) -@app.route('/system') +@app.route('/systemstatus') @login_required -def system(): +def systemstatus(): + return render_template('systemstatus.html') - task_list = scheduler.get_task_list() - - throttled_providers = list_throttled_providers() - - try: - with io.open(os.path.join(args.config_dir, 'config', 'releases.txt'), 'r', encoding='UTF-8') as f: - releases = ast.literal_eval(f.read()) - except Exception as e: - releases = [] - logging.exception( - 'BAZARR cannot parse releases caching file: ' + os.path.join(args.config_dir, 'config', 'releases.txt')) - - sonarr_version = get_sonarr_version() - - radarr_version = get_radarr_version() - - page_size = int(settings.general.page_size) - - return render_template('system.html', bazarr_version=bazarr_version, - sonarr_version=sonarr_version, radarr_version=radarr_version, - operating_system=platform.platform(), python_version=platform.python_version(), - config_dir=args.config_dir, bazarr_dir=os.path.normcase(os.path.dirname(os.path.dirname(__file__))), - base_url=base_url, task_list=task_list, page_size=page_size, releases=releases, - current_port=settings.general.port, throttled_providers=throttled_providers) +@app.route('/systemreleases') +@login_required +def systemreleases(): + return render_template('systemreleases.html') @app.route('/logs') diff --git a/views/_main.html b/views/_main.html index 1eb99ddcc..382101d34 100644 --- a/views/_main.html +++ b/views/_main.html @@ -191,8 +191,8 @@