Ejemplo n.º 1
0
 def update(self):
     newvalue = self.ui.itable.currentItem()
     # this eliminates going through the process during start up
     # otherwise it will update every value in the qtreewidget which is not needed
     if newvalue is not None:
         row = self.ui.itable.currentRow()
         # gets pathname from left column
         newkey = self.ui.itable.item(row, 0)
         path = newkey.text()
         pathn = path.split(' ')
         # removes last item of the pathname
         pathn.pop()
         if newvalue is not None:
             # this has to be 1 because of how pathn is created
             key = pathn[len(pathn) - 1]
             # finds item in the qtreewidget with the same pathname
             listnewv = self.ui.treeWidget.findItems(
                 key, Qt.MatchExactly | Qt.MatchRecursive)
             # from this list of pathnames inserts the new value into the apparatus
             for k in range(len(listnewv)):
                 if listnewv[k].parent().text(0) == pathn[len(pathn) - 2]:
                     text = newvalue.text()
                     # places the new value into the correct place in the qtreewidget
                     listnewv[k].child(0).setText(0, text)
                     # sets the new value in the apparatus and appa node
                     Apparatus.setValue(self.MyApparatus, pathn, text)
                     self.apparatus.setValue(pathn, text)
Ejemplo n.º 2
0
 def saveas(self):
     # this will build the blank apparatus
     # not needed for template apparatus because it already has a structure
     if self.apptype == 'blank':
         for k in range(self.ui.treeWidget.topLevelItemCount()):
             parent = self.ui.treeWidget.topLevelItem(k)
             pathn = []
             i = 0
             if parent.child(0) is not None:
                 while parent.child(0) is not None:
                     child = parent.child(0)
                     Parent = parent.text(0)
                     # makes a list of the parents in reverse order
                     # stops when it reaches the bottom item (no child)
                     # inserts child at the end of the array
                     pathn.insert(i, Parent)
                     parent = child
                     i = i + 1
                 pathn.insert(i, parent.text(0))
                 # sets Child equal to it's own value for setValue function
                 Child = child.text(0)
                 # updates the apparatus
                 Apparatus.setValue(self.MyApparatus, pathn, Child)
                 # needs to update the appa node
     # gets the filename from the textbox and sets the apparatus to that name
     filename = self.ui.fnamebox.text()
     filename = self.MyApparatus
     # logs the apparatus as a JSON
     Apparatus.logApparatus(filename)
Ejemplo n.º 3
0
    def getRequirements(self, device, procedure, uuid=None):
        if not self._gui_node:
            logger.warning('Cannot fetch requirements without guiNode')
            return

        if device in ('Procedures', 'Project_Procedures', ''):
            if device == 'Procedures':
                module = Procedures
            elif device == 'Project_Procedures':
                module = Project_Procedures
            else:
                module = (
                    Procedures if procedure in dir(Procedures) else Project_Procedures
                )
            try:
                apparatus = Apparatus()
                executor = Executor()
                f = getattr(module, procedure)(apparatus, executor)
                result = {
                    k: value_to_str(v['value']) for k, v in f.requirements.items()
                }
            except Exception as e:
                logger.warning(
                    f'Cannot fetch requirements of {device}_{procedure}: {str(e)}'
                )
                result = {}
        else:
            node = self._device_nodes.get(device, 'procexec')
            reqs = self._gui_node.executor.getRequirements(device, procedure, node)
            result = {k: '' for k in reqs}

        if uuid:
            proc = None
            for proc in self._procedures:
                if proc['uuid'] == uuid:
                    break
            if not proc:
                logger.error(f'No proecedure with UUID {uuid} found.')

            result.update({item['key']: item['value'] for item in proc['requirements']})

        return [{'key': k, 'value': v} for k, v in result.items()]