mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-06 10:19:55 +02:00
Fix #308: Licenses
This commit is contained in:
parent
e97f1f0e0b
commit
e5b46402f8
29 changed files with 5595 additions and 66 deletions
|
@ -0,0 +1,34 @@
|
|||
from django.core.management.base import BaseCommand, CommandError
|
||||
import requests.exceptions
|
||||
|
||||
from funkwhale_api.music import licenses
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Check that specified licenses URLs are actually reachable"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
errored = []
|
||||
objs = licenses.LICENSES
|
||||
total = len(objs)
|
||||
for i, data in enumerate(objs):
|
||||
self.stderr.write("{}/{} Checking {}...".format(i + 1, total, data["code"]))
|
||||
response = requests.get(data["url"])
|
||||
try:
|
||||
response.raise_for_status()
|
||||
except requests.exceptions.RequestException:
|
||||
self.stderr.write("!!! Error while fetching {}!".format(data["code"]))
|
||||
errored.append((data, response))
|
||||
|
||||
if errored:
|
||||
self.stdout.write("{} licenses were not reachable!".format(len(errored)))
|
||||
for row, response in errored:
|
||||
self.stdout.write(
|
||||
"- {}: error {} at url {}".format(
|
||||
row["code"], response.status_code, row["url"]
|
||||
)
|
||||
)
|
||||
|
||||
raise CommandError()
|
||||
else:
|
||||
self.stdout.write("All licenses are valid and reachable :)")
|
Loading…
Add table
Add a link
Reference in a new issue