update.py 1.69 KB
Newer Older
Guilhem Saurel's avatar
Guilhem Saurel committed
1
from django.conf import settings
Guilhem Saurel's avatar
clean    
Guilhem Saurel committed
2
from django.core.management import call_command
Guilhem Saurel's avatar
Guilhem Saurel committed
3
from django.core.management.base import BaseCommand
Guilhem Saurel's avatar
Guilhem Saurel committed
4
from django.db.models import F, Q
5
6
from rainboard.models import Branch, Forge, Project, Repo, Robotpkg
from rainboard.utils import SOURCES, update_robotpkg
Guilhem Saurel's avatar
Guilhem Saurel committed
7
8
9
10
11
12


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

    def handle(self, *args, **options):
Guilhem Saurel's avatar
Guilhem Saurel committed
13
        def log(message):
Guilhem Saurel's avatar
Guilhem Saurel committed
14
            self.stdout.write(message)
Guilhem Saurel's avatar
Guilhem Saurel committed
15

Guilhem Saurel's avatar
Guilhem Saurel committed
16
        log(f'updating forges')
17
        for forge in Forge.objects.order_by('source'):
Guilhem Saurel's avatar
Guilhem Saurel committed
18
            log(f' updating {forge}')
19
20
            forge.get_projects()

Guilhem Saurel's avatar
Guilhem Saurel committed
21
        log(f'\nUpdating all repos\n')
Guilhem Saurel's avatar
Guilhem Saurel committed
22
        for repo in Repo.objects.all():
Guilhem Saurel's avatar
Guilhem Saurel committed
23
            log(f' {repo}')
Guilhem Saurel's avatar
Guilhem Saurel committed
24
25
            repo.update()

Guilhem Saurel's avatar
Guilhem Saurel committed
26
        log(f'\nUpdating all branches\n')
Guilhem Saurel's avatar
Guilhem Saurel committed
27
        for branch in Branch.objects.all():
Guilhem Saurel's avatar
details    
Guilhem Saurel committed
28
            log(f' {branch.project} - {branch}')
Guilhem Saurel's avatar
Guilhem Saurel committed
29
30
            branch.update(pull=False)

Guilhem Saurel's avatar
Guilhem Saurel committed
31
        log(f'\nPulling Robotpkg\n')
32
        update_robotpkg(settings.RAINBOARD_RPKG)
Guilhem Saurel's avatar
Guilhem Saurel committed
33

34
35
        log(f'\nUpdating gepetto projects\n')
        for project in Project.objects.filter(from_gepetto=True, archived=False):
Guilhem Saurel's avatar
Guilhem Saurel committed
36
            log(f' {project}')
37
            project.update(only_main_branches=False)
Guilhem Saurel's avatar
Guilhem Saurel committed
38

Guilhem Saurel's avatar
Guilhem Saurel committed
39
        log(f'\nUpdating Robotpkg\n')
Guilhem Saurel's avatar
Guilhem Saurel committed
40
        for robotpkg in Robotpkg.objects.all():
Guilhem Saurel's avatar
Guilhem Saurel committed
41
            log(f' {robotpkg}')
Guilhem Saurel's avatar
Guilhem Saurel committed
42
43
            robotpkg.update(pull=False)

Guilhem Saurel's avatar
Guilhem Saurel committed
44
        log(f'\nUpdating keep doc\n')
Guilhem Saurel's avatar
Guilhem Saurel committed
45
46
47
48
49
        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
Guilhem Saurel committed
50
        log(f'\nDelet perso\n')
Guilhem Saurel's avatar
clean    
Guilhem Saurel committed
51
        call_command('delete_perso')