Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Fast check for Raspberry Pi model, closes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Huber committed Jul 27, 2016
1 parent e224b50 commit d14cace
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 31 deletions.
25 changes: 25 additions & 0 deletions upribox_interface/lib/info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
import json
import os


class HardwareInfo:
Expand Down Expand Up @@ -65,6 +66,30 @@ def __str__(self):
return '\n'.join((self.model, str(self.wifi_devices)))


class ModelInfo:

MODEL_PATH = '/proc/device-tree/model'

def __init__(self):
self.model = self.get_model_str()

def get_model_str(self):
if not os.path.exists(self.MODEL_PATH):
return None

with open(self.MODEL_PATH) as model_file:
model = model_file.read().strip()
return model

def runs_on_pi3(self):
if not self.model:
return False
elif u'Pi 3' in self.model:
return True
else:
return False


class UpdateStatus:

ANSIBLE_PULL_LOG_FILE = '/var/tmp/log/ansible-pull.log'
Expand Down
Binary file modified upribox_interface/wlan/locale/en/LC_MESSAGES/django.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion upribox_interface/wlan/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ msgstr ""

#: wlan/templates/ninja.html:39
msgid "Das Ninja WiFi kann auf dem Raspberry Pi 3 nicht aktiviert werden."
msgstr "The Ninja WiFi can not be aktived on the Raspberry Pi 3."
msgstr "The Ninja WiFi can not be activated on the Raspberry Pi 3."

#: wlan/templates/ninja.html:54 wlan/templates/silent.html:18
msgid "Ein-/Ausschalten"
Expand Down
38 changes: 10 additions & 28 deletions upribox_interface/wlan/templates/ninja.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,15 @@ <h1>{% trans "Ninja Modus" %}</h1>
Wir empfehlen die Nutzung des Tor-Browser-Bundle (Download f&uuml;r <a href="{{ windows }}">Windows</a>, <a href="{{ macos }}">Mac OS</a> oder <a href="{{ linux }}">Linux</a>). Sollten Sie keine M&ouml;glichkeit haben, den Tor-Browser zu nutzen, k&ouml;nnen Sie als Alternative den Ninja Modus einschalten. Dieser gew&auml;hrleistet aber nicht das volle Surferlebnis (etwa durch langsame Geschwindigkeit und Webseiten in fremder Sprache).
{% endblocktrans %}</strong></p>

<script>
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
var http = new XMLHttpRequest();
var url = "{% url 'upri_check_pi3' %}"
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
result = JSON.parse(http.responseText);
if (result['pi3'].localeCompare("yes") == 0) {
document.getElementById("ninja_toggle").innerHTML = '<h2 class="warning-message">{% trans "Das Ninja WiFi kann auf dem Raspberry Pi 3 nicht aktiviert werden." %}</h2>';
}
}
}
http.send('');

</script>

<div class="row clearfix" id="ninja_toggle">

<div class="row clearfix">
{% if pi3 %}

<h2 class="warning-message">{% trans "Das Ninja WiFi kann auf dem Raspberry Pi 3 nicht aktiviert werden." %}</h2>

{% else %}


<div class="col-2 col-2-main js-col-2-main">

<form>
Expand Down Expand Up @@ -88,5 +69,6 @@ <h2 class="icon i-information js-info-trigger">
<a href="#" title="{% trans "Information ausblenden" %}" class="info-out i-arrow js-info-trigger">{% trans "Information ausblenden" %}</a>
</aside>
</div>
{% endif %}
</div>
{% endblock %}
8 changes: 6 additions & 2 deletions upribox_interface/wlan/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from wlan import jobs as wlanjobs
from django.core.urlresolvers import reverse
from lib import utils
from lib.info import HardwareInfo
from lib.info import HardwareInfo, ModelInfo
from django.http import HttpResponse

# Get an instance of a logger
Expand All @@ -36,9 +36,13 @@ def ninja(request):
else:
form = WlanForm(utils.get_fact('wlan','ninja','ssid'))

model_info = ModelInfo()
pi3 = model_info.runs_on_pi3()

context.push({
'form': form,
'messagestore': jobs.get_messages()})
'messagestore': jobs.get_messages(),
'pi3': pi3})

return render_to_response("ninja.html", context)

Expand Down

0 comments on commit d14cace

Please sign in to comment.