populate.py 1.32 KB
Newer Older
Guilhem Saurel's avatar
Guilhem Saurel committed
1
2
import logging

3
import httpx
Guilhem Saurel's avatar
Guilhem Saurel committed
4
5
from django.core.management import call_command
from django.core.management.base import BaseCommand
Guilhem Saurel's avatar
yapf    
Guilhem Saurel committed
6

7
from rainboard.models import Forge, License, Repo
Guilhem Saurel's avatar
Guilhem Saurel committed
8

Guilhem Saurel's avatar
Guilhem Saurel committed
9
LICENSES = 'https://raw.githubusercontent.com/spdx/license-list-data/master/json/licenses.json'
Guilhem Saurel's avatar
Guilhem Saurel committed
10
logger = logging.getLogger('rainboard.management.populate')
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
11

Guilhem Saurel's avatar
Guilhem Saurel committed
12

Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
13
14
15
16
class Command(BaseCommand):
    help = 'populates licenses, projets, namespaces and repos from forges'

    def handle(self, *args, **options):
Guilhem Saurel's avatar
flake8    
Guilhem Saurel committed
17
        logger.info('updating licenses')
18
        for data in httpx.get(LICENSES).json()['licenses']:
Guilhem Saurel's avatar
yapf    
Guilhem Saurel committed
19
20
21
22
23
            License.objects.get_or_create(spdx_id=data['licenseId'],
                                          defaults={
                                              'name': data['name'],
                                              'url': data['detailsUrl']
                                          })
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
24

Guilhem Saurel's avatar
flake8    
Guilhem Saurel committed
25
        logger.info('updating forges')
Guilhem Saurel's avatar
Guilhem Saurel committed
26
        for forge in Forge.objects.order_by('source'):
Guilhem Saurel's avatar
Guilhem Saurel committed
27
            logger.info(f' updating {forge}')
Guilhem Saurel's avatar
initial  
Guilhem Saurel committed
28
            forge.get_projects()
Guilhem Saurel's avatar
Guilhem Saurel committed
29

Guilhem Saurel's avatar
flake8    
Guilhem Saurel committed
30
        logger.info('updating repos')
Guilhem Saurel's avatar
Guilhem Saurel committed
31
32
33
        for repo in Repo.objects.all():
            logger.info(f' updating {repo}')
            repo.api_update()
Guilhem Saurel's avatar
clean    
Guilhem Saurel committed
34
35
36
37
38

        call_command('delete_perso')
        call_command('fetch')
        call_command('robotpkg')
        call_command('cmake')