Skip to content

Commit

Permalink
Merge branch 'master' of github.com:WEEE-Open/pesto
Browse files Browse the repository at this point in the history
  • Loading branch information
il-palmi committed Oct 16, 2024
2 parents 41dfc80 + ad357f4 commit 63a1378
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: 3.12

- name: Install Python dependencies
run: pip install black
Expand Down
32 changes: 15 additions & 17 deletions pinolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,7 @@ def show_smart_data(self):
else:
self.selected_drive = self.selected_drive.text()
if self.selected_drive in self.smart_results:
self.smart_widgets[self.selected_drive] = SmartWidget(self.selected_drive,
self.smart_results[self.selected_drive]
)
self.smart_widgets[self.selected_drive] = SmartWidget(self.selected_drive, self.smart_results[self.selected_drive])
self.smart_widgets[self.selected_drive].close_signal.connect(self.remove_smart_widget)

except BaseException as exc:
Expand Down Expand Up @@ -569,10 +567,10 @@ def cannolo(self, std=False, drives=None):

def upload_to_tarallo_selection(self, std: bool = False):
# TODO: check if it's really working
#for row in self.get_selected_drive_rows():
#if row[1] == "":
# self.upload_to_tarallo(row[0])
#self.selected_drive = self.selected_drive.text();
# for row in self.get_selected_drive_rows():
# if row[1] == "":
# self.upload_to_tarallo(row[0])
# self.selected_drive = self.selected_drive.text();
self.selected_drive = self.diskTable.item(self.diskTable.currentRow(), 0)

if not std:
Expand All @@ -585,7 +583,7 @@ def upload_to_tarallo_selection(self, std: bool = False):
return
elif self.diskTable.item(self.diskTable.currentRow(), 1).text() != "":
return
loc, ok = input_dialog("Location");
loc, ok = input_dialog("Location")

# If no location is provided or cancel is selected,
# cancel the operation
Expand Down Expand Up @@ -838,7 +836,7 @@ def gui_update(self, cmd: str, params: str):
print(f"GUI: Ignored exception while parsing {cmd}, expected JSON but this isn't: {params}")

match cmd:
case 'queue_status' | 'get_queue':
case "queue_status" | "get_queue":
if cmd == "queue_status":
params = [params]
for param in params:
Expand Down Expand Up @@ -895,7 +893,7 @@ def gui_update(self, cmd: str, params: str):
if "text" in param:
status_cell.setToolTip(param["text"])

case 'get_disks':
case "get_disks":
drives = params
if len(drives) <= 0:
self.diskTable.setRowCount(0)
Expand All @@ -907,10 +905,10 @@ def gui_update(self, cmd: str, params: str):
self.diskTable.resizeColumnToContents(0)
self.diskTable.resizeColumnToContents(1)

case 'smartctl' | 'queued_smartctl':
case "smartctl" | "queued_smartctl":
self.smart_results[params["disk"]] = {"output": params["output"], "status": params["status"]}

case ' connection_failed':
case " connection_failed":
message = params["reason"]
if not self.remoteMode:
print("GUI: Connection Failed: Local server not running.")
Expand All @@ -921,29 +919,29 @@ def gui_update(self, cmd: str, params: str):
message = "Cannot find BASILICO server.\nCheck if it's running in the " "targeted machine."
warning_dialog(message, dialog_type="ok")

case 'connection_lost':
case "connection_lost":
self.statusBar().showMessage(f"⚠ Connection lost. Press the reload button to reconnect.")
self.queueTable.setRowCount(0)
self.diskTable.setRowCount(0)

case 'connection_made':
case "connection_made":
self.statusBar().showMessage(f"Connected to {params['host']}:{params['port']}")

case 'list_iso':
case "list_iso":
self.dialog = CannoloDialog(self.settingsDialog, PATH, params)
if self.manual_cannolo:
self.dialog.update.connect(self.use_cannolo_img)
self.manual_cannolo = False
else:
self.dialog.update.connect(self.settingsDialog.set_default_cannolo)

case 'error':
case "error":
message = f"{params['message']}"
if "command" in params:
message += f":\n{params['command']}"
critical_dialog(message, dialog_type="ok")

case 'error_that_can_be_manually_fixed':
case "error_that_can_be_manually_fixed":
message = params["message"]
warning_dialog(message, dialog_type="ok")

Expand Down
32 changes: 10 additions & 22 deletions widgets/smart.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
from typing import Any, Iterable, List, Dict, Union
from PyQt5 import uic
from PyQt5.QtCore import pyqtSignal, QAbstractItemModel, QModelIndex, QObject, Qt, QFileInfo
from PyQt5.QtWidgets import (
QWidget,
QPushButton,
QTreeView,
QLineEdit,
QTreeWidget
)
from PyQt5.QtWidgets import QWidget, QPushButton, QTreeView, QLineEdit, QTreeWidget


class SmartWidget(QWidget):
Expand Down Expand Up @@ -43,9 +37,9 @@ def setup(self):
# status line setup
self.statusLineEdit.setText(self.smart_status)
match self.smart_status:
case 'ok':
case "ok":
self.statusLineEdit.setStyleSheet("background-color: green; color: black;")
case 'old':
case "old":
self.statusLineEdit.setStyleSheet("background-color: yellow; color: black;")
case _:
self.statusLineEdit.setStyleSheet("background-color: red; color: black;")
Expand Down Expand Up @@ -119,9 +113,7 @@ def value_type(self, value):
self._value_type = value

@classmethod
def load(
cls, value: Union[List, Dict], parent: "TreeItem" = None, sort=True
) -> "TreeItem":
def load(cls, value: Union[List, Dict], parent: "TreeItem" = None, sort=True) -> "TreeItem":
"""Create a 'root' TreeItem from a nested list or a nested dictonary
Examples:
Expand Down Expand Up @@ -161,7 +153,7 @@ def load(


class JsonModel(QAbstractItemModel):
""" An editable model of Json data """
"""An editable model of Json data"""

def __init__(self, parent: QObject = None):
super().__init__(parent)
Expand All @@ -170,7 +162,7 @@ def __init__(self, parent: QObject = None):
self._headers = ("key", "value")

def clear(self):
""" Clear data from the model """
"""Clear data from the model"""
self.load({})

def load(self, document: dict):
Expand All @@ -180,9 +172,7 @@ def load(self, document: dict):
document (dict): JSON-compatible dictionary
"""

assert isinstance(
document, (dict, list, tuple)
), "`document` must be of dict, list or tuple, " f"not {type(document)}"
assert isinstance(document, (dict, list, tuple)), "`document` must be of dict, list or tuple, " f"not {type(document)}"

self.beginResetModel()

Expand All @@ -199,8 +189,8 @@ def clean_document_from_bloat(self, document: dict):
for key in IGNORE_SMART_RESULTS:
document.pop(key, None)

if 'ata_smart_attributes' in document:
attributes = {}
if "ata_smart_attributes" in document:
attributes = {}
for key in document["ata_smart_attributes"]["table"]:
attributes[key["name"]] = key["value"]
document.pop("ata_smart_attributes", None)
Expand Down Expand Up @@ -254,9 +244,7 @@ def setData(self, index: QModelIndex, value: Any, role: Qt.ItemDataRole):

return False

def headerData(
self, section: int, orientation: Qt.Orientation, role: Qt.ItemDataRole
):
def headerData(self, section: int, orientation: Qt.Orientation, role: Qt.ItemDataRole):
"""Override from QAbstractItemModel
For the JsonModel, it returns only data for columns (orientation = Horizontal)
Expand Down

0 comments on commit 63a1378

Please sign in to comment.