예제 #1
0
    def btnStopAllTORPrograms_clicked(self):
        with WaitCursor():
            jobs = []
            for c in self.cds:
                j = copy.deepcopy(DefaultJobs.WAIT)
                j.ClientId = c.Id
                jobs.append(j)
            DBManager.saveJobs(jobs)

            allWaiting = False
            while allWaiting == False:
                time.sleep(5)
                busyClients = DBManager.getBusyClients()
                if len(busyClients) == 0:
                    allWaiting = True
                else:
                    msg = "waiting for {} boxes to finish...".format(len(busyClients))
                    log.info(msg)
                    self.addStatusText(msg)

            msg = "all boxes ready waiting..."
            log.info(msg)
            self.addStatusText(msg)
            time.sleep(3)
            self.executeCommandOnTORServer(TORCommands.INTERACTIVE_STOP)
            self.executeCommandOnAllClients(TORCommands.CLIENT_SERVICE_STOP)
            self.executeCommandOnTORServer(TORCommands.SERVER_SERVICE_STOP)
            DBManager.clearAllCurrentStates()
            time.sleep(3)
            self.executeCommandOnAllClients(TORCommands.CLIENT_TURN_OFF_LEDS)
예제 #2
0
    def loadClientDetails(self, client):
        logMessages = DBManager.getClientLogByClientId(client.Id)
        self.showDataInTable(logMessages, self.tblLogMessages, LogMessageTableModel)
        self.setTableWidths(self.tblLogMessages, [50, 150, 200, 200])

        diceResults = DBManager.getResultsByClientId(client.Id)
        self.showDataInTable(diceResults, self.tblResults, DiceResultTableModel)
        self.setTableWidths(self.tblResults, [50, 50, 50, 50, 200])

        self.loadResultStatistics()

        self.setClientDetailInfoListText(0, client.Latin)
        self.setClientDetailInfoListText(1, client.Position)
        self.setClientDetailInfoListText(2, client.Id)
        self.setClientDetailInfoListText(3, client.IP)
        self.setClientDetailInfoListText(4, "")
        self.setClientDetailInfoListText(5, "YES" if client.AllowUserMode else "NO")
        self.setClientDetailInfoListText(6, "YES" if client.IsActive else "NO")
        self.setClientDetailInfoListText(7, client.Position)

        clientContributions = DBManager.getAllClientResultContribution(TAKE_N_RESULTS_FOR_RECENT_CONTRIBUTIONS)
        for cc in clientContributions:
            if cc.Id == client.Id:
                self.setClientDetailInfoListText(11, "{:.2f}".format(cc.Contribution))
                self.setClientDetailInfoListText(12, "{:.2f}".format(cc.AverageResult))
                break
예제 #3
0
    def updateDashboard(self):
        if self.IsUpdating:
            return
        self.IsUpdating = True
        print("updateDashboard")
        jobs = DBManager.getCurrentJobs()
        for j in jobs:
            for c in self.cds:
                if c.Id == j.Id:
                    c.CurrentJobCode = j.JobCode
                    c.CurrentJobParameters = j.JobParameters
                    break
        results = DBManager.getAllClientStatistics()
        for r in results:
            for c in self.cds:
                if c.Id == r.Id:
                    c.ResultAverage = r.ResultAverage
                    c.ResultStddev = r.ResultStddev
                    break
        data = DBManager.getAllClients()
        for d in data:
            for c in self.cds:
                if c.Id == d.Id:
                    c.IP = d.IP
                    c.Material = d.Material
                    c.Position = d.Position
                    c.Latin = d.Latin
                    c.AllowUserMode = d.AllowUserMode
                    c.IsActive = d.IsActive
                    break
        for cdv in self.cdvs:
            cdv.lblCurrentJob.setText("{} {}".format(cdv.clientDetails.CurrentJobCode, cdv.clientDetails.CurrentJobParameters))
            cdv.lblResultAverage.setText("{:.2f}±{:.2f}".format(cdv.clientDetails.ResultAverage, cdv.clientDetails.ResultStddev))
            cdv.lblResultStddev.setText("+-{}".format(cdv.clientDetails.ResultStddev))
            if cdv.clientDetails.IsBadStatistics():
                cdv.lblResultAverage.setStyleSheet("QLabel { color: \"red\"; }")
                cdv.lblResultStddev.setStyleSheet("QLabel { color: \"red\"; }")
            else:
                cdv.lblResultAverage.setStyleSheet("")
                cdv.lblResultStddev.setStyleSheet("")

        threadPool = concurrent.futures.ThreadPoolExecutor(THREAD_POOL_SIZE)
        threadFutures = [threadPool.submit(self.checkOnlineAndServiceStatusForClient, cdv.clientDetails) for cdv in self.cdvs]
        concurrent.futures.wait(threadFutures)

        for cdv in self.cdvs:
            cdv.chkUserMode.setChecked(cdv.clientDetails.AllowUserMode)
            cdv.chkIsActivated.setChecked(cdv.clientDetails.IsActive)
            cdv.refreshClientServiceStatus()
            if cdv.clientDetails.IsOnline:
                cdv.lblIsOnline.setPixmap(TORIcons.LED_GREEN)
            else:
                cdv.lblIsOnline.setPixmap(TORIcons.LED_RED)
        self.lblLastUpdateTime.setText("last update: {}".format(datetime.now().strftime("%H:%M:%S")))
        print("updateDashboard finished")
        self.IsUpdating = False
