update.py 1.44 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
        log(f'\nUpdating Robotpkg\n')
Guilhem Saurel's avatar
Guilhem Saurel committed
32
        for robotpkg in Robotpkg.objects.all():
Guilhem Saurel's avatar
Guilhem Saurel committed
33
            log(f' {robotpkg}')
Guilhem Saurel's avatar
Guilhem Saurel committed
34
35
            robotpkg.update(pull=False)

Guilhem Saurel's avatar
Guilhem Saurel committed
36
        log(f'\nUpdating all projects\n')
Guilhem Saurel's avatar
Guilhem Saurel committed
37
        for project in Project.objects.all():
Guilhem Saurel's avatar
Guilhem Saurel committed
38
            log(f' {project}')
Guilhem Saurel's avatar
Guilhem Saurel committed
39
            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')