Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Mével committed Dec 19, 2019
2 parents bada1de + fea8493 commit 91c2c4c
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 60 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bash upgrade.sh

# Nabblockly

[Nabblockly](https://github.com/pguyot/nabblockly), une interface de programmation des chorégraphies du lapin par blocs, nécessite une installation supplémentaire, et quelques connaissances en configuration Nginx. De base, il est conçu pour la salle de classe et remplace le site web de configuration du Nabaztag.
[Nabblockly](https://github.com/pguyot/nabblockly), une interface de programmation des chorégraphies du lapin par blocs, est installé sur les images des releases depuis la 0.6.3b et fonctionne sur le port 8080. L'installation est possible sur le port 80 en modifiant la configuration de Nginx.

# Architecture

Expand Down
23 changes: 18 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ if [ $upgrade -eq 1 -a $makerfaire2018 -eq 0 -a -d /home/pi/wm8960 ]; then
make && sudo make install
sudo touch /tmp/pynab.upgrade.reboot
fi
else
if [ $travis_chroot -eq 0 -a ! -e "/dev/ear0" ]; then
echo "Please install ears driver https://github.com/pguyot/tagtagtag-ears"
exit 1
fi
fi

if [ $upgrade -eq 1 ]; then
Expand All @@ -104,6 +99,24 @@ else
fi
fi

if [ $upgrade -eq 1 ]; then
echo "Updating nabblockly" > /tmp/pynab.upgrade
if [ -d /home/pi/pynab/nabblockly ]; then
cd /home/pi/pynab/nabblockly
sudo chown -R ${owner} .
pull=`git pull`
if [ "$pull" != "Already up to date." ]; then
./rebar3 release
fi
else
echo "You may want to install nabblockly from https://github.com/pguyot/nabblockly"
fi
else
if [ $travis_chroot -eq 0 -a ! -d "/home/pi/pynab/nabblockly" ]; then
echo "You may want to install nabblockly from https://github.com/pguyot/nabblockly"
fi
fi

if [ $makerfaire2018 -eq 0 ]; then
if [ $upgrade -eq 1 ]; then
echo "Updating ASR models" > /tmp/pynab.upgrade
Expand Down
2 changes: 1 addition & 1 deletion nabcommon/nabservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ async def perform(self, expiration_date, type, config):
+ "}\r\n"
)
else:
info_packet = '{"type":"info","info_id":"' + service_name + "}\r\n"
info_packet = '{"type":"info","info_id":"' + service_name + '"}\r\n'
self.writer.write(info_packet.encode("utf8"))
if type != "info":
await self.perform_additional(
Expand Down
5 changes: 5 additions & 0 deletions nabd/nabd.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ async def transition_to_idle(self):
async with self.idle_cv:
if len(self.idle_queue) == 0:
await self.set_state("idle")
self.idle_cv.notify()
else:
item = self.idle_queue.popleft()
await self.process_idle_item(item)
Expand Down Expand Up @@ -483,6 +484,8 @@ async def service_loop(self, reader, writer):
packet = json.loads(line.decode("utf8"))
await self.process_packet(packet, writer)
except UnicodeDecodeError as e:
logging.debug(f"Unicode Error {e} with service packet")
logging.debug(f"{packet}")
self.write_packet(
{
"type": "response",
Expand All @@ -493,6 +496,8 @@ async def service_loop(self, reader, writer):
writer,
)
except json.decoder.JSONDecodeError as e:
logging.debug(f"JSON Error {e} with service packet")
logging.debug(f"{packet}")
self.write_packet(
{
"type": "response",
Expand Down
3 changes: 2 additions & 1 deletion nabmastodond/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
NABAZTAG_SERVICE_PRIORITY = 2
NABAZTAG_SERVICE_PRIORITY = 1
NABAZTAG_SERVICE_PAGE = 'home'
17 changes: 10 additions & 7 deletions nabmastodond/locale/fr_FR/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,23 @@ msgstr ""
msgid ""
"First, <strong>create an account for your Nabaztag</strong> on a given "
"Mastodon instance, for example <a href=\"https://mstdn.fr/auth/sign_up\" "
"target=\"_blank\">mstdn.fr</a>."
"target=\"_blank\">mstdn.fr</a> or "
"<a href=\"https://botsin.space/auth/sign_up\" target=\"_blank\">"
"botsin.space</a>."
msgstr ""
"<strong>Créez un compte pour votre Nabaztag</strong> sur une instance "
"Mastodon, par exemple <a href=\"https://mstdn.fr/auth/sign_up\" target="
"\"_blank\">mstdn.fr</a>."
"\"_blank\">mstdn.fr</a> ou "
"<a href=\"https://botsin.space/auth/sign_up\" target=\"_blank\">"
"botsin.space</a>."

#: templates/nabmastodond/settings.html:260
msgid ""
"Connect this account with the \"Connect\" button. If your Nabaztag's account "
"is on a different instance, change the value in the instance box below.</li>"
"Indicate the instance your Nabaztag's account is on in the instance box "
"below and connect this account with the \"Connect\" button."
msgstr ""
"Connectez ce compte avec le bouton \"Connexion\". Si le compte de votre "
"Nabaztag est sur une autre instance, indiquez celle-ci au préalable dans la "
"boîte ci-dessous.</li>"
"Indiquez l'instance de Mastodon sur laquelle est le compte de votre Nabaztag "
"ci-dessous et connectez ce compte avec le bouton \"Connexion\"."

#: templates/nabmastodond/settings.html:264
msgid "Instance"
Expand Down
2 changes: 1 addition & 1 deletion nabmastodond/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class Config(singleton_model.SingletonModel):
instance = models.TextField(default="botsin.space")
instance = models.TextField(default="mstdn.fr")
client_id = models.TextField(null=True)
client_secret = models.TextField(null=True)
redirect_uri = models.TextField(null=True)
Expand Down
3 changes: 3 additions & 0 deletions nabmastodond/nabmastodond.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async def __config(self):

async def reload_config(self):
await self.setup_streaming(True)
await self.setup_initial_state()

def close_streaming(self):
if (
Expand Down Expand Up @@ -421,6 +422,8 @@ async def setup_initial_state(self):
config.spouse_left_ear_position,
config.spouse_right_ear_position,
)
else:
await self.send_stop_listening_to_ears()

def run(self):
super().connect()
Expand Down
4 changes: 2 additions & 2 deletions nabmastodond/templates/nabmastodond/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ <h5 class="modal-title" id="nabmastodon-divorce-title">{% blocktrans with spouse
{% csrf_token %}
<p>{% trans "As we don't want Nabaztag to live in the cloud we're using <a href='https://en.wikipedia.org/wiki/Mastodon_(software)'>Mastodon</a> to connect rabbits (Mastodon is a sort of decentralized Twitter - and Open Source). Currently your Nabaztag is not connected to Mastodon." %}</p>
<ol>
<li>{% blocktrans %}First, <strong>create an account for your Nabaztag</strong> on a given Mastodon instance, for example <a href="https://mstdn.fr/auth/sign_up" target="_blank">mstdn.fr</a>.{% endblocktrans %}</li>
<li>{% blocktrans %}Connect this account with the "Connect" button. If your Nabaztag's account is on a different instance, change the value in the instance box below.</li>{% endblocktrans %}
<li>{% blocktrans %}First, <strong>create an account for your Nabaztag</strong> on a given Mastodon instance, for example <a href="https://mstdn.fr/auth/sign_up" target="_blank">mstdn.fr</a> or <a href="https://botsin.space/auth/sign_up" target="_blank">botsin.space</a>.{% endblocktrans %}</li>
<li>{% blocktrans %}Indicate the instance your Nabaztag's account is on in the instance box below and connect this account with the "Connect" button.{% endblocktrans %}</li>
</ol>
<div class="input-group input-group mb-3">
<div class="input-group-prepend">
Expand Down
10 changes: 5 additions & 5 deletions nabmastodond/tests/nabmastodond_views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_get_settings(self):
self.assertTrue("config" in response.context)
config = Config.load()
self.assertEqual(response.context["config"], config)
self.assertEqual(config.instance, "botsin.space")
self.assertEqual(config.instance, "mstdn.fr")
self.assertEqual(config.client_id, None)
self.assertEqual(config.client_secret, None)
self.assertEqual(config.redirect_uri, None)
Expand All @@ -37,7 +37,7 @@ def test_get_settings(self):
def test_post_connect(self):
c = Client()
config = Config.load()
self.assertEqual(config.instance, "botsin.space")
self.assertEqual(config.instance, "mstdn.fr")
config.client_id = "test_client_id"
config.client_secret = "test_client_secret"
config.save()
Expand Down Expand Up @@ -100,13 +100,13 @@ def test_post_connect(self):

response = c.post(
"/nabmastodond/connect",
{"location": "http://10.10.10.42/", "instance": "botsin.space"},
{"location": "http://10.10.10.42/", "instance": "mstdn.fr"},
)
response_json = response.json()
self.assertTrue("status" in response_json)
self.assertTrue("request_url" in response_json)
config = Config.load()
self.assertEqual(config.instance, "botsin.space")
self.assertEqual(config.instance, "mstdn.fr")
self.assertNotEqual(config.client_id, ms2_client_id)
self.assertNotEqual(config.client_secret, ms2_client_secret)
self.assertEqual(
Expand All @@ -116,7 +116,7 @@ def test_post_connect(self):
def test_delete_connect(self):
c = Client()
config = Config.load()
self.assertEqual(config.instance, "botsin.space")
self.assertEqual(config.instance, "mstdn.fr")
config.client_id = "test_client_id"
config.client_secret = "test_client_secret"
config.redirect_uri = "test_redirect_uri"
Expand Down
2 changes: 1 addition & 1 deletion nabmastodond/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def get(self, request, *args, **kwargs):
config.last_processed_status_date = timezone.now()
config.save()
NabMastodond.signal_daemon()
return HttpResponseRedirect("/services/")
return HttpResponseRedirect("/")


class WeddingView(View):
Expand Down
4 changes: 3 additions & 1 deletion nabweatherd/nabweatherd.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,9 @@ def normalize_weather_class(self, weather_class):
return self.normalize_weather_class(weather_class[:-1])

def get_animation(self, info_data):
if info_data is None or info_data["next_rain"] is None:
if info_data is None:
return None
if info_data["next_rain"] is None:
logging.debug("No rain info, classic weather animation will be displayed")
(weather_class, info_animation) = NabWeatherd.WEATHER_CLASSES[info_data["today_forecast_weather_class"]]
else :
Expand Down
11 changes: 5 additions & 6 deletions nabweb/locale/fr_FR/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ msgstr ""
#: templates/nabweb/index.html:11
msgid ""
"Eventually, explore top navigation bar to configure <a href='/"
"settings/'>Nabaztag services</a>, <a href='/upgrade/'>upgrade software</a> "
"services/'>Nabaztag services</a>, <a href='/upgrade/'>upgrade software</a> "
"or even visit the <a target='_blank' href='https://github.com/nabaztag2018/"
"pynab'>GitHub repository</a> to start hacking, adding features or simply "
"report bugs."
msgstr ""
"Pour configurer les services, allez dans l'onglet <a href='/"
"settings/'>Services</a>, ou <a href='/upgrade/'>Mise à jour</a> pour mettre "
"services/'>Services</a>, ou <a href='/upgrade/'>Mise à jour</a> pour mettre "
"à jour le logiciel. Vous pouvez aussi visiter le <a target='_blank' "
"href='https://github.com/nabaztag2018/pynab'>GitHub repository</a> pour "
"contribuer ou simplement nous reporter des bugs !"
Expand All @@ -141,11 +141,11 @@ msgstr ""

#: templates/nabweb/index.html:14
msgid ""
"And don't forget to try <a href='http://nabaztag.local:8081' "
"And don't forget to try <a href='http://nabaztag.local:8080/' "
"target='_new'>Nabblocky</a> and learn how to code with Nabaztag. It's "
"fantastic."
msgstr ""
"Et n'oubliez pas d'essayer <a href='http://nabaztag.local:8081' "
"Et n'oubliez pas d'essayer <a href='http://nabaztag.local:8080/' "
"target='_new'>Nabblocky</a>. Pour tous ceux qui veulent apprendre à développer avec Nabaztag. "
"C'est fantastique !"

Expand All @@ -160,8 +160,7 @@ msgid ""
"British English are based on distinct voices."
msgstr ""
"La langue est utilisée par les services avec des sons enregistrés. "
"Typiquement, l'américain et le britannique utilisent des voix différentes. "
"le Japonais est intéressant."
"Une nouvelle façon d'apprendre des langues étrangères !"

#: templates/nabweb/index.html:44
msgid "Save"
Expand Down
42 changes: 25 additions & 17 deletions nabweb/templates/nabweb/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ <h1 class="display-3">{% trans "Nabaztag configuration" %}</h1>
<p class="lead">{% trans "You're currently deeply connected with your inner rabbit." %}</p>
<hr class="my-4">
<p>{% trans "First, make sure the language is properly configured below. Maybe create an account to connect your Nabaztag to <a href='https://mstdn.fr/auth/sign_up'>Mastodon</a> where it will join fellow rabbits <small>(for now, this is only used by ear communion service)</small>." %}</p>
<p>{% trans "Eventually, explore top navigation bar to configure <a href='/settings/'>Nabaztag services</a>, <a href='/upgrade/'>upgrade software</a> or even visit the <a target='_blank' href='https://github.com/nabaztag2018/pynab'>GitHub repository</a> to start hacking, adding features or simply report bugs." %}</p>
<p>{% trans "Eventually, explore top navigation bar to configure <a href='/services/'>Nabaztag services</a>, <a href='/upgrade/'>upgrade software</a> or even visit the <a target='_blank' href='https://github.com/nabaztag2018/pynab'>GitHub repository</a> to start hacking, adding features or simply report bugs." %}</p>

<p>{% trans "You can trigger some services with your voice. The processing is done locally and you need to push the button long enough to hear a 'bip' (keep the button pushed), then wait a couple of seconds (We'll have a look at this later!) then speak and when you're done just release the button. Your service should be played shortly!" %}</p>
<p>{% trans "And don't forget to try <a href='http://nabaztag.local:8081' target='_new'>Nabblocky</a> and learn how to code with Nabaztag. It's fantastic." %}</p>



<p>{% trans "And don't forget to try <a href='http://nabaztag.local:8080/' target='_new'>Nabblocky</a> and learn how to code with Nabaztag. It's fantastic." %}</p>
</div>
</div>
<div class="row justify-content-center">
Expand Down Expand Up @@ -47,19 +44,30 @@ <h5 class="card-title">{% trans "Language" %}</h5>
</div>
</div>
</form>
<script type="text/javascript">
$(function() {
var form = $('#language-settings form');
var saveBtn = form.find('button.save-button');
var resetBtn = form.find('button.reset-button');
var url = form.attr('action');
form.find('select').on('change', function() {
saveBtn.removeClass('disabled');
resetBtn.removeClass('disabled');
});
});
</script>
</div>
</div>
</div>
{% for service in services %}
<div class="row justify-content-center">
<div class="settings col-xl-8 col-lg-10 col-md-10 mb-3" data-url="/{{ service }}/settings"></div>
</div>
{% endfor %}
<script type="text/javascript">
$(function() {
var form = $('#language-settings form');
var saveBtn = form.find('button.save-button');
var resetBtn = form.find('button.reset-button');
var url = form.attr('action');
form.find('select').on('change', function() {
saveBtn.removeClass('disabled');
resetBtn.removeClass('disabled');
});
$("div.settings").each(function(index, element) {
var url = $(element).data('url');
$.get(url, function(data) {
$(element).html(data);
});
});
});
</script>
{% endblock %}
1 change: 0 additions & 1 deletion nabweb/templates/nabweb/services/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
{% endfor %}
<script type="text/javascript">
$(function() {
console.log("{{ services }}");
$("div.settings").each(function(index, element) {
var url = $(element).data('url');
$.get(url, function(data) {
Expand Down
3 changes: 3 additions & 0 deletions nabweb/templates/nabweb/upgrade/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ <h5>{% trans "Current versions" %}</h5>
{% if rfid_driver %}
{% include "nabweb/upgrade/_repository.html" with repo=ears_driver repo_name="RFID reader driver" %}
{% endif %}
{% if nabblockly %}
{% include "nabweb/upgrade/_repository.html" with repo=nabblockly repo_name="Nabblockly" %}
{% endif %}
</dl>
</div>
<div class="card-footer">
Expand Down
36 changes: 25 additions & 11 deletions nabweb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,32 @@ def get(self, request, *args, **kwargs):
context = self.get_context()
return render(request, self.template_name(), context=context)

@staticmethod
def get_services(page):
services = []
for config in apps.get_app_configs():
if hasattr(config.module, 'NABAZTAG_SERVICE_PRIORITY'):
service_page = 'services'
if hasattr(config.module, 'NABAZTAG_SERVICE_PAGE'):
service_page = config.module.NABAZTAG_SERVICE_PAGE
if service_page == page:
services.append({
'priority': config.module.NABAZTAG_SERVICE_PRIORITY,
'name': config.name
})
services_sorted = sorted(services, key=lambda s: s['priority'])
services_names = map(lambda s: s['name'], services_sorted)
return services_names

class NabWebView(BaseView):
def template_name(self):
return "nabweb/index.html"

def get_context(self):
context = super().get_context()
context["services"] = BaseView.get_services('home')
return context

def post(self, request, *args, **kwargs):
config = Config.load()
config.locale = request.POST["locale"]
Expand All @@ -64,16 +86,7 @@ def template_name(self):

def get_context(self):
context = super().get_context()
services = []
for config in apps.get_app_configs():
if hasattr(config.module, 'NABAZTAG_SERVICE_PRIORITY'):
services.append({
'priority': config.module.NABAZTAG_SERVICE_PRIORITY,
'name': config.name
})
services_sorted = sorted(services, key=lambda s: s['priority'])
services_names = map(lambda s: s['name'], services_sorted)
context["services"] = services_names
context["services"] = BaseView.get_services('services')
return context

class NabWebSytemInfoView(BaseView):
Expand Down Expand Up @@ -137,7 +150,8 @@ class GitInfo:
REPOSITORIES = {
"pynab": ".",
"sound_driver": "../wm8960",
"ears_driver": "../tagtagtag-ears/"
"ears_driver": "../tagtagtag-ears/",
"nabblockly": "nabblockly"
}

@staticmethod
Expand Down

0 comments on commit 91c2c4c

Please sign in to comment.