Пример #1
0
    def harvestTools(self):
        self.createUserToolsList()

        catDb = self.db[cfg.SEARCH_CATEGORY_TOOLS]

        self.generateBuiltInCommands(catDb)

        for toolsConfig in [cfg.TOOLS_CFG, cfg.TOOLS_CFG_USER]:
            toolsList = self.getToolsList(toolsConfig)

            for rec in toolsList:
                cd = self.createCommandDesc(rec)
                if not cd:
                    continue

                nameL = cd.name.lower()
                if (
                    nameL in catDb
                    or nameL in self.db[cfg.SEARCH_CATEGORY_CMD]
                    or nameL in self.db[cfg.SEARCH_CATEGORY_CMD_RT]
                ):
                    message_box.warning(
                        'Cannot add tool "{}" defined in:\n{}\nThat name already exists.'.format(cd.name, toolsConfig)
                    )
                    continue

                catDb[nameL] = cd
Пример #2
0
    def harvestTools(self):
        self.createUserToolsList()

        catDb = self.db[cfg.SEARCH_CATEGORY_TOOLS]

        self.generateBuiltInCommands(catDb)

        for toolsConfig in [cfg.TOOLS_CFG, cfg.TOOLS_CFG_USER]:
            toolsList = self.getToolsList(toolsConfig)

            for rec in toolsList:
                cd = self.createCommandDesc(rec)
                if not cd:
                    continue

                nameL = cd.name.lower()
                if nameL in catDb or \
                        nameL in self.db[cfg.SEARCH_CATEGORY_CMD] or \
                        nameL in self.db[cfg.SEARCH_CATEGORY_CMD_RT]:
                    message_box.warning(
                        'Cannot add tool "{}" defined in:\n{}\nThat name already exists.'
                        .format(cd.name, toolsConfig))
                    continue

                catDb[nameL] = cd
Пример #3
0
 def getRecValue(self, rec, fieldName):
     value = rec.get(fieldName, None)
     if value is None:
         return ""
     if not isinstance(value, str):
         message_box.warning(
             'Bad type for field "{}". Only "str" allowed. Replaced with empty string.'.format(fieldName),
             textDetailed=str(rec),
         )
         return ""
     return value.strip()
Пример #4
0
 def getRecValue(self, rec, fieldName):
     value = rec.get(fieldName, None)
     if value is None:
         return ''
     if not isinstance(value, str):
         message_box.warning(
             'Bad type for field "{}". Only "str" allowed. Replaced with empty string.'
             .format(fieldName),
             textDetailed=str(rec))
         return ''
     return value.strip()
Пример #5
0
    def createCommandDesc(self, rec):
        name = self.getRecValue(rec, cfg.TOOL_CFG_FIELD_NAME)
        if not name:
            message_box.warning("Tools without names not allowed. Skipped.", textDetailed=str(rec))
            return
        mel = self.getRecValue(rec, cfg.TOOL_CFG_FIELD_MEL)
        python = self.getRecValue(rec, cfg.TOOL_CFG_FIELD_PYTHON)
        if mel and python:
            message_box.warning(
                'Both "mel" and "python" fields present in tool. Provide only one.', textDetailed=str(rec)
            )
            return
        annotation = self.getRecValue(rec, cfg.TOOL_CFG_FIELD_ANNOTATION)

        if python:
            cd = command_desc.CommandDescPython(name)
            cd.run = python
        else:
            cd = command_desc.CommandDescMel(name)
            cd.run = mel
        cd.annotation = annotation

        return cd
Пример #6
0
    def createCommandDesc(self, rec):
        name = self.getRecValue(rec, cfg.TOOL_CFG_FIELD_NAME)
        if not name:
            message_box.warning('Tools without names not allowed. Skipped.',
                                textDetailed=str(rec))
            return
        mel = self.getRecValue(rec, cfg.TOOL_CFG_FIELD_MEL)
        python = self.getRecValue(rec, cfg.TOOL_CFG_FIELD_PYTHON)
        if mel and python:
            message_box.warning(
                'Both "mel" and "python" fields present in tool. Provide only one.',
                textDetailed=str(rec))
            return
        annotation = self.getRecValue(rec, cfg.TOOL_CFG_FIELD_ANNOTATION)

        if python:
            cd = command_desc.CommandDescPython(name)
            cd.run = python
        else:
            cd = command_desc.CommandDescMel(name)
            cd.run = mel
        cd.annotation = annotation

        return cd