Commit 3508f71e authored by Rémy HUBSCHER's avatar Rémy HUBSCHER
Browse files

Really fast forward PoC of a package manager.

parent a2f208b4
......@@ -21,6 +21,7 @@
<li>{% fa 'life-ring' 'fa-fw' %} <a href="{% url 'server:backup' %}">{% trans "Manage backups" %}</a></li>
<li>{% fa 'plug' 'fa-fw' %} <a href="{% url 'server:battery' %}">{% trans "Monitor battery" %}</a></li>
<li>{% fa 'wifi' 'fa-fw' %} <a href="{% url 'server:wifi' %}">{% trans "Manage Wi-Fi" %}</a></li>
<li>{% fa 'wifi' 'fa-fw' %} <a href="{% url 'server:packages' %}">{% trans "Manage packages" %}</a></li>
{% endblock third %}
{% extends 'serveradmin/index.html' %}
{% load i18n %}
{% block twothird %}
<h2>{% trans "Install new packages" %}</h2>
{% for package in packages %}
{% if forloop.first %}<ul class="packages-list">{% endif %}
<a class="package-detail" href="{% url 'server:package_detail' %}">
{{ package.title }}
<small>{{ package.tags|join:', ' }}</small>
{% if forloop.last %}
{% endif %}
{% empty %}
<p>{% trans 'No packages yet.' %}</p>
{% endfor %}
{% endblock twothird %}
......@@ -9,4 +9,7 @@ urlpatterns = [
url(r'^battery/$', views.battery, name='battery'),
url(r'^wifi/(?P<ssid>.+)?$', views.wifi, name='wifi'),
url(r'^wifi_history/$', views.wifi_history, name='wifi_history'),
url(r'^packages/$', views.packages, name='packages'),
url(r'^packages/(?P<package_id>.+)?$', views.package_detail,
from subprocess import call
import batinfo
import os
import requests
from django.conf import settings
from django.contrib import messages
from django.http import StreamingHttpResponse
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.utils.translation import ugettext as _
from kinto_client import Client
from ideascube.decorators import staff_member_required
......@@ -167,3 +170,41 @@ def wifi_history(request):
return render(
request, 'serveradmin/wifi_history.html',
{'wifi_list': wifi_list.values()})
def packages(request):
# XXX: Should have a local Kinto cache.
client = Client(server_url='',
bucket='ideascube', collection='packages')
packages = client.get_records()
return render(
request, 'serveradmin/packages.html',
{'packages': packages})
def package_detail(request, package_id):
client = Client(server_url='',
bucket='ideascube', collection='packages')
# XXX: Should use the local Kinto cache.
package = client.get_record(package_id)
# XXX: Should be done asynchroneously.
def download_file(url, path=None):
local_filename = url.split('/')[-1]
if path:
local_filename = os.path.join(path, local_filename)
# NOTE the stream=True parameter
r = requests.get(url, stream=True)
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
return local_filename
download_file(package['data']['url'], '/tmp')
return redirect('library:index')
......@@ -7,6 +7,7 @@ Pillow==3.0.0
# Upstream dbus-python is not pip-installable:
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