Commit 21103fe5 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

Robotpkg

parent cb5fc7a0
import logging
from django.core.management.base import BaseCommand
from django.conf import settings
from rainboard.models import Project, Robotpkg
import git
logger = logging.getLogger('rainboard.robotpkg')
class Command(BaseCommand):
help = 'Populate database with Robotpkg data'
def handle(self, *args, **options):
path = settings.RAINBOARD_RPKG
logger.info('Pulling Robotpkg repositories')
git.Repo(str(path / '.git')).remotes.origin.pull()
git.Repo(str(path / 'wip' / '.git')).remotes.origin.pull()
for project in Project.objects.all():
for pkg in path.glob(f'*/{project.slug}'):
logger.info(f'{project} found in {pkg}')
obj, created = Robotpkg.objects.get_or_create(name=pkg.name, category=pkg.parent.name, project=project)
if created:
obj.update(pull=False)
# Generated by Django 2.0.1 on 2018-01-31 15:48
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('rainboard', '0009_project_version'),
]
operations = [
migrations.RemoveField(
model_name='robotpkgdependency',
name='project',
),
migrations.AddField(
model_name='robotpkg',
name='category',
field=models.CharField(default='', max_length=50),
preserve_default=False,
),
migrations.AddField(
model_name='robotpkg',
name='comment',
field=models.TextField(default=''),
preserve_default=False,
),
migrations.AddField(
model_name='robotpkg',
name='description',
field=models.TextField(default=''),
preserve_default=False,
),
migrations.AddField(
model_name='robotpkg',
name='maintainer',
field=models.CharField(default='', max_length=200),
),
migrations.AddField(
model_name='robotpkg',
name='master_repository',
field=models.CharField(default='', max_length=200),
),
migrations.AddField(
model_name='robotpkg',
name='master_sites',
field=models.CharField(default='', max_length=200),
),
migrations.AddField(
model_name='robotpkg',
name='pkgbase',
field=models.CharField(default='', max_length=50),
),
migrations.AddField(
model_name='robotpkg',
name='pkgversion',
field=models.CharField(default='', max_length=20),
),
migrations.AddField(
model_name='robotpkg',
name='private',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='robotpkg',
name='updated',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AlterField(
model_name='robotpkg',
name='homepage',
field=models.URLField(default=''),
),
migrations.AlterField(
model_name='robotpkg',
name='project',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='rainboard.Project'),
),
migrations.DeleteModel(
name='RobotpkgDependency',
),
]
import logging
import re
from subprocess import check_output
from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings
......@@ -17,7 +18,11 @@ from .utils import SOURCES, TARGETS, slugify_with_dots
logger = logging.getLogger('rainboard.models')
MAIN_BRANCHES = ['master', 'devel']
CMAKE_FIELDS = {'name': 'name', 'description': 'description', 'url': 'homepage', 'version': 'version'}
RPKG_URL = 'http://robotpkg.openrobots.org'
RPKG_LICENSES = {'gnu-lgpl-v3': 'LGPL-3.0', 'gnu-lgpl-v2': 'LGPL-2.0', 'mit': 'MIT', 'gnu-gpl-v3': 'GPL-3.0',
'2-clause-bsd': 'BSD-2-Clause'}
RPKG_FIELDS = ['PKGBASE', 'PKGVERSION', 'MASTER_SITES', 'MASTER_REPOSITORY', 'MAINTAINER', 'COMMENT', 'HOMEPAGE']
CMAKE_FIELDS = {'NAME': 'name', 'DESCRIPTION': 'description', 'URL': 'homepage', 'VERSION': 'version'}
class Article(NamedModel):
......@@ -298,13 +303,13 @@ class Repo(TimeStampedModel):
return f'{self.forge.slug}/{self.namespace.slug}'
def git(self):
git = self.project.git()
git_repo = self.project.git()
remote = self.git_remote()
try:
return git.remote(remote)
return git_repo.remote(remote)
except ValueError:
logger.info(f'Creating remote {remote}')
return git.create_remote(remote, self.get_clone_url())
return git_repo.create_remote(remote, self.get_clone_url())
def main_branch(self):
return self.project.branch_set.get(name=f'{self.git_remote()}/{self.default_branch}')
......@@ -368,14 +373,56 @@ class SystemDependency(NamedModel):
target = models.PositiveSmallIntegerField(choices=enum_to_choices(TARGETS))
class RobotpkgDependency(NamedModel):
class Robotpkg(NamedModel):
project = models.ForeignKey(Project, on_delete=models.CASCADE)
category = models.CharField(max_length=50)
pkgbase = models.CharField(max_length=50, default='')
pkgversion = models.CharField(max_length=20, default='')
master_sites = models.CharField(max_length=200, default='')
master_repository = models.CharField(max_length=200, default='')
maintainer = models.CharField(max_length=200, default='')
comment = models.TextField()
homepage = models.URLField(max_length=200, default='')
class Robotpkg(NamedModel):
project = models.OneToOneField(Project, on_delete=models.CASCADE)
license = models.ForeignKey(License, on_delete=models.SET_NULL, blank=True, null=True)
homepage = models.URLField(max_length=200, blank=True, null=True)
private = models.BooleanField(default=False)
description = models.TextField()
updated = models.DateTimeField(blank=True, null=True)
def main_page(self):
if self.category != 'wip':
return f'{RPKG_URL}/robotpkg/{self.category}/{self.name}'
def build_page(self):
path = '-wip/wip' if self.category == 'wip' else f'/{self.category}'
return f'{RPKG_URL}/rbulk/robotpkg{path}/{self.name}'
def update(self, pull=True):
path = settings.RAINBOARD_RPKG
repo = git.Repo(str(path / 'wip' / '.git' if self.category == 'wip' else path / '.git'))
if pull:
repo.remotes.origin.pull()
cwd = path / self.category / self.name
for field in RPKG_FIELDS:
cmd = ['make', 'show-var', f'VARNAME={field}']
self.__dict__[field.lower()] = check_output(cmd, cwd=cwd).decode().strip()
repo_path = self.name if self.category == 'wip' else f'{self.category}/{self.name}'
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()
if license in RPKG_LICENSES:
self.license = License.objects.get(spdx_id=RPKG_LICENSES[license])
else:
logger.warning(f'Unknown robotpkg license: {license}')
self.private = bool(check_output(['make', 'show-var', f'VARNAME=RESTRICTED'], cwd=cwd).decode().strip())
with (cwd / 'DESCR').open() as f:
self.description = f.read().strip()
self.save()
class RobotpkgBuild(TimeStampedModel):
......
......@@ -30,10 +30,32 @@
</dl>
</div>
<h2>Robotpkg</h2>
{% for robotpkg in project.robotpkg_set.all %}
<h3>{{ robotpkg.category }} / {{ robotpkg }}</h3>
{{ robotpkg.description }}
<dl class="dl-horizontal">
<dt>Base</dt> <dd>{{ robotpkg.pkgbase }}</dd>
<dt>Version</dt> <dd>{{ robotpkg.pkgversion }}</dd>
<dt>Master Sites</dt> <dd>{{ robotpkg.master_sites }}</dd>
<dt>Master Repository</dt> <dd>{{ robotpkg.master_repository }}</dd>
<dt>Maintainer</dt> <dd>{{ robotpkg.maintainer }}</dd>
<dt>Comment</dt> <dd>{{ robotpkg.comment }}</dd>
<dt>License</dt> <dd>{{ robotpkg.license }}</dd>
<dt>Updated</dt> <dd>{{ robotpkg.updated }}</dd>
<dt>Main page</dt> <dd><a href="{{ robotpkg.main_page }}">{{ robotpkg.main_page }}</a></dd>
<dt>Build page</dt> <dd><a href="{{ robotpkg.build_page }}">{{ robotpkg.build_page }}</a></dd>
</dl>
{% endfor %}
<h2>Répos</h2>
{% render_table repos %}
<h2>Robotpkg</h2>
{% endblock %}
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