update.py 1.45 KB
Newer Older
Guilhem Saurel's avatar
Guilhem Saurel committed
1
2
3
import logging

from django.conf import settings
Guilhem Saurel's avatar
clean    
Guilhem Saurel committed
4
from django.core.management import call_command
Guilhem Saurel's avatar
Guilhem Saurel committed
5
from django.core.management.base import BaseCommand
Guilhem Saurel's avatar
Guilhem Saurel committed
6
from django.db.models import F, Q
Guilhem Saurel's avatar
Guilhem Saurel committed
7
8

from rainboard.models import Branch, Project, Repo, Robotpkg
9
from rainboard.utils import update_robotpkg
Guilhem Saurel's avatar
Guilhem Saurel committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

logger = logging.getLogger('rainboard.management.update')


class Command(BaseCommand):
    help = 'Update the DB'

    def handle(self, *args, **options):
        logger.info(f'\nUpdating all repos\n')
        for repo in Repo.objects.all():
            logger.info(f' {repo}')
            repo.update()

        logger.info(f'\nUpdating all branches\n')
        for branch in Branch.objects.all():
            logger.info(f' {branch}')
            branch.update(pull=False)

        logger.info(f'\nPulling Robotpkg\n')
29
        update_robotpkg(settings.RAINBOARD_RPKG)
Guilhem Saurel's avatar
Guilhem Saurel committed
30
31
32
33
34
35
36
37
38
39

        logger.info(f'\nUpdating Robotpkg\n')
        for robotpkg in Robotpkg.objects.all():
            logger.info(f' {robotpkg}')
            robotpkg.update(pull=False)

        logger.info(f'\nUpdating all projects\n')
        for project in Project.objects.all():
            logger.info(f' {project}')
            project.update()
Guilhem Saurel's avatar
clean    
Guilhem Saurel committed
40

Guilhem Saurel's avatar
Guilhem Saurel committed
41
42
43
44
45
        Branch.objects.filter(
                Q(name__endswith='master') | Q(name__endswith='devel'),
                repo__namespace=F('project__main_namespace'), repo__forge__source=SOURCES.gitlab
                ).update(keep_doc=True)

Guilhem Saurel's avatar
clean    
Guilhem Saurel committed
46
        call_command('delete_perso')