From 277a65977165f131991dce70e8b435b4431a706c Mon Sep 17 00:00:00 2001
From: Piero Toffanin
Date: Wed, 24 May 2023 14:35:23 -0400
Subject: [PATCH] Revert diagnostic plugin changes
---
coreplugins/diagnostic/plugin.py | 66 ++---
coreplugins/diagnostic/requirements.txt | 1 -
.../diagnostic/templates/diagnostic.html | 252 +++++-------------
3 files changed, 84 insertions(+), 235 deletions(-)
delete mode 100644 coreplugins/diagnostic/requirements.txt
diff --git a/coreplugins/diagnostic/plugin.py b/coreplugins/diagnostic/plugin.py
index 1edda6f1c..bc6068906 100644
--- a/coreplugins/diagnostic/plugin.py
+++ b/coreplugins/diagnostic/plugin.py
@@ -1,8 +1,4 @@
-from rest_framework.response import Response
-from rest_framework import status, permissions
-from rest_framework.decorators import api_view, permission_classes
-
-from app.plugins import PluginBase, Menu, MountPoint, get_current_plugin
+from app.plugins import PluginBase, Menu, MountPoint
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.utils.translation import gettext as _
@@ -34,58 +30,30 @@ def get_memory_stats():
except:
return {}
-def get_diagnostic_stats():
- plugin = get_current_plugin()
- with plugin.python_imports():
- import psutil
-
- # Disk space
- total_disk_space, used_disk_space, free_disk_space = shutil.disk_usage('./')
-
- # CPU Stats
- cpu_percent_used = psutil.cpu_percent()
- cpu_percent_free = 100 - cpu_percent_used
- cpu_freq = psutil.cpu_freq()
-
- diagnostic_stats = {
- 'total_disk_space': total_disk_space,
- 'used_disk_space': used_disk_space,
- 'free_disk_space': free_disk_space,
- 'cpu_percent_used': round(cpu_percent_used, 2),
- 'cpu_percent_free': round(cpu_percent_free, 2),
- 'cpu_freq_current': round(cpu_freq.current / 1000, 2),
- }
-
- # Memory (Linux only)
- memory_stats = get_memory_stats()
- if 'free' in memory_stats:
- diagnostic_stats['free_memory'] = memory_stats['free']
- diagnostic_stats['used_memory'] = memory_stats['used']
- diagnostic_stats['total_memory'] = memory_stats['total']
-
- return diagnostic_stats
class Plugin(PluginBase):
def main_menu(self):
return [Menu(_("Diagnostic"), self.public_url(""), "fa fa-chart-pie fa-fw")]
-
- def api_mount_points(self):
-
- @api_view()
- @permission_classes((permissions.IsAuthenticated,))
- def diagnostic(request):
- diagnostic_stats = get_diagnostic_stats()
- return Response(diagnostic_stats)
-
- return [
- MountPoint('/', diagnostic)
- ]
def app_mount_points(self):
@login_required
def diagnostic(request):
- template_args = get_diagnostic_stats()
- template_args['title'] = 'Diagnostic'
+ # Disk space
+ total_disk_space, used_disk_space, free_disk_space = shutil.disk_usage('./')
+
+ template_args = {
+ 'title': 'Diagnostic',
+ 'total_disk_space': total_disk_space,
+ 'used_disk_space': used_disk_space,
+ 'free_disk_space': free_disk_space
+ }
+
+ # Memory (Linux only)
+ memory_stats = get_memory_stats()
+ if 'free' in memory_stats:
+ template_args['free_memory'] = memory_stats['free']
+ template_args['used_memory'] = memory_stats['used']
+ template_args['total_memory'] = memory_stats['total']
return render(request, self.template_path("diagnostic.html"), template_args)
diff --git a/coreplugins/diagnostic/requirements.txt b/coreplugins/diagnostic/requirements.txt
deleted file mode 100644
index a7e7363b7..000000000
--- a/coreplugins/diagnostic/requirements.txt
+++ /dev/null
@@ -1 +0,0 @@
-psutil==5.9.5
\ No newline at end of file
diff --git a/coreplugins/diagnostic/templates/diagnostic.html b/coreplugins/diagnostic/templates/diagnostic.html
index 9ba76edab..adc399293 100644
--- a/coreplugins/diagnostic/templates/diagnostic.html
+++ b/coreplugins/diagnostic/templates/diagnostic.html
@@ -11,34 +11,20 @@ {% trans 'Storage Space' %}
-
- {% trans 'Free' context 'Megabytes of storage space' %}: {{ free_disk_space|filesizeformat }} |
+
{% trans 'Free' context 'Megabytes of storage space' %}: {{ free_disk_space|filesizeformat }} |
{% trans 'Used' context 'Megabytes of storage space' %}: {{ used_disk_space|filesizeformat }} |
- {% trans 'Total' context 'Megabytes of storage space' %}: {{ total_disk_space|filesizeformat }}
-
+ {% trans 'Total' context 'Megabytes of storage space' %}: {{ total_disk_space|filesizeformat }}
- {% if total_memory %}
-
-
{% trans 'Memory' context 'Computer memory (RAM)' %}
-
-
-
-
- {% trans 'Free' context 'Megabytes of memory space' %}: {{ free_memory|filesizeformat }} |
- {% trans 'Used' context 'Megabytes of memory space' %}: {{ used_memory|filesizeformat }} |
- {% trans 'Total' context 'Megabytes of memory space'%}: {{ total_memory|filesizeformat }}
-
-
- {% endif %}
-
{% trans 'CPU Usage' context 'Computer CPU Usage' %}
+ {% if total_memory %}
+
{% trans 'Memory' context 'Computer memory (RAM)' %}
-
+
-
- {% trans 'CPU Usage' context 'CPU usage percentage' %}: {{ cpu_percent_used }}% |
- {% trans 'CPU Frequency' context 'CPU frequenzy in Heartz' %}: {{ cpu_freq_current }} GHz
-
+
{% trans 'Free' context 'Megabytes of memory space' %}: {{ free_memory|filesizeformat }} |
+ {% trans 'Used' context 'Megabytes of memory space' %}: {{ used_memory|filesizeformat }} |
+ {% trans 'Total' context 'Megabytes of memory space'%}: {{ total_memory|filesizeformat }}
+ {% endif %}
@@ -47,178 +33,74 @@ {% trans 'CPU Usage' context 'Computer CPU Usage' %}
{% trans 'Note!' %} {% blocktrans with win_hyperv_link="
Windows (Hyper-V)" win_wsl2_link="
Windows (WSL2)" mac_link="
MacOS" %}These values might be relative to the virtualization environment in which the application is running, not necessarily the values of the your machine. See instructions for {{ win_hyperv_link }}, {{ win_wsl2_link }}, and {{ mac_link }} for changing these values in a Docker setup.{% endblocktrans %}
{% endblock %}