update.py 1.58 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
Guilhem Saurel committed
5
6

from rainboard.models import Branch, Project, Repo, Robotpkg
Guilhem Saurel's avatar
Guilhem Saurel committed
7
from rainboard.utils import update_robotpkg, SOURCES
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
15
16
17
18
        def log(message):
            if int(options['verbosity']) > 1:
                self.stdout.write(message)

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

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

Guilhem Saurel's avatar
Guilhem Saurel committed
28
        log(f'\nPulling Robotpkg\n')
29
        update_robotpkg(settings.RAINBOARD_RPKG)
Guilhem Saurel's avatar
Guilhem Saurel committed
30

Guilhem Saurel's avatar
Guilhem Saurel committed
31
32
33
34
35
36
37
38
39
        log(f'\nUpdating all projects\n')
        for project in Project.objects.all():
            log(f' {project}')
            try:
                project.update()
            except Branch.DoesNotExist:
                project.update_branches()
                project.update()

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
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
clean    
Guilhem Saurel committed
50
        call_command('delete_perso')