Commit cb5fc7a0 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

parse CMakeLists

parent 663d7f3d
from django.core.management.base import BaseCommand
from rainboard.models import Project
class Command(BaseCommand):
help = 'Get informations from CMakeLists.txt on all projects'
def handle(self, *args, **options):
for project in Project.objects.all():
project.cmake()
# Generated by Django 2.0.1 on 2018-01-30 17:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('rainboard', '0007_auto_20180130_1457'),
]
operations = [
migrations.AddField(
model_name='project',
name='description',
field=models.TextField(default=''),
preserve_default=False,
),
]
# Generated by Django 2.0.1 on 2018-01-30 17:13
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('rainboard', '0008_project_description'),
]
operations = [
migrations.AddField(
model_name='project',
name='version',
field=models.CharField(blank=True, max_length=20, null=True),
),
]
import logging
import re
from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings
......@@ -16,6 +17,7 @@ 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'}
class Article(NamedModel):
......@@ -154,13 +156,18 @@ class Project(Links, NamedModel, TimeStampedModel):
license = models.ForeignKey(License, on_delete=models.SET_NULL, blank=True, null=True)
homepage = models.URLField(max_length=200, blank=True, null=True)
articles = models.ManyToManyField(Article)
description = models.TextField()
version = models.CharField(max_length=20, blank=True, null=True)
# TODO: release github ↔ robotpkg
def get_absolute_url(self):
return reverse('rainboard:project', kwargs={'slug': self.slug})
def git_path(self):
return settings.RAINBOARD_GITS / self.main_namespace.slug / self.slug
def git(self):
path = settings.RAINBOARD_GITS / self.main_namespace.slug / self.slug
path = self.git_path()
if not path.exists():
logger.info(f'Creating repo for {self.main_namespace.slug}/{self.slug}')
return git.Repo.init(path)
......@@ -198,6 +205,18 @@ class Project(Links, NamedModel, TimeStampedModel):
def main_branch(self):
return 'devel' if 'devel' in self.git().heads else 'master'
def cmake(self):
filename = self.git_path() / 'CMakeLists.txt'
if not filename.exists():
return
with filename.open() as f:
content = f.read()
for key, value in CMAKE_FIELDS.items():
search = re.search(f'set\s*\(\s*project_{key}\s+([^)]+)*\)', content, re.I)
if search:
self.__dict__[value] = search.groups()[0].strip(''' \r\n\t'"''')
self.save()
class Repo(TimeStampedModel):
name = models.CharField(max_length=200)
......
......@@ -20,17 +20,13 @@
{% endif %}
</div>
{% if project.homepage %}<a href="{{ project.homepage }}">{{ project.homepage }}</a>{% endif %}
<dl class="dl-horizontal">
<dt>Homepage</dt>
<dd>{{ project.homepage|default:"—" }}</dd>
<dt>Main forge</dt>
<dd>{{ project.main_forge }}</dd>
<dt>Main namespace</dt>
<dd>{{ project.main_namespace }}</dd>
<dt>Main branch</dt>
<dd>{{ project.main_branch }}</dd>
<dt>Main forge</dt> <dd>{{ project.main_forge.get_link }}</dd>
<dt>Main namespace</dt> <dd>{{ project.main_namespace }}</dd>
<dt>Main branch</dt> <dd>{{ project.main_branch }}</dd>
<dt>Description</dt> <dd>{{ project.description }}</dd>
<dt>Version</dt> <dd>{{ project.version|default:"—" }}</dd>
<dt>Homepage</dt> <dd>{% if project.homepage %}<a href="{{ project.homepage }}">{{ project.homepage }}</a>{% else %}—{% endif %}</dd>
</dl>
</div>
......
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