Beispiel #1
0
  def parseJobsFile(self, template_dir, job_file):
    jobs = []
    # We expect the job list to be named "job_list"
    filename = template_dir + job_file

    try:
      data = ParseGetPot.readInputFile(filename)
    except:        # ParseGetPot class
      print "Parse Error: " + filename
      return jobs

    # We expect our root node to be called "Jobs"
    if 'Jobs' in data.children:
      jobs_node = data.children['Jobs']

      # Get the active line
      active_jobs = None
      if 'active' in jobs_node.params:
        active_jobs = jobs_node.params['active'].split(' ')

      for jobname, job_node in jobs_node.children.iteritems():
        # Make sure this job is active
        if active_jobs != None and not jobname in active_jobs:
          continue

        # First retrieve the type so we can get the valid params
        if 'type' not in job_node.params:
          print "Type missing in " + filename
          sys.exit(1)

        params = self.factory.getValidParams(job_node.params['type'])

        params['job_name'] = jobname

        # Now update all the base level keys
        params_parsed = set()
        params_ignored = set()
        for key, value in job_node.params.iteritems():
          params_parsed.add(key)
          if key in params:
            if params.type(key) == list:
              params[key] = value.split(' ')
            else:
              if re.match('".*"', value):  # Strip quotes
                params[key] = value[1:-1]
              else:
                params[key] = value
          else:
            params_ignored.add(key)

        # Make sure that all required parameters are supplied
        required_params_missing = params.required_keys() - params_parsed
        if len(required_params_missing):
          print 'Required Missing Parameter(s): ', required_params_missing
          sys.exit(1)
        if len(params_ignored):
          print 'Ignored Parameter(s): ', params_ignored

        jobs.append(params)
    return jobs
Beispiel #2
0
  def parseJobsFile(self, template_dir, job_file):
    jobs = []
    # We expect the job list to be named "job_list"
    filename = template_dir + job_file

    try:
      data = ParseGetPot.readInputFile(filename)
    except:        # ParseGetPot class
      print "Parse Error: " + filename
      return jobs

    # We expect our root node to be called "Jobs"
    if 'Jobs' in data.children:
      jobs_node = data.children['Jobs']

      # Get the active line
      active_jobs = None
      if 'active' in jobs_node.params:
        active_jobs = jobs_node.params['active'].split(' ')

      for jobname, job_node in jobs_node.children.iteritems():
        # Make sure this job is active
        if active_jobs != None and not jobname in active_jobs:
          continue

        # First retrieve the type so we can get the valid params
        if 'type' not in job_node.params:
          print "Type missing in " + filename
          sys.exit(1)

        params = self.factory.validParams(job_node.params['type'])

        params['job_name'] = jobname

        # Now update all the base level keys
        params_parsed = set()
        params_ignored = set()
        for key, value in job_node.params.iteritems():
          params_parsed.add(key)
          if key in params:
            if params.type(key) == list:
              params[key] = value.split(' ')
            else:
              if re.match('".*"', value):  # Strip quotes
                params[key] = value[1:-1]
              else:
                params[key] = value
          else:
            params_ignored.add(key)

        # Make sure that all required parameters are supplied
        required_params_missing = params.required_keys() - params_parsed
        if len(required_params_missing):
          print 'Required Missing Parameter(s): ', required_params_missing
          sys.exit(1)
        if len(params_ignored):
          print 'Ignored Parameter(s): ', params_ignored

        jobs.append(params)
    return jobs
Beispiel #3
0
  def parse(self, filename):
    error_code = 0x00

    try:
      self.root = ParseGetPot.readInputFile(filename)
    except ParseGetPot.ParseException, ex:
      print "Parse Error in " + filename + ": " + ex.msg
      return 0x01 # Parse Error
Beispiel #4
0
  def parse(self, filename):
    error_code = 0x00

    try:
      self.root = ParseGetPot.readInputFile(filename)
    except ParseGetPot.ParseException, ex:
      print "Parse Error in " + filename + ": " + ex.msg
      return 0x01 # Parse Error
Beispiel #5
0
    def parse(self, filename):
        try:
            root = ParseGetPot.readInputFile(filename)
        except:
            print "Parse Error: " + filename
            sys.exit(1)

        self._parseNode(root)

        if len(self.params_ignored):
            print "Warning detected during test specification parsing\n  File: "  #+ os.path.join(test_dir, filename)
            print '       Ignored Parameter(s): ', self.params_ignored
Beispiel #6
0
  def parse(self, filename):
    try:
      root = ParseGetPot.readInputFile(filename)
    except:
      print "Parse Error: " + filename
      sys.exit(1)

    self._parseNode(root)

    if len(self.params_ignored):
      print "Warning detected during test specification parsing\n  File: " #+ os.path.join(test_dir, filename)
      print '       Ignored Parameter(s): ', self.params_ignored
