update.py 2.22 KB
Newer Older
1
2
from datetime import timedelta

Guilhem Saurel's avatar
Guilhem Saurel committed
3
from django.conf import settings
Guilhem Saurel's avatar
clean    
Guilhem Saurel committed
4
from django.core.management import call_command
Guilhem Saurel's avatar
Guilhem Saurel committed
5
from django.core.management.base import BaseCommand
Guilhem Saurel's avatar
Guilhem Saurel committed
6
from django.db.models import F, Q
7
from django.utils import timezone
Guilhem Saurel's avatar
yapf    
Guilhem Saurel committed
8

9
from rainboard.models import Branch, Forge, Image, Project, Repo, Robotpkg
10
from rainboard.utils import SOURCES, update_robotpkg
Guilhem Saurel's avatar
Guilhem Saurel committed
11
12
13
14
15
16


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

    def handle(self, *args, **options):
Guilhem Saurel's avatar
Guilhem Saurel committed
17
        def log(message):
Guilhem Saurel's avatar
Guilhem Saurel committed
18
            self.stdout.write(message)
Guilhem Saurel's avatar
Guilhem Saurel committed
19

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

Guilhem Saurel's avatar
Guilhem Saurel committed
25
        log(f'\nUpdating all repos\n')
26
        for repo in Repo.objects.filter(project__archived=False, project__from_gepetto=True):
Guilhem Saurel's avatar
Guilhem Saurel committed
27
            log(f' {repo}')
Guilhem Saurel's avatar
Guilhem Saurel committed
28
29
            repo.update()

Guilhem Saurel's avatar
Guilhem Saurel committed
30
        log(f'\nUpdating all branches\n')
Guilhem Saurel's avatar
Guilhem Saurel committed
31
        for branch in Branch.objects.filter(project__archived=False, project__from_gepetto=True):
Guilhem Saurel's avatar
details    
Guilhem Saurel committed
32
            log(f' {branch.project} - {branch}')
Guilhem Saurel's avatar
Guilhem Saurel committed
33
34
            branch.update(pull=False)

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

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

Guilhem Saurel's avatar
Guilhem Saurel committed
43
        log(f'\nUpdating Robotpkg\n')
44
        for robotpkg in Robotpkg.objects.filter(project__archived=False, project__from_gepetto=True):
Guilhem Saurel's avatar
Guilhem Saurel committed
45
            log(f' {robotpkg}')
Guilhem Saurel's avatar
Guilhem Saurel committed
46
47
            robotpkg.update(pull=False)

Guilhem Saurel's avatar
Guilhem Saurel committed
48
        log(f'\nUpdating keep doc\n')
Guilhem Saurel's avatar
yapf    
Guilhem Saurel committed
49
50
51
        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
52

Guilhem Saurel's avatar
typo    
Guilhem Saurel committed
53
        log(f'\nDelete perso\n')
Guilhem Saurel's avatar
clean    
Guilhem Saurel committed
54
        call_command('delete_perso')
55

Guilhem Saurel's avatar
Guilhem Saurel committed
56
57
58
        log(f'\nclean obsolete Images\n')
        Image.objects.filter(robotpkg__project__archived=True).delete()

59
        log(f'\nLook for missing images\n')
60
        for img in Image.objects.filter(created__lt=timezone.now() - timedelta(days=7), target__active=True):
61
            log(f' {img}')