Exemple #1
0
 def remove(cls, workflow):
     wf_busy = (workflow.status['step'] is not None
                and workflow.status['step_progress'] < 1)
     if wf_busy:
         raise util.SpreadsException(
             "Cannot remove a workflow while it is busy."
             " (active step: '{0}')".format(workflow.status['step']))
     shutil.rmtree(unicode(workflow.path))
     cls._cache[workflow.path.parent].remove(workflow)
     on_removed.send(id=workflow.id)
Exemple #2
0
    def capture(self, retake=False):
        """ Perform a single capture.

        :param retake:  Replace the previous capture
        """
        if not self.status['prepared']:
            raise util.SpreadsException("Capture was not prepared before.")
        # To prevent multiple captures from interfering with each other,
        # we hold a lock during the whole process.
        with self._capture_lock:
            self._logger.info("Triggering capture.")
            on_capture_triggered.send(self)
            parallel_capture = (
                'parallel_capture' in self.config['device'].keys() and
                self.config['device']['parallel_capture'].get()
            )
            num_devices = len(self.devices)

            # Abort when there is little free space
            if util.get_free_space(self.path) < 50*(1024**2):
                raise IOError("Insufficient disk space to take a capture.")

            futures = []
            captured_pages = []
            with concfut.ThreadPoolExecutor(
                    num_devices if parallel_capture else 1) as executor:
                self._logger.debug("Sending capture command to devices")
                for dev in self.devices:
                    page = self._get_next_capture_page(dev.target_page)
                    captured_pages.append(page)
                    futures.append(executor.submit(dev.capture,
                                                   page.raw_image))
            util.check_futures_exceptions(futures)

            if retake:
                # Remove previous n pages, where n == len(self.devices)
                self.remove_pages(*self.pages[-num_devices:])

            for page in sorted(captured_pages, key=lambda p: p.capture_num):
                page.sequence_num = len(self.pages)
                self.pages.append(page)
            self._run_hook('capture', self.devices, self.path)
            # Queue new images for hashing
            future = self._threadpool.submit(self.bag.add_payload,
                                             *(unicode(p.raw_image)
                                               for p in captured_pages))
            self._pending_tasks.append(future)

        self._save_pages()
        on_capture_succeeded.send(self, pages=captured_pages, retake=retake)
Exemple #3
0
    def remove(cls, workflow):
        """ Delete a workflow from the disk and cache.

        :param workflow:    Workflow to be deleted
        :type workflow:     :py:class:`Workflow`
        """
        wf_busy = (workflow.status['step'] is not None and
                   workflow.status['step_progress'] < 1)
        if wf_busy:
            raise util.SpreadsException(
                "Cannot remove a workflow while it is busy."
                " (active step: '{0}')".format(workflow.status['step']))
        shutil.rmtree(unicode(workflow.path))
        cls._cache[workflow.path.parent].remove(workflow)
        on_removed.send(senderId=workflow.id)