Beispiel #7
0
    def parse(self, filename):
        error_code = 0x00

        try:
            root = ParseGetPot.readInputFile(filename)
        except:
            print "Parse Error: " + filename
            return 0x01  # Parse Error

        error_code = self._parseNode(filename, root)

        if len(self.params_ignored):
            print 'Warning detected when parsing file "' + os.path.join(os.getcwd(), filename) + '"'
            print "       Ignored Parameter(s): ", self.params_ignored

        return error_code
Beispiel #8
0
    def parse(self, filename):
        error_code = 0x00

        try:
            root = ParseGetPot.readInputFile(filename)
        except:
            print "Parse Error: " + filename
            return 0x01  # Parse Error

        error_code = self._parseNode(filename, root)

        if len(self.params_ignored):
            print 'Warning detected when parsing file "' + os.path.join(
                os.getcwd(), filename) + '"'
            print '       Ignored Parameter(s): ', self.params_ignored

        return error_code
Beispiel #9
0
def checkAndUpdate(filename):
    # Use the parser to find a specific parameter
    try:
        data = ParseGetPot.readInputFile(filename)
    except:        # ParseGetPot class
        print "*********************************************************************\nFailed to Parse " + filename + "\n"
        return

    if 'Executioner' in data.children:
        new_data = data.children['Executioner']
        if 'print_linear_residuals' in new_data.params:
            print filename
            update(filename)

    if 'Output' in data.children:
        new_data = data.children['Output']
        if 'print_linear_residuals' in new_data.params:
            print filename
            update(filename)
Beispiel #10
0
def checkAndUpdate(filename):
    # Use the parser to find a specific parameter
    try:
        data = ParseGetPot.readInputFile(filename)
    except:  # ParseGetPot class
        print "*********************************************************************\nFailed to Parse " + filename + "\n"
        return

    if 'Executioner' in data.children:
        new_data = data.children['Executioner']
        if 'print_linear_residuals' in new_data.params:
            print filename
            update(filename)

    if 'Output' in data.children:
        new_data = data.children['Output']
        if 'print_linear_residuals' in new_data.params:
            print filename
            update(filename)
Beispiel #11
0
    def parseGetPotTestFormat(self, filename):
        tests = []
        test_dir = os.path.abspath(os.path.dirname(filename))
        relative_path = test_dir.replace(self.run_tests_dir, '')

        # Filter tests that we want to run
        # Under the new format, we will filter based on directory not filename since it is fixed
        will_run = False
        if len(self.tests) == 0:
            will_run = True
        else:
            for item in self.tests:
                if test_dir.find(item) > -1:
                    will_run = True
        if not will_run:
            return tests

        try:
            data = ParseGetPot.readInputFile(filename)
        except:  # ParseGetPot class
            print "Parse Error: " + test_dir + "/" + filename
            return tests

        # We expect our root node to be called "Tests"
        if 'Tests' in data.children:
            tests_node = data.children['Tests']

            for testname, test_node in tests_node.children.iteritems():
                # First retrieve the type so we can get the valid params
                if 'type' not in test_node.params:
                    print "Type missing in " + test_dir + filename
                    sys.exit(1)

                params = self.factory.getValidParams(test_node.params['type'])

                # Now update all the base level keys
                params_parsed = set()
                params_ignored = set()
                for key, value in test_node.params.iteritems():
                    params_parsed.add(key)
                    if key in params:
                        if params.type(key) == list:
                            params[key] = value.split(' ')
                        else:
                            if re.match('".*"', value):  # Strip quotes
                                params[key] = value[1:-1]
                            else:
                                # Prevent bool types from being stored as strings.  This can lead to the
                                # strange situation where string('False') evaluates to true...
                                if params.isValid(key) and (type(params[key])
                                                            == type(bool())):
                                    # We support using the case-insensitive strings {true, false} and the string '0', '1'.
                                    if (value.lower() == 'true') or (value
                                                                     == '1'):
                                        params[key] = True
                                    elif (value.lower()
                                          == 'false') or (value == '0'):
                                        params[key] = False
                                    else:
                                        print "Unrecognized (key,value) pair: (", key, ',', value, ")"
                                        sys.exit(1)

                                # Otherwise, just do normal assignment
                                else:
                                    params[key] = value
                    else:
                        params_ignored.add(key)

                # Make sure that all required parameters are supplied
                required_params_missing = params.required_keys(
                ) - params_parsed
                if len(required_params_missing):
                    print "Error detected during test specification parsing\n  File: " + os.path.join(
                        test_dir, filename)
                    print '       Required Missing Parameter(s): ', required_params_missing
                if len(params_ignored):
                    print "Warning detected during test specification parsing\n  File: " + os.path.join(
                        test_dir, filename)
                    print '       Ignored Parameter(s): ', params_ignored

                # We are going to do some formatting of the path that is printed
                # Case 1.  If the test directory (normally matches the input_file_name) comes first,
                #          we will simply remove it from the path
                # Case 2.  If the test directory is somewhere in the middle then we should preserve
                #          the leading part of the path
                relative_path = relative_path.replace(
                    '/' + self.options.input_file_name + '/', ':')
                relative_path = re.sub(
                    '^[/:]*', '', relative_path)  # Trim slashes and colons
                formatted_name = relative_path + '.' + testname

                params['test_name'] = formatted_name
                params['test_dir'] = test_dir
                params['relative_path'] = relative_path
                params['executable'] = self.executable
                params['hostname'] = self.host_name
                params['moose_dir'] = self.moose_dir
                if params.isValid('prereq'):
                    if type(params['prereq']) != list:
                        print "Option 'prereq' needs to be of type list in " + params[
                            'test_name']
                        sys.exit(1)
                    params['prereq'] = [
                        relative_path.replace('/tests/', '') + '.' + item
                        for item in params['prereq']
                    ]

                # Build a list of test specs (dicts) to return
                tests.append(params)
        return tests
