update.py 1.17 KB
Newer Older
Guilhem Saurel's avatar
Guilhem Saurel committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import logging

from django.conf import settings
from django.core.management.base import BaseCommand

import git

from rainboard.models import Branch, Project, Repo, Robotpkg

logger = logging.getLogger('rainboard.management.update')


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

    def handle(self, *args, **options):
        logger.info(f'\nUpdating all repos\n')
        for repo in Repo.objects.all():
            logger.info(f' {repo}')
            repo.update()

        logger.info(f'\nUpdating all branches\n')
        for branch in Branch.objects.all():
            logger.info(f' {branch}')
            branch.update(pull=False)

        logger.info(f'\nPulling Robotpkg\n')
        git.Repo(str(settings.RAINBOARD_RPKG / '.git')).remotes.origin.pull()
        git.Repo(str(settings.RAINBOARD_RPKG / 'wip' / '.git')).remotes.origin.pull()

        logger.info(f'\nUpdating Robotpkg\n')
        for robotpkg in Robotpkg.objects.all():
            logger.info(f' {robotpkg}')
            robotpkg.update(pull=False)

        logger.info(f'\nUpdating all projects\n')
        for project in Project.objects.all():
            logger.info(f' {project}')
            project.update()