modified the "current" label in a caffe-version-widget to show if barista...

modified the "current" label in a caffe-version-widget to show if barista needs to be restarted first after switching the version
parent d69e86c1
......@@ -2,6 +2,7 @@ import os
from backend.barista.utils.logger import LogCaller
versions = []
restart = False
def saveVersions(path=""):
"""Saves the versions to file."""
......
......@@ -37,7 +37,8 @@ class Protocol:
ADDCAFFEVERSIONS = 51
SETCURRENTCAFFEVERSION = 52
REMOVECAFFEVERSION = 53
GETDEFAULTCAFFEVERSION = 54
GETDEFAULTCAFFEVERSION = 54
GETCAFFERESTART = 55
class SessionProtocol:
......
......@@ -48,6 +48,7 @@ class ServerTransaction(Transaction):
Protocol.SETCURRENTCAFFEVERSION: self._setCurrentCaffeVersion,
Protocol.REMOVECAFFEVERSION: self._removeCaffeVersion,
Protocol.GETDEFAULTCAFFEVERSION: self._getDefaultCaffeVersion,
Protocol.GETCAFFERESTART: self._getCaffeRestart,
Protocol.GETFILEHASH: self._getFileHash,
Protocol.GETDIRHASH: self._getDirHash
......@@ -366,6 +367,7 @@ class ServerTransaction(Transaction):
msg = self.asyncRead()
versionNameReceived = msg["versionname"]
caffeVersions.setDefaultVersion(versionNameReceived, self.parent.sessionPath)
caffeVersions.restart = True
msg["status"] = True
self.send(msg)
......@@ -386,6 +388,12 @@ class ServerTransaction(Transaction):
msg["status"] = False
self.send(msg)
def _getCaffeRestart(self):
msg = self.asyncRead()
msg["cafferestart"] = caffeVersions.restart
msg["status"] = True
self.send(msg)
def _getFileHash(self):
msg = self.asyncRead()
path = msg["path"]
......
......@@ -123,7 +123,7 @@ class CaffeVersionManager(QDialog):
for version in caffeVersions.getAvailableVersions():
name = version.getName()
selected = self.versionsEqual(self.selectedVersion, {"host": None, "versionname": version.getName()})
widget = CaffeVersionWidget(caffeVersions.getVersionByName(name), self.lstVersions, self, isSelected = selected, current = name == localCurrent, host = None)
widget = CaffeVersionWidget(caffeVersions.getVersionByName(name), self.lstVersions, self, isSelected = selected, current = name == localCurrent, restart = caffeVersions.restart, host = None)
self.addListWidget(widget, True, selected)
for host in self.hostManager.getActiveHostList():
......@@ -140,6 +140,13 @@ class CaffeVersionManager(QDialog):
if reply["status"]:
remoteCurrent = reply["defaultVersionName"]
remoteRestart = False
msg = {"key": Protocol.GETCAFFERESTART}
reply = sendMsgToHost(host.host, host.port, msg)
if reply:
if reply["status"]:
remoteRestart = reply["cafferestart"]
msg = {"key": Protocol.GETCAFFEVERSIONS}
reply = sendMsgToHost(host.host, host.port, msg)
if reply:
......@@ -147,7 +154,7 @@ class CaffeVersionManager(QDialog):
for version in remoteVersions:
version = caffeVersions.caffeVersion(version, remoteVersions[version]["root"], remoteVersions[version]["binary"], remoteVersions[version]["python"], remoteVersions[version]["proto"])
selected = self.versionsEqual(self.selectedVersion, {"host": host, "versionname": version.getName()})
widget = CaffeVersionWidget(version, self.lstVersions, self, isSelected = selected, current = remoteCurrent == version.getName(), host = host)
widget = CaffeVersionWidget(version, self.lstVersions, self, isSelected = selected, current = remoteCurrent == version.getName(), restart = remoteRestart, host = host)
self.addListWidget(widget, True, selected)
def addListWidget(self, widget, selectable, selected):
......
......@@ -20,7 +20,7 @@ from PyQt5.QtWidgets import (
class CaffeVersionWidget(QWidget):
"""This widget class represents a caffe version as it is displayed in the caffe_version_manager"""
def __init__(self, version, parent, versionManager, isSelected, current, host):
def __init__(self, version, parent, versionManager, isSelected, current, restart, host):
super(CaffeVersionWidget, self).__init__(parent)
self.caffe_version = version
self.versionManager = versionManager
......@@ -46,9 +46,14 @@ class CaffeVersionWidget(QWidget):
if current:
"""Indicators if version is current project version or not"""
self.lblCurrent = QLabel("Current")
self.lblCurrent.setFixedSize(0, 0)
self.lblCurrent.setStyleSheet(self.lblCurrent.styleSheet() + "QLabel{background-color: #00EE00; border: 1px solid black; border-radius: 5px}")
if restart:
self.lblCurrent = QLabel("Restart!")
self.lblCurrent.setFixedSize(0, 0)
self.lblCurrent.setStyleSheet(self.lblCurrent.styleSheet() + "QLabel{background-color: #F4EE42; border: 1px solid black; border-radius: 5px}")
else:
self.lblCurrent = QLabel("Current")
self.lblCurrent.setFixedSize(0, 0)
self.lblCurrent.setStyleSheet(self.lblCurrent.styleSheet() + "QLabel{background-color: #00EE00; border: 1px solid black; border-radius: 5px}")
self.lblCurrent.setAlignment(QtCore.Qt.AlignCenter)
self.lblCurrent.setFixedSize(150, 30)
......@@ -95,11 +100,13 @@ class CaffeVersionWidget(QWidget):
if msgBox.exec_() == 1:
msg = {"key": Protocol.RESTART, "pid": self.versionManager.project.getProjectId()}
sendMsgToHost(self.host.host, self.host.port, msg)
def _onSetCurrent(self):
"""Sets this version as the current projects/remote hosts caffe version"""
if self.host == None:
self.versionManager.project.changeProjectCaffeVersion(self.caffe_version.getName())
self.restartWarning()
caffeVersions.restart = True
else:
msg = {"key": Protocol.SETCURRENTCAFFEVERSION, "versionname": self.caffe_version.getName()}
sendMsgToHost(self.host.host, self.host.port, msg)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment