Example #1
0
  def checkParameterSets(self, data, allowTermination, name, isTool):
    success = True

    # Define the allowed attributes.
    allowedAttributes                = {}
    allowedAttributes['id']          = (str, True, True, 'id')
    allowedAttributes['description'] = (str, True, True, 'description')
    allowedAttributes['data']        = (list, True, False, None)

    # Define the allowed attributes in the data section of the parameter set.
    allowedDataAttributes           = {}
    allowedDataAttributes['id']     = (str, True, True, 'id')
    allowedDataAttributes['values'] = (list, True, True, 'values')

    # The parameter set definitions differ slightly between tools and pipelines. For tools, the argument is
    # provided as the means of identifying the node for which the supplied values apply. For pipelines, it is
    # the node within the pipeline that is supplied.
    if isTool: allowedDataAttributes['argument'] = (str, True, True, 'argument')
    else: allowedDataAttributes['node']          = (str, True, True, 'nodeId')

    # Loop over all of the defined parameter sets.
    for parameterSet in data:

      # Check that the supplied structure is a dictionary.
      if not methods.checkIsDictionary(parameterSet, allowTermination): return False

      # Check that the node has a valid ID. This is required for help messages.
      id = methods.checkForId(parameterSet, name, 'parameter sets', allowTermination, isTool)
      if not id: return False

      # Define a set of information to be used in help messages.
      helpInfo = (name, 'parameter sets', id)

      # Define a structure to hold the data.
      attributes = parameterSetData()

      # Check the attributes.
      success, attributes = methods.checkAttributes(parameterSet, allowedAttributes, attributes, allowTermination, helpInfo)

      # Loop over all of the data supplied with the parameter set and check the validity.
      for dataSet in parameterSet['data']:

        # Check that the supplied structure is a dictionary.
        if not methods.checkIsDictionary(dataSet, allowTermination): return False

        # Define a structure to hold the information for each argument.
        dataAttributes = parameterSetArguments()

        # Check the attributes.
        success, dataAttributes = methods.checkAttributes(dataSet, allowedDataAttributes, dataAttributes, allowTermination, helpInfo)

        # Append this argument to the main parameter set attributes.
        attributes.data.append(dataAttributes)

      # Store the parameter set data.
      #TODO RROR
      if attributes.id in self.sets: print('parameterSets.checkParameterSets - REPEAT', attributes.id); exit(0)
      self.sets[attributes.id] = attributes

    return success
  def checkDefinedEdges(self, data):

    if 'connect nodes' not in data: return True

    # Define the allowed attributes.
    allowedAttributes             = {}
    allowedAttributes['argument'] = (str, True, False, None)
    allowedAttributes['source']   = (str, True, False, None)
    allowedAttributes['target']   = (str, True, False, None)

    # Loop over all the defined definitions.
    for i, information in enumerate(data['connect nodes']):

      # Define a set of information to be used in help messages.
      helpInfo = (self.name, 'connect nodes', str(i))

      # Check that the supplied structure is a dictionary.
      if not methods.checkIsDictionary(information, self.allowTermination): return

      # Define the attributes object.
      attributes = edgeDefinitions()

      # Check the attributes conform to expectations.
      self.success, attributes = methods.checkAttributes(information, allowedAttributes, attributes, self.allowTermination, helpInfo)

      # Store the connection.
      attributes.source   = str(information['source'])
      attributes.target   = str(information['target'])
      attributes.argument = str(information['argument'])
      self.connections.append(attributes)
  def checkSharedNodeTasks(self):

    # Define the allowed nodes attributes.
    allowedAttributes                        = {}
    allowedAttributes['node id']             = (str, False, True, 'externalNodeId')
    allowedAttributes['stub extension']      = (str, False, True, 'stubExtension')
    allowedAttributes['task']                = (str, True, True, 'task')
    allowedAttributes['task argument']       = (str, False, True, 'taskArgument')

    # Loop over all of the defined nodes.
    for nodeId in self.sharedNodeAttributes:
      for node in self.sharedNodeAttributes[nodeId].nodes:

        # Define a set of information to be used in help messages.
        helpInfo = (self.name, 'shared nodes', nodeId)

        # Check that the supplied structure is a dictionary.
        if not methods.checkIsDictionary(node, self.allowTermination): return

        # Define the attributes object.
        attributes = nodeTaskAttributes()
  
        # Check that the supplied attributes are valid.
        self.success, attributes = methods.checkAttributes(node, allowedAttributes, attributes, self.allowTermination, helpInfo)

        #TODO INCLUDE A CHECK TO ENSURE THAT AN ALLOWED COMBINATION OF FIELDS IS PRESENT. IN PARTICULAR,
        # IF THE TASK POINTS TO A PIPELINE RATHER THAN A TOOL, ENSURE THAT THE NODE ID IS PRESENT AND NOT
        # THE TASK ARGUMENT.

        # Store the attributes.
        self.sharedNodeAttributes[nodeId].sharedNodeTasks.append(attributes)
  def checkArguments(self, data):

    # If there is not information on unique graph nodes, return.
    if 'arguments' not in data: return

    # Define the allowed nodes attributes.
    allowedAttributes                        = {}
    allowedAttributes['description']         = (str, True, True, 'description')
    allowedAttributes['hide in help']        = (bool, False, True, 'hideInHelp')
    allowedAttributes['linked argument']     = (str, False, True, 'linkedArgument')
    allowedAttributes['long form argument']  = (str, True, True, 'longFormArgument')
    allowedAttributes['node id']             = (str, True, True, 'nodeId')
    allowedAttributes['required']            = (bool, False, True, 'isRequired')
    allowedAttributes['short form argument'] = (str, True, True, 'shortFormArgument')

    # Loop over all of the argument categories.
    for category in data['arguments']:

      # Loop over all arguments in the category.
      for argumentInformation in data['arguments'][category]:
  
        # Check that the supplied structure is a dictionary.
        if not methods.checkIsDictionary(argumentInformation, self.allowTermination): return
  
        # Check that the node has a long form argument. This is required for help messages.
        longFormArgument = methods.checkForLongFormArgument(argumentInformation, self.allowTermination)
        if not longFormArgument: return
  
        # Define a set of information to be used in help messages.
        helpInfo = (self.name, 'arguments -> ' + category, longFormArgument)
  
        # Define the attributes object and add the help category.
        attributes          = pipelineArguments()
        attributes.category = category
  
        # Check the attributes conform to expectations.
        self.success, attributes = methods.checkAttributes(argumentInformation, allowedAttributes, attributes, self.allowTermination, helpInfo)
  
        # If the long form argument already exists, there is a problem. All arguments must be unique.
        if longFormArgument in self.longFormArguments: self.errors.repeatedLongFormArgument(helpInfo)
  
        # Also check that the node id is not the name of a task.
        shortFormArgument = attributes.shortFormArgument
        if shortFormArgument in self.shortFormArguments: self.errors.repeatedShortFormArgument(helpInfo)

        # If the argument shares a name with a pipeline task.
        if longFormArgument.strip('-') in self.pipelineTasks: self.errors.argumentIsTask(longFormArgument, shortFormArgument, isLongForm = True)
        if shortFormArgument.strip('-') in self.pipelineTasks: self.errors.argumentIsTask(longFormArgument, shortFormArgument, isLongForm = False)

        # Store the attributes.
        self.longFormArguments[longFormArgument]   = attributes
        self.shortFormArguments[shortFormArgument] = longFormArgument
