update.py 1.67 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
Guilhem Saurel's avatar
yapf    
Guilhem Saurel committed
5

6
7
from rainboard.models import Branch, Forge, Project, Repo, Robotpkg
from rainboard.utils import SOURCES, update_robotpkg
Guilhem Saurel's avatar
Guilhem Saurel committed
8
9
10
11
12
13


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

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

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

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

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

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

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

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

Guilhem Saurel's avatar
Guilhem Saurel committed
45
        log(f'\nUpdating keep doc\n')
Guilhem Saurel's avatar
Guilhem Saurel committed
46
        Branch.objects.filter(
Guilhem Saurel's avatar
yapf    
Guilhem Saurel committed
47
48
49
            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

Guilhem Saurel's avatar
Guilhem Saurel committed
51
        log(f'\nDelet perso\n')
Guilhem Saurel's avatar
clean    
Guilhem Saurel committed
52
        call_command('delete_perso')