bundles/octoprint: add update check
This commit is contained in:
parent
91f2fd839b
commit
4f5e462c94
4 changed files with 70 additions and 0 deletions
41
bundles/octoprint/files/check_octoprint_update
Normal file
41
bundles/octoprint/files/check_octoprint_update
Normal file
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from requests import get
|
||||
from sys import exit
|
||||
|
||||
api_key = '${api_key}'
|
||||
|
||||
try:
|
||||
json = get('http://[::1]:22030/plugin/softwareupdate/check', headers={'X-Api-Key': api_key}).json()
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
exit(3)
|
||||
|
||||
updates = set()
|
||||
errors = set()
|
||||
|
||||
for identifier, info in json['information'].items():
|
||||
if info['updateAvailable']:
|
||||
updates.add(info['displayName'])
|
||||
|
||||
if not json['environment']['supported']:
|
||||
errors.add('OctoPrint runs in an unsupported environment!')
|
||||
|
||||
if not json['storage']['sufficient']:
|
||||
errors.add('OctoPrint reports insufficient storage!')
|
||||
|
||||
|
||||
for error in sorted(errors):
|
||||
print(error)
|
||||
|
||||
if len(updates) > 0:
|
||||
print('Updates available: {}'.format(', '.join(sorted(updates))))
|
||||
|
||||
|
||||
if len(errors) > 0:
|
||||
exit(2)
|
||||
elif len(updates) > 0:
|
||||
exit(1)
|
||||
else:
|
||||
print('OK')
|
||||
exit(0)
|
Loading…
Add table
Add a link
Reference in a new issue