update.py 1.6 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
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
15
16
17
        def log(message):
            if int(options['verbosity']) > 1:
                self.stdout.write(message)

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

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

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

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

Guilhem Saurel's avatar
Guilhem Saurel committed
36
37
38
        log(f'\nUpdating all projects\n')
        for project in Project.objects.all():
            log(f' {project}')
Guilhem Saurel's avatar
Guilhem Saurel committed
39
            project.update()
Guilhem Saurel's avatar
Guilhem Saurel committed
40

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

Guilhem Saurel's avatar
Guilhem Saurel committed
46
47
48
49
50
        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
51
        call_command('delete_perso')