예제 #4
0
    def loadAllClientDetails(self):
        logMessages = DBManager.getClientLog()
        self.showDataInTable(logMessages, self.tblLogMessages, LogMessageTableModel)
        self.setTableWidths(self.tblLogMessages, [50, 150, 50, 150, 200, 200])

        diceResults = DBManager.getResults()
        self.showDataInTable(diceResults, self.tblResults, DiceResultTableModel)
        self.setTableWidths(self.tblResults, [50, 150, 50, 50, 50, 50, 200])

        self.loadResultStatistics()

        for i in range(len(self.clientDetailInfoList)):
            self.setClientDetailInfoListText(i, "---")
예제 #5
0
 def btnStartTour_clicked(self):
     jobs = []
     for w in self.jobListWidgets:
         j = Job()
         if w[1].isChecked():
             j = copy.deepcopy(DefaultJobs.QUIT)
         elif w[2].isChecked():
             j = copy.deepcopy(DefaultJobs.WAIT)
         elif w[3].isChecked():
             j = copy.deepcopy(DefaultJobs.RUN)
         elif w[4].isChecked():
             j = copy.deepcopy(DefaultJobs.RUN_AND_WAIT)
         j.JobParameters = w[5].text()
         j.ClientId = w[0]
         jobs.append(j)
     DBManager.saveJobs(jobs)
예제 #6
0
def getMeshpoints(clientId):
    meshpoints = DBManager.getMeshpoints(clientId)
    meshTypes = ["B", "R", "M"]
    groupedPoints = {}
    for t in meshTypes:
        points = [(float(x), float(y), float(z))
                  for (ty, no, x, y, z) in meshpoints if ty == t]
        if len(points) > 0:
            groupedPoints[t] = points
    return groupedPoints
예제 #7
0
 def cmbTour_currentIndexChanged(self, index):
     programName = self.cmbTour.currentText()
     if programName != NEW_PROGRAM_NAME:
         programJobs = DBManager.getJobsByProgramName(programName)
         self.fillJobList(programJobs)
         self.wdgJobList.setEnabled(False)
예제 #8
0
 def btnStartAllTORPrograms_clicked(self):
     with WaitCursor():
         DBManager.clearAllCurrentStates()
         self.executeCommandOnTORServer(TORCommands.SERVER_SERVICE_START)
         self.executeCommandOnAllClients(TORCommands.CLIENT_SERVICE_START, onlyActive=True)
         self.executeCommandOnTORServer(TORCommands.INTERACTIVE_START)
예제 #9
0
def saveMeshpoints(clientId, type, points):
    DBManager.saveMeshpoints(clientId, type, points)
