Exemplo n.º 1
0
    def execute(self, inputs=None, output=None, load_targets=False):
        """
        Run this step, recursively running or loading inputs.
        Used in bin/run_step.py which is run by drake.
        Args:
            inputs: collection of steps that should be loaded
            output: step that should be dumped after it is run
            load_targets (boolean): load all steps which are targets.
                This argument is not used by run_step.py because target
                does not get serialized. But it can be useful for
                running steps directly.
        """
        if self == output:
            if os.path.exists(self._dump_dirname):
                shutil.rmtree(self._dump_dirname)
            if os.path.exists(self._target_filename):
                os.remove(self._target_filename)
            os.makedirs(self._dump_dirname)

        if inputs is None:
            inputs = []

        if not self.has_result():
            if self in inputs or (load_targets and self.target):
                logging.info('Loading\n%s' % util.indent(str(self)))
                self.load()
            else:
                for i in self.inputs:
                    i.execute(inputs=inputs,
                              output=output,
                              load_targets=load_targets)

                args, kwargs = self.map_inputs()
                logging.info('Running\n%s' % util.indent(str(self)))
                self.set_result(self.run(*args, **kwargs))

        if self == output:
            logging.info('Dumping\n%s' % util.indent(str(self)))
            self.dump()
            util.touch(self._target_filename)
Exemplo n.º 2
0
Arquivo: step.py Projeto: dssg/drain
def load(steps):
    """
    safely load steps, excluding those that fail
    """
    loaded = []
    for s in steps:
        try:
            s.load()
            loaded.append(s)
        except:
            logging.warn('Error during step load:\n%s' % util.indent(traceback.format_exc()))
            pass
    return loaded
Exemplo n.º 3
0
def load(steps):
    """
    safely load steps, excluding those that fail
    """
    loaded = []
    for s in steps:
        try:
            s.load()
            loaded.append(s)
        except:
            logging.warn('Error during step load:\n%s' %
                         util.indent(traceback.format_exc()))
            pass
    return loaded
Exemplo n.º 4
0
Arquivo: step.py Projeto: dssg/drain
 def execute(self, inputs=None, output=None, load_targets=False):
     """ 
     Run this step, recursively running or loading inputs. 
     Used in bin/run_step.py which is run by drake.
     Args:
         inputs: collection of steps that should be loaded
         output: step that should be dumped after it is run
         load_targets (boolean): load all steps which are targets.
             This argument is not used by run_step.py because target 
             does not get serialized. But it can be useful for 
             running steps directly.
     """
     if self == output:
         if os.path.exists(self._dump_dirname):
             shutil.rmtree(self._dump_dirname)
         if os.path.exists(self._target_filename):
             os.remove(self._target_filename)
         os.makedirs(self._dump_dirname)
 
     if inputs is None:
         inputs = []
 
     if not self.has_result():
         if self in inputs or (load_targets and self.is_target()):
             logging.info('Loading\n%s' % util.indent(str(self)))
             self.load()
         else:
             for i in self.inputs:
                 i.execute(inputs=inputs, output=output, load_targets=load_targets)
 
             args, kwargs = self.map_inputs()
             logging.info('Running\n%s' % util.indent(str(self)))
             self.set_result(self.run(*args, **kwargs))
 
     if self == output:
         self.dump()
         util.touch(self._target_filename)