New updater with default setting -> only stable releases #653
This commit is contained in:
+24
-138
@@ -57,6 +57,7 @@ from redirect import redirect_back
|
||||
import time
|
||||
import server
|
||||
from reverseproxy import ReverseProxied
|
||||
from updater import updater_thread
|
||||
|
||||
try:
|
||||
from googleapiclient.errors import HttpError
|
||||
@@ -1139,127 +1140,7 @@ def get_matching_tags():
|
||||
@app.route("/get_update_status", methods=['GET'])
|
||||
@login_required_if_no_ano
|
||||
def get_update_status():
|
||||
status = {
|
||||
'update': False,
|
||||
'success': False,
|
||||
'message': '',
|
||||
'current_commit_hash': ''
|
||||
}
|
||||
parents = []
|
||||
|
||||
repository_url = 'https://api.github.com/repos/janeczku/calibre-web'
|
||||
tz = datetime.timedelta(seconds=time.timezone if (time.localtime().tm_isdst == 0) else time.altzone)
|
||||
|
||||
if request.method == "GET":
|
||||
version = helper.get_current_version_info()
|
||||
if version is False:
|
||||
status['current_commit_hash'] = _(u'Unknown')
|
||||
else:
|
||||
status['current_commit_hash'] = version['hash']
|
||||
|
||||
try:
|
||||
r = requests.get(repository_url + '/git/refs/heads/master')
|
||||
r.raise_for_status()
|
||||
commit = r.json()
|
||||
except requests.exceptions.HTTPError as e:
|
||||
status['message'] = _(u'HTTP Error') + ' ' + str(e)
|
||||
except requests.exceptions.ConnectionError:
|
||||
status['message'] = _(u'Connection error')
|
||||
except requests.exceptions.Timeout:
|
||||
status['message'] = _(u'Timeout while establishing connection')
|
||||
except requests.exceptions.RequestException:
|
||||
status['message'] = _(u'General error')
|
||||
|
||||
if status['message'] != '':
|
||||
return json.dumps(status)
|
||||
|
||||
if 'object' not in commit:
|
||||
status['message'] = _(u'Unexpected data while reading update information')
|
||||
return json.dumps(status)
|
||||
|
||||
if commit['object']['sha'] == status['current_commit_hash']:
|
||||
status.update({
|
||||
'update': False,
|
||||
'success': True,
|
||||
'message': _(u'No update available. You already have the latest version installed')
|
||||
})
|
||||
return json.dumps(status)
|
||||
|
||||
# a new update is available
|
||||
status['update'] = True
|
||||
|
||||
try:
|
||||
r = requests.get(repository_url + '/git/commits/' + commit['object']['sha'])
|
||||
r.raise_for_status()
|
||||
update_data = r.json()
|
||||
except requests.exceptions.HTTPError as e:
|
||||
status['error'] = _(u'HTTP Error') + ' ' + str(e)
|
||||
except requests.exceptions.ConnectionError:
|
||||
status['error'] = _(u'Connection error')
|
||||
except requests.exceptions.Timeout:
|
||||
status['error'] = _(u'Timeout while establishing connection')
|
||||
except requests.exceptions.RequestException:
|
||||
status['error'] = _(u'General error')
|
||||
|
||||
if status['message'] != '':
|
||||
return json.dumps(status)
|
||||
|
||||
if 'committer' in update_data and 'message' in update_data:
|
||||
status['success'] = True
|
||||
status['message'] = _(u'A new update is available. Click on the button below to update to the latest version.')
|
||||
|
||||
new_commit_date = datetime.datetime.strptime(
|
||||
update_data['committer']['date'], '%Y-%m-%dT%H:%M:%SZ') - tz
|
||||
parents.append(
|
||||
[
|
||||
format_datetime(new_commit_date, format='short', locale=get_locale()),
|
||||
update_data['message'],
|
||||
update_data['sha']
|
||||
]
|
||||
)
|
||||
|
||||
# it only makes sense to analyze the parents if we know the current commit hash
|
||||
if status['current_commit_hash'] != '':
|
||||
try:
|
||||
parent_commit = update_data['parents'][0]
|
||||
# limit the maximum search depth
|
||||
remaining_parents_cnt = 10
|
||||
except IndexError:
|
||||
remaining_parents_cnt = None
|
||||
|
||||
if remaining_parents_cnt is not None:
|
||||
while True:
|
||||
if remaining_parents_cnt == 0:
|
||||
break
|
||||
|
||||
# check if we are more than one update behind if so, go up the tree
|
||||
if parent_commit['sha'] != status['current_commit_hash']:
|
||||
try:
|
||||
r = requests.get(parent_commit['url'])
|
||||
r.raise_for_status()
|
||||
parent_data = r.json()
|
||||
|
||||
parent_commit_date = datetime.datetime.strptime(
|
||||
parent_data['committer']['date'], '%Y-%m-%dT%H:%M:%SZ') - tz
|
||||
parent_commit_date = format_datetime(
|
||||
parent_commit_date, format='short', locale=get_locale())
|
||||
|
||||
parents.append([parent_commit_date, parent_data['message'], parent_data['sha']])
|
||||
parent_commit = parent_data['parents'][0]
|
||||
remaining_parents_cnt -= 1
|
||||
except Exception:
|
||||
# it isn't crucial if we can't get information about the parent
|
||||
break
|
||||
else:
|
||||
# parent is our current version
|
||||
break
|
||||
|
||||
else:
|
||||
status['success'] = False
|
||||
status['message'] = _(u'Could not fetch update information')
|
||||
|
||||
status['history'] = parents
|
||||
return json.dumps(status)
|
||||
return updater_thread.get_available_updates(request.method)
|
||||
|
||||
|
||||
@app.route("/get_updater_status", methods=['GET', 'POST'])
|
||||
@@ -1284,12 +1165,12 @@ def get_updater_status():
|
||||
"11": _(u'Update failed:') + u' ' + _(u'General error')
|
||||
}
|
||||
status['text'] = text
|
||||
helper.updater_thread = helper.Updater()
|
||||
helper.updater_thread.start()
|
||||
status['status'] = helper.updater_thread.get_update_status()
|
||||
# helper.updater_thread = helper.Updater()
|
||||
updater_thread.start()
|
||||
status['status'] = updater_thread.get_update_status()
|
||||
elif request.method == "GET":
|
||||
try:
|
||||
status['status'] = helper.updater_thread.get_update_status()
|
||||
status['status'] = updater_thread.get_update_status()
|
||||
except AttributeError:
|
||||
# thread is not active, occours after restart on update
|
||||
status['status'] = 7
|
||||
@@ -1957,13 +1838,13 @@ def shutdown():
|
||||
abort(404)
|
||||
|
||||
|
||||
@app.route("/update")
|
||||
'''@app.route("/update")
|
||||
@login_required
|
||||
@admin_required
|
||||
def update():
|
||||
helper.updater_thread = helper.Updater()
|
||||
# updater.updater_thread = helper.Updater()
|
||||
flash(_(u"Update done"), category="info")
|
||||
return abort(404)
|
||||
return abort(404)'''
|
||||
|
||||
|
||||
@app.route("/search", methods=["GET"])
|
||||
@@ -2862,20 +2743,23 @@ def profile():
|
||||
@login_required
|
||||
@admin_required
|
||||
def admin():
|
||||
version = helper.get_current_version_info()
|
||||
version = updater_thread.get_current_version_info()
|
||||
if version is False:
|
||||
commit = _(u'Unknown')
|
||||
else:
|
||||
commit = version['datetime']
|
||||
if 'datetime' in version:
|
||||
commit = version['datetime']
|
||||
|
||||
tz = datetime.timedelta(seconds=time.timezone if (time.localtime().tm_isdst == 0) else time.altzone)
|
||||
form_date = datetime.datetime.strptime(commit[:19], "%Y-%m-%dT%H:%M:%S")
|
||||
if len(commit) > 19: # check if string has timezone
|
||||
if commit[19] == '+':
|
||||
form_date -= datetime.timedelta(hours=int(commit[20:22]), minutes=int(commit[23:]))
|
||||
elif commit[19] == '-':
|
||||
form_date += datetime.timedelta(hours=int(commit[20:22]), minutes=int(commit[23:]))
|
||||
commit = format_datetime(form_date - tz, format='short', locale=get_locale())
|
||||
tz = datetime.timedelta(seconds=time.timezone if (time.localtime().tm_isdst == 0) else time.altzone)
|
||||
form_date = datetime.datetime.strptime(commit[:19], "%Y-%m-%dT%H:%M:%S")
|
||||
if len(commit) > 19: # check if string has timezone
|
||||
if commit[19] == '+':
|
||||
form_date -= datetime.timedelta(hours=int(commit[20:22]), minutes=int(commit[23:]))
|
||||
elif commit[19] == '-':
|
||||
form_date += datetime.timedelta(hours=int(commit[20:22]), minutes=int(commit[23:]))
|
||||
commit = format_datetime(form_date - tz, format='short', locale=get_locale())
|
||||
else:
|
||||
commit = version['version']
|
||||
|
||||
content = ub.session.query(ub.User).all()
|
||||
settings = ub.session.query(ub.Settings).first()
|
||||
@@ -3100,6 +2984,8 @@ def configuration_helper(origin):
|
||||
content.config_goodreads_api_key = to_save["config_goodreads_api_key"]
|
||||
if "config_goodreads_api_secret" in to_save:
|
||||
content.config_goodreads_api_secret = to_save["config_goodreads_api_secret"]
|
||||
if "config_updater" in to_save:
|
||||
content.config_updatechannel = int(to_save["config_updater"])
|
||||
if "config_log_level" in to_save:
|
||||
content.config_log_level = int(to_save["config_log_level"])
|
||||
if content.config_logfile != to_save["config_logfile"]:
|
||||
|
||||
Reference in New Issue
Block a user