예제 #10
0
    def __init__(self):
        super().__init__()

        self.IsBusy = False
        self.IsUpdating = False

        self.currentSelectedTabIndex = 0
        self.setWindowTitle("TOR")
        self.setWindowIcon(TORIcons.APP_ICON)

        self.cdvs = []
        self.cds = []
        clients = DBManager.getAllClients()
        layClientDetails = QHBoxLayout()
        layClientDetails.setContentsMargins(0, 0, 0, 0)
        grpClientDetailsRegions = [QGroupBox() for i in range(3)]
        for g in grpClientDetailsRegions:
            g.setObjectName("ClientGroup")
        grpClientDetailsRegions[0].setTitle("Front")
        grpClientDetailsRegions[1].setTitle("Middle")
        grpClientDetailsRegions[2].setTitle("Back")
        layClientDetailsRegions = [QGridLayout() for i in range(3)]
        for i in range(3):
            #layClientDetailsRegions[i].setContentsMargins(0, 0, 0, 0)
            #layClientDetailsRegions[i].setSpacing(0)
            grpClientDetailsRegions[i].setLayout(layClientDetailsRegions[i])
            #grpClientDetailsRegions[i].setContentsMargins(0, 0, 0, 0)
            for j in range(3):
                for k in range(3):
                    c = clients[i*9 + j*3 + k]
                    cdv = ClientDetailView()
                    cd = ClientDetails()
                    cd.Id = c.Id
                    cd.IP = c.IP
                    cd.Material = c.Material
                    cd.Position = c.Position
                    cd.Latin = c.Latin
                    cd.AllowUserMode = c.AllowUserMode
                    cd.IsActive = c.IsActive
                    cdv.clientDetails = cd
                    cdv.grpMainGroup.setTitle("#{}: {}...".format(cd.Position, cd.Latin[0:9]))
                    layClientDetailsRegions[i].addWidget(cdv, k, 3*i + j)
                    self.cdvs.append(cdv)
                    self.cds.append(cd)
            layClientDetails.addWidget(grpClientDetailsRegions[i])
        wdgClientDetails = QWidget()
        wdgClientDetails.setLayout(layClientDetails)


        self.btnStartAllTORPrograms = QPushButton()
        self.btnStartAllTORPrograms.setText("START installation")
        self.btnStartAllTORPrograms.clicked.connect(self.btnStartAllTORPrograms_clicked)
        self.btnStartAllTORPrograms.setStyleSheet("QPushButton { font-weight: bold }; ")

        self.btnStopAllTORPrograms = QPushButton()
        self.btnStopAllTORPrograms.setText("STOP installation")
        self.btnStopAllTORPrograms.clicked.connect(self.btnStopAllTORPrograms_clicked)
        self.btnStopAllTORPrograms.setStyleSheet("QPushButton { font-weight: bold }; ")

        self.btnStartAllClientService = QPushButton()
        self.btnStartAllClientService.setText("Start all active TORClients")
        self.btnStartAllClientService.clicked.connect(self.btnStartAllClientService_clicked)

        self.btnStopAllClientService = QPushButton()
        self.btnStopAllClientService.setText("Stop all TORClients")
        self.btnStopAllClientService.clicked.connect(self.btnStopAllClientService_clicked)

        self.btnSaveSettings = QPushButton()
        self.btnSaveSettings.setText("Save Settings")
        self.btnSaveSettings.clicked.connect(self.btnSaveSettings_clicked)

        self.btnRestoreSettings = QPushButton()
        self.btnRestoreSettings.setText("Restore Settings")
        self.btnRestoreSettings.clicked.connect(self.btnRestoreSettings_clicked)

        self.btnStartTORServer = QPushButton()
        self.btnStartTORServer.setText("Start TOR Server")
        self.btnStartTORServer.clicked.connect(self.btnStartTORServer_clicked)

        self.btnStopTORServer = QPushButton()
        self.btnStopTORServer.setText("Stop TOR Server")
        self.btnStopTORServer.clicked.connect(self.btnStopTORServer_clicked)

        self.btnStartTORInteractive = QPushButton()
        self.btnStartTORInteractive.setText("Start Visitor App")
        self.btnStartTORInteractive.clicked.connect(self.btnStartTORInteractive_clicked)

        self.btnStopTORInteractive = QPushButton()
        self.btnStopTORInteractive.setText("Stop Visitor App")
        self.btnStopTORInteractive.clicked.connect(self.btnStopTORInteractive_clicked)

        self.btnEndAllUserModes = QPushButton()
        self.btnEndAllUserModes.setText("End all visitor control")
        self.btnEndAllUserModes.clicked.connect(self.btnEndAllUserModes_clicked)

        self.btnTurnOnLEDs = QPushButton()
        self.btnTurnOnLEDs.setText("Turn ON all LEDs")
        self.btnTurnOnLEDs.clicked.connect(self.btnTurnOnLEDs_clicked)

        self.btnTurnOffLEDs = QPushButton()
        self.btnTurnOffLEDs.setText("Turn OFF all LEDs")
        self.btnTurnOffLEDs.clicked.connect(self.btnTurnOffLEDs_clicked)

        self.btnUpdateDashboard = QPushButton()
        self.btnUpdateDashboard.setText("Update dashboard")
        self.btnUpdateDashboard.clicked.connect(self.btnUpdateDashboard_clicked)

        self.lblLastUpdateTime = QLabel()

        spacerSize = 30
        layDashboardButtons = QVBoxLayout()
        layDashboardButtons.addSpacing(spacerSize)
        layDashboardButtons.addWidget(QLabel("<h3>Installation</h3>"))
        layDashboardButtons.addWidget(self.btnStartAllTORPrograms)
        layDashboardButtons.addWidget(self.btnStopAllTORPrograms)
        layDashboardButtons.addSpacing(spacerSize)
        layDashboardButtons.addWidget(QLabel("Clients"))
        layDashboardButtons.addWidget(self.btnStartAllClientService)
        layDashboardButtons.addWidget(self.btnStopAllClientService)
        layDashboardButtons.addSpacing(spacerSize)
        layDashboardButtons.addWidget(QLabel("LEDs"))
        layDashboardButtons.addWidget(self.btnTurnOnLEDs)
        layDashboardButtons.addWidget(self.btnTurnOffLEDs)
        layDashboardButtons.addSpacing(spacerSize)
        layDashboardButtons.addWidget(QLabel("Server"))
        layDashboardButtons.addWidget(self.btnStartTORServer)
        layDashboardButtons.addWidget(self.btnStopTORServer)
        layDashboardButtons.addSpacing(spacerSize)
        layDashboardButtons.addWidget(QLabel("Visitor App"))
        layDashboardButtons.addWidget(self.btnStartTORInteractive)
        layDashboardButtons.addWidget(self.btnStopTORInteractive)
        layDashboardButtons.addWidget(self.btnEndAllUserModes)
        layDashboardButtons.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding))
        layDashboardButtons.addWidget(self.btnUpdateDashboard)
        layDashboardButtons.addWidget(self.lblLastUpdateTime)


        wdgDashboardButtons = QWidget()
        wdgDashboardButtons.setLayout(layDashboardButtons)

        """
        layDashboardButtonsTop = QHBoxLayout()
        layDashboardButtonsTop.addWidget(self.btnStartAllClientService)
        layDashboardButtonsTop.addWidget(self.btnStopAllClientService)
        layDashboardButtonsTop.addWidget(self.btnSaveSettings)
        layDashboardButtonsTop.addWidget(self.btnRestoreSettings)
        wdgDashboardButtonsTop = QWidget()
        wdgDashboardButtonsTop.setLayout(layDashboardButtonsTop)

        layDashboardButtons2 = QHBoxLayout()
        layDashboardButtons2.addWidget(self.btnTurnOnLEDs)
        layDashboardButtons2.addWidget(self.btnTurnOffLEDs)
        wdgDashboardButtons2 = QWidget()
        wdgDashboardButtons2.setLayout(layDashboardButtons2)

        layDashboardButtonsBottom = QHBoxLayout()
        layDashboardButtonsBottom.addWidget(self.btnStartTORServer)
        layDashboardButtonsBottom.addWidget(self.btnStopTORServer)
        layDashboardButtonsBottom.addWidget(self.btnStartTORInteractive)
        layDashboardButtonsBottom.addWidget(self.btnStopTORInteractive)
        layDashboardButtonsBottom.addWidget(self.btnEndAllUserModes)
        wdgDashboardButtonsBottom = QWidget()
        wdgDashboardButtonsBottom.setLayout(layDashboardButtonsBottom)
        """

        layDashboard = QHBoxLayout()
        #layDashboard.addWidget(wdgDashboardButtonsTop)
        #layDashboard.addWidget(wdgDashboardButtons2)
        layDashboard.addWidget(wdgClientDetails)
        #layDashboard.addWidget(wdgDashboardButtonsBottom)
        layDashboard.addWidget(wdgDashboardButtons)

        wdgDashboard = QWidget()
        wdgDashboard.setLayout(layDashboard)


        programNames = DBManager.getAllJobProgramNames()
        self.jobProgramNames = [pn.Name for pn in programNames]
        self.cmbTour = QComboBox()
        self.cmbTour.insertItem(-1, NEW_PROGRAM_NAME)
        for i in range(len(self.jobProgramNames)):
            self.cmbTour.insertItem(i, self.jobProgramNames[i])
        self.cmbTour.currentIndexChanged.connect(self.cmbTour_currentIndexChanged)
        self.btnStartTour = QPushButton("Start")
        self.btnStartTour.clicked.connect(self.btnStartTour_clicked)
        self.btnEditTour = QPushButton("Edit")
        self.btnEditTour.clicked.connect(self.btnEditTour_clicked)

        layTourSelection = QHBoxLayout()
        layTourSelection.addWidget(QLabel("Program: "))
        layTourSelection.addWidget(self.cmbTour)
        layTourSelection.addSpacing(100)
        layTourSelection.addWidget(self.btnStartTour)
        layTourSelection.addWidget(self.btnEditTour)
        layTourSelection.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding))

        wdgTourSelection = QWidget()
        wdgTourSelection.setLayout(layTourSelection)

        self.jobListWidgets = []
        layJobList = QGridLayout()
        jobs = DBManager.getCurrentJobs()
        layJobList.addWidget(QLabel("<h3>Box</h3>"), 0, 0)
        layJobList.addWidget(QLabel("<h3>Quit</h3>"), 0, 1)
        layJobList.addWidget(QLabel("<h3>Wait</h3>"), 0, 2)
        layJobList.addWidget(QLabel("<h3>Run</h3>"), 0, 3)
        layJobList.addWidget(QLabel("<h3>Run & Wait</h3>"), 0, 4)
        layJobList.addWidget(QLabel("<h3>Parameters</h3>"), 0, 5)
        chkQuitAll = QCheckBox()
        chkQuitAll.clicked.connect(self.chkQuitAll_clicked)
        chkWaitAll = QCheckBox()
        chkWaitAll.clicked.connect(self.chkWaitAll_clicked)
        chkRunAll = QCheckBox()
        chkRunAll.clicked.connect(self.chkRunAll_clicked)
        chkRunAndWaitAll = QCheckBox()
        chkAllGroup = QButtonGroup(self)
        chkAllGroup.addButton(chkQuitAll)
        chkAllGroup.addButton(chkWaitAll)
        chkAllGroup.addButton(chkRunAll)
        chkAllGroup.addButton(chkRunAndWaitAll)
        chkRunAndWaitAll.clicked.connect(self.chkRunAndWaitAll_clicked)
        txtParametersAll = QLineEdit()
        txtParametersAll.textChanged.connect(self.txtParametersAll_textChanged)
        layJobList.addWidget(chkQuitAll, 1, 1)
        layJobList.addWidget(chkWaitAll, 1, 2)
        layJobList.addWidget(chkRunAll, 1, 3)
        layJobList.addWidget(chkRunAndWaitAll, 1, 4)
        layJobList.addWidget(txtParametersAll, 1, 5)
        row = 2
        clientCount = 0
        for c in self.cds:
            chkQuit = QCheckBox()
            chkWait = QCheckBox()
            chkRun = QCheckBox()
            chkRunAndWait = QCheckBox()
            txtParameters = QLineEdit()
            chkGroup = QButtonGroup(self)
            chkGroup.addButton(chkQuit)
            chkGroup.addButton(chkWait)
            chkGroup.addButton(chkRun)
            chkGroup.addButton(chkRunAndWait)
            layJobList.addWidget(QLabel("Pos {}: {}".format(c.Position, c.Latin)), row, 0)
            layJobList.addWidget(chkQuit, row, 1)
            layJobList.addWidget(chkWait, row, 2)
            layJobList.addWidget(chkRun, row, 3)
            layJobList.addWidget(chkRunAndWait, row, 4)
            layJobList.addWidget(txtParameters, row, 5)
            self.jobListWidgets.append([c.Id, chkQuit, chkWait, chkRun, chkRunAndWait, txtParameters])
            row += 1
            clientCount += 1
            if clientCount % 9 == 0 and clientCount < 27:
                line = QFrame()
                line.setGeometry(QRect())
                line.setFrameShape(QFrame.HLine)
                line.setFrameShadow(QFrame.Sunken)
                layJobList.addWidget(line, row, 0, 1, 6)
                row += 1

        self.fillJobList(jobs)

        self.wdgJobList = QWidget()
        self.wdgJobList.setEnabled(False)
        self.wdgJobList.setLayout(layJobList)

        lblJobDescriptionText = QLabel(
            """
                The parameters for Job 'W' are of the form 't' where 't' is optional<br>check every t seconds if there is another job to do
                <br><br><br> 
                The parameters for Job 'RW' are of the form 'r w t'<br>run r times, then wait w times for t seconds
            """)
        lblJobDescriptionText.setAlignment(Qt.AlignTop)

        layJobListAndDescriptions = QHBoxLayout()
        layJobListAndDescriptions.addWidget(self.wdgJobList)
        layJobListAndDescriptions.addSpacing(100)
        layJobListAndDescriptions.addWidget(lblJobDescriptionText)
        layJobListAndDescriptions.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding))

        wdgJobListAndDescriptions = QWidget()
        wdgJobListAndDescriptions.setLayout(layJobListAndDescriptions)

        layJobOverview = QVBoxLayout()
        #layJobOverview.addWidget(QLabel("Job Overview"))
        layJobOverview.addWidget(wdgTourSelection)
        layJobOverview.addWidget(wdgJobListAndDescriptions)

        wdgJobOverivew = QWidget()
        wdgJobOverivew.setLayout(layJobOverview)

        # Client Details

        self.cmbClient = QComboBox()
        self.cmbClient.setFixedWidth(180)
        self.cmbClient.insertItem(-1, "All", -1)
        for c in self.cds:
            self.cmbClient.insertItem(c.Position, "#{}: {}".format(c.Position, c.Latin), c.Position)
        self.cmbClient.currentIndexChanged.connect(self.cmbClient_currentIndexChanged)

        self.btnRereshClientDetails = QPushButton("Refresh")
        self.btnRereshClientDetails.clicked.connect(self.btnRereshClientDetails_clicked)

        layClientSelection = QHBoxLayout()
        layClientSelection.addWidget(QLabel("Box: "))
        layClientSelection.addWidget(self.cmbClient)
        layClientSelection.addSpacing(100)
        layClientSelection.addWidget(self.btnRereshClientDetails)
        layClientSelection.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Fixed))

        wdgClientSelection = QWidget()
        wdgClientSelection.setLayout(layClientSelection)

        self.tblResults = QTableView()
        self.tblResults.horizontalHeader().setStretchLastSection(True)
        self.tblResults.setWordWrap(False)
        self.tblResults.setTextElideMode(Qt.ElideRight)

        self.clientDetailInfoList = [
            ["Name", QLabel("-")],
            ["Position", QLabel("-")],
            ["ID", QLabel("-")],
            ["IP", QLabel("-")],
            ["MAC", QLabel("-")],
            ["Allow User Mode", QLabel("-")],
            ["User Mode Active", QLabel("-")],
            ["Is Active", QLabel("-")],
            ["Current State", QLabel("-")],
            ["Current Job", QLabel("-")],
            ["Recent results", QLabel("-")],
            ["Average contribution", QLabel("-")],
            ["Average result (3.5)", QLabel("-")],
            ["Results last hour", QLabel("-")],
            ["Results last 2 hours", QLabel("-")],
            ["Results today", QLabel("-")],
            ["Results Total", QLabel("-")]
        ]
        layClientDetailInfos = QGridLayout()
        for num, (text, widget) in enumerate(self.clientDetailInfoList):
            layClientDetailInfos.addWidget(QLabel(text), num, 0)
            layClientDetailInfos.addWidget(widget, num, 1)

        grpClientDetailInfos = QGroupBox()
        grpClientDetailInfos.setTitle("Details")
        grpClientDetailInfos.setLayout(layClientDetailInfos)

        layClientDetailsTop = QHBoxLayout()
        layClientDetailsTop.addWidget(self.tblResults)
        layClientDetailsTop.addSpacing(100)
        layClientDetailsTop.addWidget(grpClientDetailInfos)
        layClientDetailsTop.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Fixed))

        wdgClientDetailsTop = QWidget()
        wdgClientDetailsTop.setLayout(layClientDetailsTop)


        self.tblLogMessages = QTableView()
        self.tblLogMessages.horizontalHeader().setStretchLastSection(True)
        self.tblLogMessages.setWordWrap(False)
        self.tblLogMessages.setTextElideMode(Qt.ElideRight)

        self.tblResultStatistics = QTableView()
        #self.tblResultStatistics.horizontalHeader().setStretchLastSection(True)
        self.tblResultStatistics.setWordWrap(False)
        self.tblResultStatistics.setTextElideMode(Qt.ElideRight)
        self.tblResultStatistics.setSortingEnabled(True)

        layClientDetailsBottom = QHBoxLayout()
        layClientDetailsBottom.addWidget(self.tblLogMessages)
        layClientDetailsBottom.addSpacing(20)
        layClientDetailsBottom.addWidget(self.tblResultStatistics)
        #layClientDetailsBottom.addSpacerItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Fixed))

        wdgClientDetailsBottom = QWidget()
        wdgClientDetailsBottom.setLayout(layClientDetailsBottom)

        layDetails = QVBoxLayout()
        layDetails.addWidget(wdgClientSelection)
        layDetails.addWidget(QLabel("Results"))
        layDetails.addWidget(wdgClientDetailsTop)
        layDetails.addWidget(QLabel("Log messages"))
        layDetails.addWidget(wdgClientDetailsBottom)


        wdgDetails = QWidget()
        wdgDetails.setLayout(layDetails)


        layTORServer = QVBoxLayout()
        layTORServer.addWidget(QLabel("TOR server"))

        wdgTORServer = QWidget()
        wdgTORServer.setLayout(layTORServer)

        self.clientDetailsTabIndex = 2

        self.tabDashboard = QTabWidget()
        self.tabDashboard.addTab(wdgDashboard, "Dashboard")
        #self.tabDashboard.addTab(wdgTORServer, "TORServer")
        self.tabDashboard.addTab(wdgJobOverivew, "Jobs")
        self.tabDashboard.addTab(wdgDetails, "Detail View")
        self.dashboardTabIndex = 0
        self.tabDashboard.currentChanged.connect(self.tabDashboard_currentChanged)

        self.txtStatus = QPlainTextEdit()
        self.txtStatus.setReadOnly(True)

        layMain = QVBoxLayout()
        layMain.addWidget(self.tabDashboard)
        layMain.addWidget(self.txtStatus)

        wdgMain = QWidget()
        wdgMain.setLayout(layMain)
        self.setCentralWidget(wdgMain)

        self.initDashboard()
        self.updateDashboard()
        timerFetchData = QTimer(self)
        timerFetchData.timeout.connect(self.updateDashboardFromTimer)
        timerFetchData.start(120 * 1000)
