Patchwork [bitbake-devel,21/94] bitbake: webhob: add layer information to the database

login
register
mail settings
Submitter Alexandru DAMIAN
Date Sept. 24, 2013, 4:51 p.m.
Message ID <40ec5cb935911dba08b21d0db9acd1722d52dcdf.1380041477.git.alexandru.damian@intel.com>
Download mbox | patch
Permalink /patch/58729/
State New
Headers show

Comments

Alexandru DAMIAN - Sept. 24, 2013, 4:51 p.m.
From: Calin Dragomir <calinx.l.dragomir@intel.com>

This patch adds the layer information to the database. Using the
values stored in BBLAYERS it retrieves all the information needed
for the database fields.
It also includes a hardcoded mapping to deal with the URLs that
are different from the standard naming convention.
---
 bitbake/lib/bb/ui/buildinfohelper.py              | 45 +++++++++++++++++++++++
 bitbake/lib/webhob/bldviewer/templates/layer.html | 34 +++++++++++++++++
 bitbake/lib/webhob/bldviewer/urls.py              |  1 +
 bitbake/lib/webhob/bldviewer/views.py             | 10 ++++-
 4 files changed, 89 insertions(+), 1 deletion(-)
 create mode 100644 bitbake/lib/webhob/bldviewer/templates/layer.html

Patch

diff --git a/bitbake/lib/bb/ui/buildinfohelper.py b/bitbake/lib/bb/ui/buildinfohelper.py
index a0da2e1..2da38e2 100644
--- a/bitbake/lib/bb/ui/buildinfohelper.py
+++ b/bitbake/lib/bb/ui/buildinfohelper.py
@@ -336,6 +336,49 @@  class ORMWrapper(object):
 
         return layer_info
 
+    def _get_layer_dict(self, layer_path):
+
+        layer_info = {}
+        layer_name = layer_path.split('/')[-1]
+        layer_url = 'http://layers.openembedded.org/layerindex/layer/{layer}/'
+        layer_url_name = self._get_url_map_name(layer_name)
+
+        layer_info['name'] = layer_name
+        layer_info['local_path'] = layer_path
+        layer_info['layer_index_url'] = layer_url.format(layer=layer_url_name)
+
+        return layer_info
+
+    def _get_url_map_name(self, layer_name):
+        """ Some layers have a different name on openembedded.org site,
+            this method returns the correct name to use in the URL
+        """
+
+        url_name = layer_name
+        url_mapping = {'meta': 'openembedded-core'}
+
+        for key in url_mapping.keys():
+            if key == layer_name:
+                url_name = url_mapping[key]
+
+        return url_name
+
+    def _save_layer_object(self, layer_path):
+
+        layer_information = self._get_layer_dict(layer_path)
+
+        layer_object = Layer.objects.get_or_create(
+                            name=layer_information['name'],
+                            local_path=layer_information['local_path'],
+                            layer_index_url=layer_information['layer_index_url'])
+
+        layer_object[0].save()
+
+    def store_layer_info(self):
+        layers = self.server.runCommand(["getVariable", "BBLAYERS"])[0].strip().split(" ")
+        for layer_path in layers:
+            self._save_layer_object(layer_path)
+
 
 class BuildInfoHelper(object):
     """ This class gathers the build information from the server and sends it
@@ -352,6 +395,8 @@  class BuildInfoHelper(object):
 
     def store_started_build(self, event):
 
+        self.orm_wrapper.store_layer_info()
+
         machine_information = self.orm_wrapper.get_machine_information()
         machine_obj = self.orm_wrapper.create_machine_object(machine_information)
 
diff --git a/bitbake/lib/webhob/bldviewer/templates/layer.html b/bitbake/lib/webhob/bldviewer/templates/layer.html
new file mode 100644
index 0000000..905a781
--- /dev/null
+++ b/bitbake/lib/webhob/bldviewer/templates/layer.html
@@ -0,0 +1,34 @@ 
+<html>
+
+	<head>
+		<title>WebHob Layer page</title>
+	</head>
+
+<body>
+	<h1>WebHob Layers</h1>
+
+	<table border="1">
+
+	{% load projecttags %}
+
+		<tr>
+			<th>Name</th>
+			<th>Local Path</th>
+			<th>Layer Index URL</th>
+		</tr>
+
+		{% for layer in layers %}
+
+		<tr>
+			<td>{{layer.name}}</td>
+			<td>{{layer.local_path}}</td>
+			<td><a href='{{layer.layer_index_url}}'>{{layer.layer_index_url}}</a></td>
+		</tr>
+
+		{% endfor %}
+
+	</table>
+
+</body>
+
+</html>
diff --git a/bitbake/lib/webhob/bldviewer/urls.py b/bitbake/lib/webhob/bldviewer/urls.py
index 335885c..8d5dc6e 100644
--- a/bitbake/lib/webhob/bldviewer/urls.py
+++ b/bitbake/lib/webhob/bldviewer/urls.py
@@ -3,5 +3,6 @@  from django.conf.urls import patterns, include, url
 
 urlpatterns = patterns('bldviewer.views',
         url(r'^$', 'build', name='build'),
+        url(r'^layers/$', 'layer', name='layer'),
         url(r'^(?P<build_id>\d+)/$', 'task', name='task'),
 )
diff --git a/bitbake/lib/webhob/bldviewer/views.py b/bitbake/lib/webhob/bldviewer/views.py
index 292a638..f40d396 100644
--- a/bitbake/lib/webhob/bldviewer/views.py
+++ b/bitbake/lib/webhob/bldviewer/views.py
@@ -1,5 +1,5 @@ 
 from django.shortcuts import render
-from orm.models import Build, Task
+from orm.models import Build, Task, Layer
 
 
 def build(request):
@@ -18,3 +18,11 @@  def task(request, build_id):
     context = {'tasks': tasks}
 
     return render(request, template, context)
+
+def layer(request):
+    template = 'layer.html'
+    layer_info = Layer.objects.all()
+
+    context = {'layers': layer_info}
+
+    return render(request, template, context)