Commit ce156157 authored by d_beck26's avatar d_beck26

Merge branch 'develop' into feature/355_multiple-caffe-versions

parents a3930002 91c8cab5
......@@ -19,3 +19,6 @@
/barista.conf
/baristalog.txt
caffeVersions
/.vscode/
/sessions
......@@ -15,6 +15,10 @@ from backend.barista import caffe_versions
class BaristaServer():
MIN_PORT = 0
MAX_PORT = 65535
DEFAULT_PORT = 4200
def __init__(self, application, ip, port, sessionPath):
self.application = application
self.server = None
......@@ -154,4 +158,5 @@ class BaristaServer():
return False
self.trainOnHW = hid
self._saveConfig()
return True
\ No newline at end of file
return True
......@@ -12,9 +12,12 @@ from backend.networking.protocol import Protocol
from gui.gui_util import askFromList
from gui.host_manager.remote_file_dialog import RemoteFileDialog
from gui.host_manager.hardware_selector import HardwareSelector
from backend.networking.barista_server import BaristaServer
class HostManager(QWidget):
DEFAULT_HOSTNAME = 'Default'
def __init__(self, parent=None):
QWidget.__init__(self,parent)
......@@ -46,7 +49,7 @@ class HostManager(QWidget):
# listwidget with all dbs
self._hostscroll = QListWidget()
self._hostscroll.setSelectionMode(QAbstractItemView.ExtendedSelection)
self._hostscroll.setSelectionMode(QAbstractItemView.SingleSelection)
self._hostscroll.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
self._layout.addWidget(self._hostscroll)
......@@ -58,8 +61,22 @@ class HostManager(QWidget):
self._hostscroll.itemSelectionChanged.connect(self._selectionChange)
self._loadFromSettings()
self._addDefaultServer()
self._updateListWidget()
def _addDefaultServer(self):
""" Add a localhost server with name 'Default', if it's not already in the
list. """
for id, item in self.dict['hostlist'].iteritems():
if item.host == 'localhost' and item.port == BaristaServer.DEFAULT_PORT:
return False
host = Host(self, 'localhost', BaristaServer.DEFAULT_PORT, self.DEFAULT_HOSTNAME)
id = str(uuid.uuid4())
host.setID(id)
self.dict["hostorder"].append(id)
self.dict["hostlist"][id] = host
return True
def _loadFromSettings(self):
settings = applicationQSetting()
settings.beginGroup("Host")
......@@ -100,12 +117,17 @@ class HostManager(QWidget):
hostdict["hostlist"][id] = host
return hostdict
def _selectedHost(self):
if len(self._hostscroll.selectedItems()) < 1:
return None
id = self._hostscroll.selectedItems()[0].data(Qt.UserRole)
host = self.dict["hostlist"][id]
return host
def _selectionChange(self):
"""disable and enable the delete button on selection"""
if len(self._hostscroll.selectedItems()) <= 0:
self._pb_remove.setEnabled(False)
else:
self._pb_remove.setEnabled(True)
num_selected = len(self._hostscroll.selectedItems())
self._pb_remove.setEnabled(num_selected > 0 and self._selectedHost().name != self.DEFAULT_HOSTNAME)
def getActiveHostList(self):
ret = []
......@@ -138,6 +160,9 @@ class HostManager(QWidget):
"""remove selected hosts"""
ic = len(self._hostscroll.selectedItems())
if ic > 0:
# Prevent DEFAULT HOST from being deleted.
if self._selectedHost().name == self.DEFAULT_HOSTNAME:
return
gramNum = ""
if ic > 1:
gramNum = "s"
......@@ -884,6 +909,3 @@ class Host(QObject):
if self.transaction:
self.transaction.close()
self.transaction = None
......@@ -13,6 +13,7 @@ class DatabaseObject:
self._dbType = None
self._openPath = None
self._openDBType = None
self._projectPath = None
def __del__(self):
'''on delete: close'''
......
......@@ -12,6 +12,9 @@ from backend.caffe import path_loader
from gui.start_dialog import StartDialog
from PyQt5.QtWidgets import QApplication
from gui.caffepath_dialog import CaffepathDialog
from backend.networking.barista_server import BaristaServer
import threading
import subprocess
if __name__ == "__main__":
......@@ -20,6 +23,8 @@ if __name__ == "__main__":
QLocale.setDefault(QLocale.c())
# Parse command line arguments.
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--server', help='start a local server and add it to the host manager', default=False, action='store_true')
parser.add_argument('-d', '--dir', help='local directory to run server sessions in', type=str, default='.')
parser.add_argument('-o', '--open', help='path to a Barista project to be opened', type=str, default='')
args = parser.parse_args()
# Get caffepath out of settings.
......@@ -28,6 +33,17 @@ if __name__ == "__main__":
path = settings.value("caffePath")
app = QApplication(sys.argv)
signal.signal(signal.SIGINT, signal.SIG_DFL)
# Start local server on 'localhost:4200' in subprocess.
if args.server:
if not os.path.exists(args.dir):
logging.error("Session folder '%s' does not exist." % (args.dir))
sys.stderr.write("Session folder '%s' does not exist." % (args.dir))
exit(2)
command = './server.py --port {} --dir {}'.format(BaristaServer.DEFAULT_PORT, args.dir)
pid = subprocess.Popen(command.split()).pid
# Stop the server when the app is about to quit.
app.aboutToQuit.connect(lambda: os.kill(pid, signal.SIGTERM))
# server = BaristaServer(app, ip=None, port=BaristaServer.DEFAULT_PORT, sessionPath='sessions')
# Set global application stylesheet.
with open('resources/styles.qss', "r") as stylesFile:
stylesheet = stylesFile.read()
......
......@@ -8,23 +8,19 @@ from PyQt5.QtCore import QCoreApplication
from backend.networking.barista_server import BaristaServer
MIN_PORT = 0
MAX_PORT = 65535
if __name__ == "__main__":
logging.basicConfig(format='[%(asctime)s] %(levelname)s @ %(funcName)s: %(message)s', datefmt='%d/%m/%Y %H:%M:%S',
filename="baristalog.txt", level=logging.INFO)
# Parse command line arguments.
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--port', help='local port to receive connections', default='0', type=int)
parser.add_argument('-p', '--port', help='local port to receive connections', default=BaristaServer.DEFAULT_PORT, type=int)
parser.add_argument('-d', '--dir', help='local directory to run all sessions in', type=str, default='.')
parser.add_argument('-i', '--ip', help='IP reachable from Barista GUI', type=str)
args = parser.parse_args()
# Validate port.
if args.port < MIN_PORT or args.port > MAX_PORT:
logging.error("Port should be between %d and %d." % (MIN_PORT, MAX_PORT))
sys.stderr.write("Port should be between %d and %d.\n" % (MIN_PORT, MAX_PORT))
if args.port < BaristaServer.MIN_PORT or args.port > BaristaServer.MAX_PORT:
logging.error("Port should be between %d and %d." % (BaristaServer.MIN_PORT, BaristaServer.MAX_PORT))
sys.stderr.write("Port should be between %d and %d.\n" % (BaristaServer.MIN_PORT, BaristaServer.MAX_PORT))
exit(2)
# Validate session directory.
args.dir = os.path.abspath(args.dir)
......
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