Example #5
0
  def checkReplaceSubstring(self, arguments):
    allowedFields = {}
    allowedFields['replace'] = (str, True)
    allowedFields['with']    = (str, True)

    # Loop over all the arguments.
    for category in arguments.keys():
      for argumentAttributes in arguments[category]:

        # Check if the argument has instructions on replacing substrings.
        if 'replace substring' in argumentAttributes:

          # Get the long form argument.
          argument = argumentAttributes['long form argument']
          replace  = argumentAttributes['replace substring']

          # Loop over the list and check that each entry is a dictionary with the correct attributes.
          for data in replace:
            if not methods.checkIsDictionary(data, self.allowTermination):
              if self.allowTermination: self.errors.invalidReplaceSubstring(self.name, category, argument)
              else: return False

            # Check the contained values.
            observedFields = []
            toReplace      = None
            replaceWith    = None
            for key in data:
              value = data[key]
              if key not in allowedFields:
                if self.allowTermination: self.errors.invalidReplaceSubstring(self.name, category, argument)
                else: return False
  
              # Store the value.
              if key == 'replace': toReplace = value
              elif key == 'with': replaceWith = value

              # Record the field as having been observed.
              observedFields.append(key)

            # Store the values.
            self.arguments[argument].isReplaceSubstring    = True
            self.arguments[argument].replaceSubstring.append((str(toReplace), str(replaceWith)))

            # Check that all required fields have been set.
            for field in allowedFields.keys():
              if allowedFields[field][1] and field not in observedFields:
                if self.allowTermination: self.errors.invalidReplaceSubstring(self.name, category, argument)
                else: return False

    # Return success.
    return True
  def checkUniqueNodes(self, data):

    # If there is not information on unique graph nodes, return.
    if 'unique graph nodes' not in data: return

    # Define the allowed nodes attributes.
    allowedAttributes                             = {}
    allowedAttributes['delete files']             = (bool, False, True, 'isDelete')
    allowedAttributes['evaluate command']         = (dict, False, True, 'evaluateCommand')
    allowedAttributes['id']                       = (str, True, True, 'id')
    allowedAttributes['omit from reduced plot']   = (bool, False, True, 'omitFromReducedPlot')
    allowedAttributes['node id']                  = (str, False, True, 'nodeId')
    allowedAttributes['task']                     = (str, True, True, 'task')
    allowedAttributes['task argument']            = (str, False, True, 'taskArgument')

    # Loop over all of the defined nodes.
    for uniqueNode in data['unique graph nodes']:

      # Check that the supplied structure is a dictionary.
      if not methods.checkIsDictionary(uniqueNode, self.allowTermination): return

      # Check that the node has a valid ID. This is required for help messages.
      id = methods.checkForId(uniqueNode, self.name, 'unique graph nodes', self.allowTermination, isTool = False)
      if not id: return

      # Define a set of information to be used in help messages.
      helpInfo = (self.name, 'unique graph nodes', id)

      # Define the attributes object.
      attributes = uniqueGraphNodes()

      # Check the attributes conform to expectations.
      self.success, attributes = methods.checkAttributes(uniqueNode, allowedAttributes, attributes, self.allowTermination, helpInfo)

      # If the nodeId already exists in the attributes, a node of this name has already been seen. All 
      #nodes must have a unique name.
      if attributes.id in self.uniqueNodeAttributes: self.errors.repeatedNodeId(helpInfo)

      # Also check that the node id is not the name of a task.
      if attributes.id in self.allTasks: self.errors.nodeIdIsTaskId('unique', helpInfo)

      # Store the attributes.
      self.uniqueNodeAttributes[attributes.id] = attributes