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 logging
import re
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings from django.conf import settings
...@@ -16,6 +17,7 @@ from .utils import SOURCES, TARGETS, slugify_with_dots ...@@ -16,6 +17,7 @@ from .utils import SOURCES, TARGETS, slugify_with_dots
logger = logging.getLogger('rainboard.models') logger = logging.getLogger('rainboard.models')
MAIN_BRANCHES = ['master', 'devel'] MAIN_BRANCHES = ['master', 'devel']
CMAKE_FIELDS = {'name': 'name', 'description': 'description', 'url': 'homepage', 'version': 'version'}
class Article(NamedModel): class Article(NamedModel):
...@@ -154,13 +156,18 @@ class Project(Links, NamedModel, TimeStampedModel): ...@@ -154,13 +156,18 @@ class Project(Links, NamedModel, TimeStampedModel):
license = models.ForeignKey(License, on_delete=models.SET_NULL, blank=True, null=True) license = models.ForeignKey(License, on_delete=models.SET_NULL, blank=True, null=True)
homepage = models.URLField(max_length=200, blank=True, null=True) homepage = models.URLField(max_length=200, blank=True, null=True)
articles = models.ManyToManyField(Article) articles = models.ManyToManyField(Article)
description = models.TextField()
version = models.CharField(max_length=20, blank=True, null=True)
# TODO: release github ↔ robotpkg # TODO: release github ↔ robotpkg
def get_absolute_url(self): def get_absolute_url(self):
return reverse('rainboard:project', kwargs={'slug': self.slug}) 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): def git(self):
path = settings.RAINBOARD_GITS / self.main_namespace.slug / self.slug path = self.git_path()
if not path.exists(): if not path.exists():
logger.info(f'Creating repo for {self.main_namespace.slug}/{self.slug}') logger.info(f'Creating repo for {self.main_namespace.slug}/{self.slug}')
return git.Repo.init(path) return git.Repo.init(path)
...@@ -198,6 +205,18 @@ class Project(Links, NamedModel, TimeStampedModel): ...@@ -198,6 +205,18 @@ class Project(Links, NamedModel, TimeStampedModel):
def main_branch(self): def main_branch(self):
return 'devel' if 'devel' in self.git().heads else 'master' 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): class Repo(TimeStampedModel):
name = models.CharField(max_length=200) name = models.CharField(max_length=200)
......
...@@ -20,17 +20,13 @@ ...@@ -20,17 +20,13 @@
{% endif %} {% endif %}
</div> </div>
{% if project.homepage %}<a href="{{ project.homepage }}">{{ project.homepage }}</a>{% endif %}
<dl class="dl-horizontal"> <dl class="dl-horizontal">
<dt>Homepage</dt> <dt>Main forge</dt> <dd>{{ project.main_forge.get_link }}</dd>
<dd>{{ project.homepage|default:"—" }}</dd> <dt>Main namespace</dt> <dd>{{ project.main_namespace }}</dd>
<dt>Main forge</dt> <dt>Main branch</dt> <dd>{{ project.main_branch }}</dd>
<dd>{{ project.main_forge }}</dd> <dt>Description</dt> <dd>{{ project.description }}</dd>
<dt>Main namespace</dt> <dt>Version</dt> <dd>{{ project.version|default:"—" }}</dd>
<dd>{{ project.main_namespace }}</dd> <dt>Homepage</dt> <dd>{% if project.homepage %}<a href="{{ project.homepage }}">{{ project.homepage }}</a>{% else %}—{% endif %}</dd>
<dt>Main branch</dt>
<dd>{{ project.main_branch }}</dd>
</dl> </dl>
</div> </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