Example #1
0
 def clone_from_parent(self, case_dir):
    """Clones the case from its parent case."""
    try:
       parent_dir = self._parent_runner.case_dir
       if not _op.isdir(_op.join(case_dir, 'system')):
          _fu.clone_case(parent_dir, case_dir, verbose=False)
       return True
    except Exception:
       import sys
       e = sys.exc_info()[1]
       _fu.cerror("Failed to clone", parent_dir, ":", str(e),
             file=sys.stderr)
       return False
Example #2
0
   def run(self, step=None, test_mode=False, verbose=False):
      """Run the case as a whole or a specific step.

      A step is only run if at least one of the following applies:
         * `test_mode` is True.
         * The stamp file of the test (usually the log file) does not exist.
         * The stamp file of the preceeding step is newer than the one for this
           step.

      Every step is assumed to depend on the preceeding step, and above
      criteria propagate up to the first step if required (except for
      `test_mode` which only applies to the specified step, or to all steps if
      `step` is None). This means that if you specify a step to be run and any
      of the preceeding steps has not been run or is out of date, that step and
      all the ones in between will also be run.

      Parameters
      ----------
      step      : Name of the step to be run. If `None`, try to run all steps.
      test_mode : Run in testing mode.
      verbose   : Echo the output to standard output.

      Returns
      -------
      True if the steps all ran successfully, False otherwise.

      """
      import sys
      assert len(self._stepnames) > 0, "No steps registered"

      if step == None:
         step = self._stepnames[-1]
      assert step in self._stepnames, "Step "+step+" not registered"

      if test_mode:
         self.clone_test()
         case_dir = self.test_dir
      else:
         case_dir = self.case_dir
      case_dir = _op.abspath(case_dir)

      echo('Running case '+case_dir)

      stat = True
      fmt = '    %%-%ds  ${HIDE_CURSOR}'%max(
            30, max(map(len, self._stepnames)))
      last = self._stepnames.index(step)
      try:
         for i, s in enumerate(self._stepnames):
            if not verbose:
               _fu.cecho(fmt%s, end='')
            sys.stdout.flush()
            stamp = _op.join(case_dir, self._steps[s]['stamp'])
            do_skip = False
            if test_mode and self._steps[s]['skip_test']:
               do_skip = True
            else:
               if i > last:
                  do_skip = True
               elif _op.isfile(stamp):
                  do_skip = True
                  if i > 0:
                     old_s = self._stepnames[i-1]
                     old_stamp = _op.join(
                           case_dir, self._steps[old_s]['stamp'])
                     if _op.getmtime(old_stamp) > _op.getmtime(stamp):
                        do_skip = False
            if do_skip:
               if not verbose:
                  _fu.cecho('${YELLOW}[ SKIP ]${NORMAL}')
               continue

            try:
               if verbose:
                  stamp_file = _fu.Tee(stamp, 'wt')
               else:
                  stamp_file = open(stamp, 'wt')
               stat = self._steps[s]['cmd'](case_dir, stamp_file, test_mode)
               if not verbose:
                  if stat:
                     _fu.cecho('${GREEN}[  OK  ]${NORMAL}')
                  else:
                     _fu.cecho('${RED}${BOLD}[FAILED]${NORMAL}')
            except BaseException:
               e = sys.exc_info()[1]
               if not verbose:
                  _fu.cecho('${RED}${BOLD}[FAILED]${NORMAL}')
               _fu.cerror("Step %s in case %s raised an exception:\n%s"%
                     (s, case_dir, str(e)), file=sys.stderr)
               stat = False
               raise
            if not stat:
               break
      finally:
         _fu.cecho('${SHOW_CURSOR}', end='')
      return stat