robotpkg.py 1.04 KB
Newer Older
1
import itertools
Guilhem Saurel's avatar
Guilhem Saurel committed
2
3
4
import logging

from django.conf import settings
Guilhem Saurel's avatar
Guilhem Saurel committed
5
6
from django.core.management.base import BaseCommand
from rainboard.models import Project, Robotpkg
7
from rainboard.utils import update_robotpkg
Guilhem Saurel's avatar
Guilhem Saurel committed
8

Guilhem Saurel's avatar
Guilhem Saurel committed
9
10
11
12
13
14
15
16
17
18
logger = logging.getLogger('rainboard.robotpkg')


class Command(BaseCommand):
    help = 'Populate database with Robotpkg data'

    def handle(self, *args, **options):
        path = settings.RAINBOARD_RPKG

        logger.info('Pulling Robotpkg repositories')
19
        update_robotpkg(path)
Guilhem Saurel's avatar
Guilhem Saurel committed
20
21

        for project in Project.objects.all():
22
            for slug in [project.slug, project.slug.replace('_', '-')]:
Guilhem Saurel's avatar
Guilhem Saurel committed
23
24
25
26
                for pkg in itertools.chain(
                        path.glob(f'*/{slug}{project.suffix}'), path.glob(f'*/py-{slug}{project.suffix}')):
                    obj, created = Robotpkg.objects.get_or_create(
                        name=pkg.name, category=pkg.parent.name, project=project)
27
28
29
                    if created:
                        logger.info(f'{project} found in {pkg}')
                        obj.update(pull=False)