예제 #11
0
 def chkIsActivated_clicked(self, checked):
     self.clientDetails.IsActive = checked
     DBManager.setClientIsActive(self.clientDetails.Id, checked)
예제 #12
0
 def chkUserMode_clicked(self, checked):
     self.clientDetails.AllowUserMode = checked
     DBManager.setUserModeEnabled(self.clientDetails.Id, checked)
예제 #13
0
def saveClientSettings(clientId, settings):
    DBManager.saveClientSettings(clientId, settings)
예제 #14
0
ips = ["192.168.1.101", "192.168.1.111", "192.168.1.128"]
positions = []
#positions = [1, 2, 3, 4,5, 6, 7, 8, 9]
#positions = range(1, 28)
#positions = [10, 11, 12, 13, 14, 15]
#positions = [1, 2, 3]
#positions = [4]

#from itertools import chain
#positions = chain(range(1, 21), range(23, 28))

if len(positions) > 0:
    from tor.base import DBManager

for p in positions:
    ips.append(DBManager.getIPByPosition(p))

#if len(positions) == 0:
#    ips = [115]

path_key = tsl.PATH_TO_SSH_KEY

cmd_new_shell = "invoke-expression 'cmd /c start powershell -Command {{ {0} }}'"

#### TOR ####
filename = "update_tor.cmd"
cmd_delete = r'ssh -i {0} pi@{1} "sudo rm -r tor; sudo rm -r scripts"'
cmd_copy = r"scp -i {0} -r " + tsl.PATH_TO_TOR_SOURCE + r"/TOR/tor pi@{1}:/home/pi"
#cmd_delete_service = r'ssh -i {0} pi@{1} "sudo rm -r scripts"'
cmd_copy_service = r"scp -i {0} -r " + tsl.PATH_TO_TOR_SCRIPTS + r"/TOR/scripts pi@{1}:/home/pi"
#cmd_copy_service_system = r'ssh -i {0} pi@{1} "sudo cp /home/pi/scripts/TORClient.service /etc/systemd/system/TORClient.service"'
예제 #15
0
 def loadResultStatistics(self):
     resultStatistics = DBManager.getResultStatistics(ts.DICE_RESULT_EVENT_SOURCE)
     self.showDataInTable(resultStatistics, self.tblResultStatistics, ResultStatisticsTableModel)
     w = 50
     self.setTableWidths(self.tblResultStatistics, [w, 100, w, w, w, w, w, w, w, w])
