Skip to content

Commit

Permalink
v8.15.11 bugfix release
Browse files Browse the repository at this point in the history
  • Loading branch information
kizniche committed Oct 18, 2023
1 parent a49f77c commit 73b5dbe
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 16 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 8.15.11 (2023.10.18)

This release fixes a bug that prevents installing some dependencies.

### Bugfixes

- Fix issue installing some dependencies
- Fix automatically reloading the frontend when adding certain Widgets


## 8.15.10 (2023.10.15)

This release is a bugfix release to fix issues related to installing Mycodo on the latest Raspberry Pi OS (Debian 12, Bookworm).
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Mycodo

Environmental Regulation System

Latest version: 8.15.10
Latest version: 8.15.11

Mycodo is open source software for the Raspberry Pi that couples inputs and outputs in interesting ways to sense and manipulate the environment.

Expand Down
2 changes: 1 addition & 1 deletion mycodo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
from config_translations import TRANSLATIONS as T

MYCODO_VERSION = '8.15.10'
MYCODO_VERSION = '8.15.11'
ALEMBIC_VERSION = '16b28ef31b5b'

# FORCE UPGRADE MASTER
Expand Down
23 changes: 16 additions & 7 deletions mycodo/mycodo_flask/routes_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,22 @@ def install_dependencies(dependencies):
for each_dep in dependencies:
if each_dep[2] == 'bash-commands':
for each_command in each_dep[1]:
command = "{cmd} | ts '[%Y-%m-%d %H:%M:%S]' >> {log} 2>&1".format(
cmd=each_command,
log=DEPENDENCY_LOG_FILE)
cmd_out, cmd_err, cmd_status = cmd_output(
command, timeout=600, cwd="/tmp")
logger.info("Command returned: out: {}, error: {}, status: {}".format(
cmd_out, cmd_err, cmd_status))
try:
with open(DEPENDENCY_LOG_FILE, 'a') as f:
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
f.write(f"\n[{now}] Executing command: {each_command}\n")

command = "{cmd} | ts '[%Y-%m-%d %H:%M:%S]' >> {log} 2>&1".format(
cmd=each_command,
log=DEPENDENCY_LOG_FILE)
cmd_out, cmd_err, cmd_status = cmd_output(
command, user='root', timeout=600, cwd="/tmp")

with open(DEPENDENCY_LOG_FILE, 'a') as f:
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
f.write(f"\n[{now}] Command returned: out: {cmd_out}, error: {cmd_err}, status: {cmd_status}\n")
except:
logger.exception("Executing command")
else:
cmd = "{pth}/mycodo/scripts/mycodo_wrapper install_dependency {dep}" \
" | ts '[%Y-%m-%d %H:%M:%S]' >> {log} 2>&1".format(
Expand Down
25 changes: 22 additions & 3 deletions mycodo/mycodo_flask/routes_dashboard.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# coding=utf-8
"""collection of Page endpoints."""
import flask_login
import logging
import os

import flask_login
import subprocess
from flask import redirect, render_template, request, url_for
from flask.blueprints import Blueprint
from sqlalchemy import and_

from mycodo.config import INSTALL_DIRECTORY
from mycodo.config import PATH_HTML_USER
from mycodo.databases.models import (PID, Camera, Conditional, Conversion,
CustomController, Dashboard,
Expand Down Expand Up @@ -125,7 +126,11 @@ def page_dashboard(dashboard_id):

# Widget
elif form_base.widget_add.data:
unmet_dependencies = utils_dashboard.widget_add(form_base, request.form)
unmet_dependencies, reload_flask = utils_dashboard.widget_add(form_base, request.form)
if not unmet_dependencies and reload_flask:
return redirect(url_for(
'routes_dashboard.restart_flask_auto_advance_page',
dashboard_id=this_dashboard.unique_id))
elif form_base.widget_mod.data:
utils_dashboard.widget_mod(form_base, request.form)
elif form_base.widget_delete.data:
Expand Down Expand Up @@ -319,3 +324,17 @@ def page_dashboard(dashboard_id):
form_base=form_base,
form_dashboard=form_dashboard,
widget=widget)


@blueprint.route('/reload_flask/<dashboard_id>')
@flask_login.login_required
def restart_flask_auto_advance_page(dashboard_id=""):
"""Wait then automatically load next page"""
logger.info("Reloading frontend in 5 seconds")

cmd = f"sleep 5 && {INSTALL_DIRECTORY}/mycodo/scripts/mycodo_wrapper frontend_reload 2>&1"
subprocess.Popen(cmd, shell=True)
logger.info("Rendering wait page")

return render_template('pages/wait_and_autoload.html',
dashboard_id=dashboard_id)
21 changes: 21 additions & 0 deletions mycodo/mycodo_flask/templates/pages/wait_and_autoload.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "layout.html" %}

{% set dashboard_dict = dict() %}

{% block title %} - Please Wait 10 Seconds{% endblock %}

{% block head %}
<meta http-equiv="refresh" content="10;url=/dashboard/{{dashboard_id}}" />
{% endblock %}

{% block body %}
<!-- Route: /dashboard -->
<div class="container">
{% include 'flash_messages.html' %}
</div>

<div class="container-fluid" style="text-align: center">
To add this Widget, the Frontend needs to reload. Please wait for the frontend to reload. You will be automatically redirected after 10 seconds.
</div>

{% endblock %}
8 changes: 4 additions & 4 deletions mycodo/mycodo_flask/utils/utils_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ def widget_add(form_base, request_form):
controller=TRANSLATIONS['widget']['title'])
error = []

reload_flask = False

dict_widgets = parse_widget_information()

if form_base.widget_type.data:
Expand Down Expand Up @@ -230,9 +232,7 @@ def dict_has_value(key):
# It has already handled its first request, any changes will not be applied consistently.
# Make sure all imports, decorators, functions, etc. needed to set up the application are done before running it.
if Widget.query.filter(Widget.graph_type == widget_name).count() == 1:
cmd = f"{INSTALL_DIRECTORY}/mycodo/scripts/mycodo_wrapper frontend_reload 2>&1"
init = subprocess.Popen(cmd, shell=True)
init.wait()
reload_flask = True

if not current_app.config['TESTING']:
# Refresh widget settings
Expand All @@ -252,7 +252,7 @@ def dict_has_value(key):
for each_error in error:
flash(each_error, "error")

return dep_unmet
return dep_unmet, reload_flask


def widget_mod(form_base, request_form):
Expand Down

0 comments on commit 73b5dbe

Please sign in to comment.