checks.py 2.82 KB
Newer Older
Guilhem Saurel's avatar
Guilhem Saurel committed
1
2
3
4
import logging

from django.core.management.base import BaseCommand
from rainboard.models import Project, Robotpkg
Guilhem Saurel's avatar
Guilhem Saurel committed
5
from rainboard.utils import SOURCES
Guilhem Saurel's avatar
Guilhem Saurel committed
6
7
8
9

ALLOWED_MAINTAINERS = ['hpp@laas.fr', 'pinocchio@laas.fr']
ATTRIBUTES = ['homepage', 'license', 'description']
NUM_ATTRS = ['license']
Guilhem Saurel's avatar
Guilhem Saurel committed
10
NOT_GITLAB = ['homepage', 'license']
Guilhem Saurel's avatar
Guilhem Saurel committed
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
40
logger = logging.getLogger('rainboard.management.checks')


def exclude_falsy(qs, attr):
    falsy = 0 if attr in NUM_ATTRS else ''
    return qs.exclude(**{f'{attr}__isnull': True}).exclude(**{attr: falsy})


class Command(BaseCommand):
    help = 'Checks some metadata'

    def handle(self, *args, **options):
        for attr_name in ATTRIBUTES:
            print(f'\nChecking {attr_name}s\n')

            for project in Project.objects.all():
                attr = getattr(project, attr_name)
                if not attr:
                    logger.warning(f'project {project} has no {attr_name}')
                    for rpkg in exclude_falsy(project.robotpkg_set, attr_name):
                        rattr = getattr(rpkg, 'comment' if attr_name == 'description' else attr_name)
                        logger.warning(f'  found in rpkg {rpkg}: {rattr}')
                    for repo in exclude_falsy(project.repo_set, attr_name):
                        rattr = getattr(repo, attr_name)
                        logger.warning(f'  found in repo {repo}: {rattr}')
                    continue
                for rpkg in project.robotpkg_set.exclude(**{attr_name: attr}):
                    rattr = getattr(rpkg, 'comment' if attr_name == 'description' else attr_name)
                    logger.warning(f"project {project}'s rpkg {rpkg} {attr_name}: {attr} Vs. {rattr}")
                for repo in project.repo_set.exclude(**{attr_name: attr}):
Guilhem Saurel's avatar
Guilhem Saurel committed
41
42
                    if repo.forge.source == SOURCES.gitlab and attr in NOT_GITLAB:
                        continue
Guilhem Saurel's avatar
Guilhem Saurel committed
43
44
45
                    rattr = getattr(repo, attr_name)
                    logger.warning(f"project {project}'s repo {repo.git_remote()} {attr_name}: {attr} Vs. {rattr}")

Guilhem Saurel's avatar
flake8    
Guilhem Saurel committed
46
        print('\nChecking robotpkgs\n')
Guilhem Saurel's avatar
Guilhem Saurel committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

        for robotpkg in Robotpkg.objects.all():
            repo, project_repo = robotpkg.master_repository, robotpkg.project.main_repo().url
            if repo and ' ' in repo:
                repo = repo.split()[1]
            if repo != project_repo:
                logger.warning(f'{robotpkg} master_repository: {repo} != {project_repo}')

            version, project_version = robotpkg.pkgversion, robotpkg.project.version
            if 'r' in version:
                version = version.split('r')[0]
            if version != project_version:
                logger.warning(f'{robotpkg} version: {version} != {project_version}')

            if robotpkg.maintainer not in ALLOWED_MAINTAINERS:
                logger.warning(f'{robotpkg} maintainer: {robotpkg.maintainer}')