예제 #16
0
def handleRequest(conn):
    request = NetworkUtils.recvData(conn)
    if isinstance(request, dict):
        if "C" in request:  #request from client C
            clientId = request["C"]
            if "RESULT" in request:  #die roll result
                dieResult = request["RESULT"]
                x = request["POSX"]
                y = request["POSY"]
                userGenerated = request["USER"]
                log.info("Client {} rolled {} at [{}, {}]".format(
                    clientId, dieResult, x, y))
                NetworkUtils.sendOK(conn)
                DBManager.writeResult(clientId, dieResult, x, y, userGenerated,
                                      ts.DICE_RESULT_EVENT_SOURCE)
            elif "E" in request:  #error on client
                log.warning("Error {} @ Client {}".format(
                    request["E"], clientId))
                log.warning(request["MESSAGE"])
                DBManager.logClientAction(clientId, "ERROR", request["E"],
                                          request["MESSAGE"])
                NetworkUtils.sendOK(conn)
            elif "MSG" in request:  # message for logging
                log.info("Message {} @ Client {}".format(
                    request["MSG"], clientId))
                log.warning(request["MESSAGE"])
                DBManager.logClientAction(clientId, "INFO", request["MSG"],
                                          request["MESSAGE"])
                NetworkUtils.sendOK(conn)
            elif "J" in request:  #client asks for job
                job = DBManager.getNextJobForClientId(clientId)
                log.info("client {} asks for job, send {}".format(
                    clientId, job))
                NetworkUtils.sendData(conn, {
                    job.JobCode: job.JobParameters,
                    "T": job.ExecuteAt.__str__()
                })
            elif "U" in request:
                if request["U"] == "EXIT":
                    exitUserMode(clientId)
                else:
                    setCurrentStateForUserMode(clientId, request["U"])
                NetworkUtils.sendOK(conn)
            elif "A" in request:
                log.info("send next user action")
                action = DBManager.getUserAction(clientId)
                #log.info("action: {}".format(action))
                NetworkUtils.sendData(conn, {
                    "A": action["Action"],
                    "PARAM": action["Parameters"]
                })
            elif "GET" in request:
                if request["GET"] == "MESH":
                    meshpoints = getMeshpoints(clientId)
                    NetworkUtils.sendData(conn, meshpoints)
                elif request["GET"] == "SETTINGS":
                    settings = getClientSettings(clientId)
                    NetworkUtils.sendData(conn, settings)
            elif "PUT" in request:
                if request["PUT"] == "MESH":
                    NetworkUtils.sendOK(conn)
                    saveMeshpoints(clientId, request["TYPE"],
                                   request["POINTS"])
                elif request["PUT"] == "SETTINGS":
                    NetworkUtils.sendOK(conn)
                    saveClientSettings(clientId, request["SETTINGS"])
        elif "MAC" in request:
            cId = DBManager.getClientIdentity(request["MAC"])
            NetworkUtils.sendData(
                conn, {
                    "Id": cId.Id,
                    "IP": cId.IP,
                    "Material": cId.Material,
                    "Position": cId.Position,
                    "Latin": cId.Latin
                })
        else:
            log.warning("could not identify client.")
    else:
        log.warning("request not defined: {}".format(request))
