Commit 824aee99 authored by Guilhem Saurel's avatar Guilhem Saurel

flake8

parent 9102fb02
Pipeline #10587 passed with stage
in 1 minute and 15 seconds
......@@ -3,8 +3,11 @@ from ipaddress import ip_address, ip_network
from django.conf import settings
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
from django.shortcuts import reverse
from rest_framework import permissions
ALLOWED_URLS = ('admin', 'accounts', 'gh')
def ip_laas(request: HttpRequest) -> bool:
"""check if request comes from settings.LAAS_NETWORKS."""
......@@ -21,7 +24,6 @@ class LAASPermsMiddleware:
or if the user is authenticated,
or if the request comes from a trusted IP.
"""
ALLOWED_URLS = ('admin', 'accounts', 'gh')
allowed = (any(request.path.startswith(f'/{url}/') for url in ALLOWED_URLS)
or request.user and request.user.is_authenticated
or request.method in permissions.SAFE_METHODS and ip_laas(request))
......
......@@ -43,7 +43,7 @@ class Command(BaseCommand):
rattr = getattr(repo, attr_name)
logger.warning(f"project {project}'s repo {repo.git_remote()} {attr_name}: {attr} Vs. {rattr}")
print(f'\nChecking robotpkgs\n')
print('\nChecking robotpkgs\n')
for robotpkg in Robotpkg.objects.all():
repo, project_repo = robotpkg.master_repository, robotpkg.project.main_repo().url
......
......@@ -11,5 +11,5 @@ class Command(BaseCommand):
help = 'Delete personnal projects'
def handle(self, *args, **options):
logger.info(f'removing unwanted projects:')
logger.info('removing unwanted projects:')
logger.info(str(Project.objects.filter(main_namespace__group=False).delete()))
......@@ -10,7 +10,7 @@ class Command(BaseCommand):
help = 'Fetch all remotes'
def handle(self, *args, **options):
logger.info(f'Fetching all repos')
logger.info('Fetching all repos')
for project in Project.objects.all():
logger.info(f' updating branches for {project}')
project.update_branches(main=False, pull=True)
......@@ -14,7 +14,7 @@ class Command(BaseCommand):
help = 'populates licenses, projets, namespaces and repos from forges'
def handle(self, *args, **options):
logger.info(f'updating licenses')
logger.info('updating licenses')
for data in requests.get(LICENSES).json()['licenses']:
License.objects.get_or_create(spdx_id=data['licenseId'],
defaults={
......@@ -22,12 +22,12 @@ class Command(BaseCommand):
'url': data['detailsUrl']
})
logger.info(f'updating forges')
logger.info('updating forges')
for forge in Forge.objects.order_by('source'):
logger.info(f' updating {forge}')
forge.get_projects()
logger.info(f'updating repos')
logger.info('updating repos')
for repo in Repo.objects.all():
logger.info(f' updating {repo}')
repo.api_update()
......
......@@ -58,46 +58,46 @@ class Command(BaseCommand):
def log(message):
self.stdout.write(message)
log(f'updating forges')
log('updating forges')
for forge in Forge.objects.order_by('source'):
log(f' updating {forge}')
forge.get_projects()
log(f'\nUpdating all repos\n')
log('\nUpdating all repos\n')
for repo in Repo.objects.filter(project__archived=False, project__main_namespace__from_gepetto=True):
log(f' {repo}')
repo.update()
log(f'\nUpdating all branches\n')
log('\nUpdating all branches\n')
for branch in Branch.objects.filter(project__archived=False, project__main_namespace__from_gepetto=True):
log(f' {branch.project} - {branch}')
branch.update(pull=False)
log(f'\nPulling Robotpkg\n')
log('\nPulling Robotpkg\n')
update_robotpkg(settings.RAINBOARD_RPKG)
log(f'\nUpdating gepetto projects\n')
log('\nUpdating gepetto projects\n')
for project in Project.objects.filter(archived=False, main_namespace__from_gepetto=True):
log(f' {project}')
project.update(only_main_branches=False)
log(f'\nUpdating Robotpkg\n')
log('\nUpdating Robotpkg\n')
for robotpkg in Robotpkg.objects.filter(project__archived=False, project__main_namespace__from_gepetto=True):
log(f' {robotpkg}')
robotpkg.update(pull=False)
log(f'\nUpdating keep doc\n')
log('\nUpdating keep doc\n')
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)
log(f'\nDelete perso\n')
log('\nDelete perso\n')
call_command('delete_perso')
log(f'\nclean obsolete Images\n')
log('\nclean obsolete Images\n')
Image.objects.filter(robotpkg__project__archived=True).delete()
log(f'\nLook for missing images\n')
log('\nLook for missing images\n')
for img in Image.objects.filter(created__lt=timezone.now() - timedelta(days=7), target__active=True):
log(f' {img}')
......
import json
import logging
import re
from functools import cmp_to_key
from subprocess import check_output
from django.conf import settings
......@@ -844,12 +843,12 @@ class Robotpkg(NamedModel):
last_commit = next(repo.iter_commits(paths=repo_path, max_count=1))
self.updated = last_commit.authored_datetime
license = check_output(['make', 'show-var', f'VARNAME=LICENSE'], cwd=cwd).decode().strip()
license = check_output(['make', 'show-var', 'VARNAME=LICENSE'], cwd=cwd).decode().strip()
if license in RPKG_LICENSES:
self.license = License.objects.get(spdx_id=RPKG_LICENSES[license])
else:
logger.warning(f'Unknown robotpkg license: {license}')
self.public = not bool(check_output(['make', 'show-var', f'VARNAME=RESTRICTED'], cwd=cwd).decode().strip())
self.public = not bool(check_output(['make', 'show-var', 'VARNAME=RESTRICTED'], cwd=cwd).decode().strip())
with (cwd / 'DESCR').open() as f:
self.description = f.read().strip()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment