Browse Source

feat(upgrade): ajoute une commande devérification de MaJ ; fix #150

pull/158/head
François Poulain 1 year ago
committed by Gitea
parent
commit
0d50b414a1
  1. 8
      README.md
  2. 45
      benevalibre/base/management/commands/check_update.py
  3. 8
      benevalibre/settings/base.py
  4. 3
      config.env.example
  5. 4
      requirements/base.txt

8
README.md

@ -139,6 +139,14 @@ location = /favicon.ico {
}
```
### Checking for new releases
Once you deployed benevalibre, you can check for new release using
$ ./manage.py check_update
Giving `--warn` option you get error code when a new release is available.
## Structure
### Overview

45
benevalibre/base/management/commands/check_update.py

@ -0,0 +1,45 @@
import sys
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
import requests
from packaging import version
from benevalibre import __version__
class Command(BaseCommand):
help = 'Check for available upgrade'
def add_arguments(self, parser):
parser.add_argument(
'--warn',
action='store_true',
help='Exit error code when new release is available',
)
def handle(self, *args, **options):
try:
r = requests.get(settings.UPSTREAM_RELEASES)
except Exception as e:
raise CommandError('Unable to fetch upstream versions:', e)
current_version = version.parse(__version__)
upstream_versions = [version.parse(v['name']) for v in r.json()]
release_versions = [
v for v in upstream_versions if not v.is_prerelease
]
if any([v > current_version for v in release_versions]):
self.stdout.write(
self.style.WARNING(
'New version available: {}'.format(max(release_versions))
)
)
if options['warn']:
sys.exit(1)
else:
self.stdout.write(
self.style.SUCCESS('Already to the last available version')
)

8
benevalibre/settings/base.py

@ -276,3 +276,11 @@ OPEN_REGISTRATION = env.bool('OPEN_REGISTRATION', default=True)
# However is has to be moderated by administrators
MODERATED_REGISTRATION = env.bool('MODERATED_REGISTRATION', default=False)
# UPGRADES
# ------------------------------------------------------------------------------
# Upstream source
UPSTREAM_RELEASES = env(
'UPSTREAM_RELEASES',
default='https://forge.cliss21.org/api/v1/repos/cliss21/benevalibre/tags',
)

3
config.env.example

@ -94,3 +94,6 @@
#
# However is has to be moderated by administrators
#MODERATED_REGISTRATION=False
# Upstream source for new release checking
#UPSTREAM_RELEASES=https://forge.cliss21.org/api/v1/repos/cliss21/benevalibre/tags

4
requirements/base.txt

@ -2,6 +2,10 @@
# ------------------------------------------------------------------------------
# Table exports
tablib >=0.11,<0.12 # https://github.com/kennethreitz/tablib
# Api fetching
requests
# Version comparison
packaging
# Django
# ------------------------------------------------------------------------------

Loading…
Cancel
Save
Map all the world