예제 #17
0
def setCurrentStateForUserMode(clientId, state):
    DBManager.setCurrentStateForUserMode(clientId, state)
예제 #18
0
def exitUserMode(clientId):
    DBManager.exitUserMode(clientId)
예제 #19
0
positions = []
#positions = [1, 2, 3, 4, 5, 6, 7, 8, 9]
positions = range(1, 28)
#positions = [1, 3]
#positions = [16]
#positions = [4, 5, 6]
positions = [1, 2, 3, 4, 5, 6]
#positions = range(5, 28)

from itertools import chain
#positions = chain(range(2, 16), range(17, 28))
#positions = chain(range(1, 21), range(23, 28))
#positions = chain(range(1, 4), range(5, 28))

for p in positions:
    ids.append(DBManager.getIdByPosition(p))

#if len(positions) == 0:
#    ids = [15]

if not isinstance(ids, list):
    ids = [ids]
for jobToCreate in jobsToCreate:
    jobs = []
    for id in ids:
        j = copy.deepcopy(jobToCreate)
        j.ClientId = id
        jobs.append(j)
    DBManager.saveJobs(jobs)
    if len(jobsToCreate) > 1:
        time.sleep(10)
예제 #20
0
def getClientSettings(clientId):
    settings = DBManager.getClientSettings(clientId)
    return settings