Beispiel #12
0
  def parseGetPotTestFormat(self, filename):
    tests = []
    test_dir = os.path.abspath(os.path.dirname(filename))
    relative_path = test_dir.replace(self.run_tests_dir, '')

    # Filter tests that we want to run
    # Under the new format, we will filter based on directory not filename since it is fixed
    will_run = False
    if len(self.tests) == 0:
      will_run = True
    else:
      for item in self.tests:
        if test_dir.find(item) > -1:
          will_run = True
    if not will_run:
      return tests

    try:
      data = ParseGetPot.readInputFile(filename)
    except:        # ParseGetPot class
      print "Parse Error: " + test_dir + "/" + filename
      return tests

    # We expect our root node to be called "Tests"
    if 'Tests' in data.children:
      tests_node = data.children['Tests']

      for testname, test_node in tests_node.children.iteritems():
        # First retrieve the type so we can get the valid params
        if 'type' not in test_node.params:
          print "Type missing in " + test_dir + filename
          sys.exit(1)

        params = self.factory.getValidParams(test_node.params['type'])

        # Now update all the base level keys
        params_parsed = set()
        params_ignored = set()
        for key, value in test_node.params.iteritems():
          params_parsed.add(key)
          if key in params:
            if params.type(key) == list:
              params[key] = value.split(' ')
            else:
              if re.match('".*"', value):  # Strip quotes
                params[key] = value[1:-1]
              else:
                # Prevent bool types from being stored as strings.  This can lead to the
                # strange situation where string('False') evaluates to true...
                if params.isValid(key) and (type(params[key]) == type(bool())):
                  # We support using the case-insensitive strings {true, false} and the string '0', '1'.
                  if (value.lower()=='true') or (value=='1'):
                    params[key] = True
                  elif (value.lower()=='false') or (value=='0'):
                    params[key] = False
                  else:
                    print "Unrecognized (key,value) pair: (", key, ',', value, ")"
                    sys.exit(1)

                # Otherwise, just do normal assignment
                else:
                  params[key] = value
          else:
            params_ignored.add(key)

        # Make sure that all required parameters are supplied
        required_params_missing = params.required_keys() - params_parsed
        if len(required_params_missing):
          print "Error detected during test specification parsing\n  File: " + os.path.join(test_dir, filename)
          print '       Required Missing Parameter(s): ', required_params_missing
        if len(params_ignored):
          print "Warning detected during test specification parsing\n  File: " + os.path.join(test_dir, filename)
          print '       Ignored Parameter(s): ', params_ignored

        # We are going to do some formatting of the path that is printed
        # Case 1.  If the test directory (normally matches the input_file_name) comes first,
        #          we will simply remove it from the path
        # Case 2.  If the test directory is somewhere in the middle then we should preserve
        #          the leading part of the path
        relative_path = relative_path.replace('/' + self.options.input_file_name + '/', ':')
        relative_path = re.sub('^[/:]*', '', relative_path)  # Trim slashes and colons
        formatted_name = relative_path + '.' + testname

        params['test_name'] = formatted_name
        params['test_dir'] = test_dir
        params['relative_path'] = relative_path
        params['executable'] = self.executable
        params['hostname'] = self.host_name
        params['moose_dir'] = self.moose_dir
        if params.isValid('prereq'):
          if type(params['prereq']) != list:
            print "Option 'prereq' needs to be of type list in " + params['test_name']
            sys.exit(1)
          params['prereq'] = [relative_path.replace('/tests/', '') + '.' + item for item in params['prereq']]

        # Build a list of test specs (dicts) to return
        tests.append(params)
    return tests