Improving releases and update process.

pull/1383/head
morpheus65535 4 years ago
parent 94825422d5
commit 5aea4e0483

@ -295,12 +295,15 @@ class SystemReleases(Resource):
releases = [] releases = []
try: try:
with io.open(os.path.join(args.config_dir, 'config', 'releases.txt'), 'r', encoding='UTF-8') as f: with io.open(os.path.join(args.config_dir, 'config', 'releases.txt'), 'r', encoding='UTF-8') as f:
releases = ast.literal_eval(f.read()) releases = json.loads(f.read())
for release in releases: releases = releases[:5]
release[1] = release[1].replace('- ', '') for i, release in enumerate(releases):
release[1] = release[1].split('\r\n') body = release['body'].replace('- ', '').split('\r\n')[1:]
release[1].pop(0) releases[i] = {"body": body,
release.append(True if release[0].lstrip('v') == os.environ["BAZARR_VERSION"] else False) "name": release['name'],
"date": release['date'][:10],
"prerelease": release['prerelease'],
"current": True if release['name'].lstrip('v') == os.environ["BAZARR_VERSION"] else False}
except Exception as e: except Exception as e:
logging.exception( logging.exception(

@ -54,24 +54,22 @@ def check_and_apply_update():
logging.info('BAZARR Updated to latest version. Restart required. ' + result) logging.info('BAZARR Updated to latest version. Restart required. ' + result)
updated() updated()
else: else:
url = 'https://api.github.com/repos/morpheus65535/bazarr/releases' url = 'https://api.github.com/repos/morpheus65535/bazarr/releases/latest'
releases = request_json(url, timeout=20, whitelist_status_code=404, validator=lambda x: type(x) == list) release = request_json(url, timeout=20, whitelist_status_code=404, validator=lambda x: type(x) == list)
if releases is None: if release is None:
logging.warning('BAZARR Could not get releases from GitHub.') logging.warning('BAZARR Could not get releases from GitHub.')
return return
else: else:
release = releases[0]
latest_release = release['tag_name'] latest_release = release['tag_name']
if ('v' + os.environ["BAZARR_VERSION"]) != latest_release: if ('v' + os.environ["BAZARR_VERSION"]) != latest_release:
update_from_source() update_from_source(tar_download_url=release['tarball_url'])
else: else:
logging.info('BAZARR is up to date') logging.info('BAZARR is up to date')
def update_from_source(): def update_from_source(tar_download_url):
tar_download_url = 'https://github.com/morpheus65535/bazarr/tarball/{}'.format(settings.general.branch)
update_dir = os.path.join(os.path.dirname(__file__), '..', 'update') update_dir = os.path.join(os.path.dirname(__file__), '..', 'update')
logging.info('BAZARR Downloading update from: ' + tar_download_url) logging.info('BAZARR Downloading update from: ' + tar_download_url)
@ -135,7 +133,10 @@ def check_releases():
logging.exception("Error trying to get releases from Github.") logging.exception("Error trying to get releases from Github.")
else: else:
for release in r.json(): for release in r.json():
releases.append([release['name'], release['body']]) releases.append({'name': release['name'],
'body': release['body'],
'date': release['published_at'],
'prerelease': release['prerelease']})
with open(os.path.join(args.config_dir, 'config', 'releases.txt'), 'w') as f: with open(os.path.join(args.config_dir, 'config', 'releases.txt'), 'w') as f:
json.dump(releases, f) json.dump(releases, f)

@ -215,12 +215,12 @@ class Scheduler:
check_and_apply_update, CronTrigger(year='2100'), hour=4, id='update_bazarr', name=task_name, check_and_apply_update, CronTrigger(year='2100'), hour=4, id='update_bazarr', name=task_name,
replace_existing=True) replace_existing=True)
self.aps_scheduler.add_job( self.aps_scheduler.add_job(
check_releases, IntervalTrigger(hours=6), max_instances=1, coalesce=True, misfire_grace_time=15, check_releases, IntervalTrigger(hours=3), max_instances=1, coalesce=True, misfire_grace_time=15,
id='update_release', name='Update Release Info', replace_existing=True) id='update_release', name='Update Release Info', replace_existing=True)
else: else:
self.aps_scheduler.add_job( self.aps_scheduler.add_job(
check_releases, IntervalTrigger(hours=6), max_instances=1, coalesce=True, misfire_grace_time=15, check_releases, IntervalTrigger(hours=3), max_instances=1, coalesce=True, misfire_grace_time=15,
id='update_release', name='Update Release Info', replace_existing=True) id='update_release', name='Update Release Info', replace_existing=True)
def __search_wanted_subtitles_task(self): def __search_wanted_subtitles_task(self):

@ -2,6 +2,15 @@
{% block title %}Releases - Bazarr{% endblock %} {% block title %}Releases - Bazarr{% endblock %}
{% block head %}
<style>
.badge {
vertical-align: text-bottom;
margin-left: 10px;
}
</style>
{% endblock head %}
{% block bcleft %} {% block bcleft %}
{% endblock bcleft %} {% endblock bcleft %}
@ -27,8 +36,12 @@
function appendFunc(value) { function appendFunc(value) {
entries = ''; entries = '';
value[1].forEach(appendEntry); value['body'].forEach(appendEntry);
releases = releases + '<h4>'+value[0]+((value[2]) ? ' <span class="badge badge-success">Current Version</span>' : '')+'</h4><hr/><p><b>From newest to oldest:</b></p><ul>'+entries+'</ul>'; releases = releases + '<h3 style="display:inline;">'+value['name']+'</h3>'
releases += ' — '+value['date']
releases += ((value['prerelease']) ? '<span class="badge badge-danger">Development</span>' : '<span class="badge badge-info">Master</span>')
releases += ((value['current']) ? '<span class="badge badge-secondary">Currently Installed</span>' : '')
releases += '</h4><hr/><p><b>From newest to oldest:</b></p><ul>'+entries+'</ul>';
function appendEntry(entry) { function appendEntry(entry) {
entries = entries + '<li>'+entry+'</li>'; entries = entries + '<li>'+entry+'</li>';

Loading…
Cancel
Save