Beispiel #1
0
    def capture(self, retake=False):
        with self._capture_lock:
            self._logger.info("Triggering capture.")
            self.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 get_free_space(self.path) < 50 * (1024**2):
                raise IOError("Insufficient disk space to take a capture.")

            if retake:
                # Remove last n images, where n == len(self.devices)
                map(lambda x: x.unlink(), self.images[-num_devices:])

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

            self._run_hook('capture', self.devices, self.path)
            if not retake:
                self.pages_shot += len(self.devices)

            self.on_capture_succeeded.send(self,
                                           images=self.images[-num_devices:])
Beispiel #2
0
    def capture(self, retake=False):
        with self._capture_lock:
            self._logger.info("Triggering capture.")
            self.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 get_free_space(self.path) < 50*(1024**2):
                raise IOError("Insufficient disk space to take a capture.")

            if retake:
                # Remove last n images, where n == len(self.devices)
                map(lambda x: x.unlink(), self.images[-num_devices:])

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

            self._run_hook('capture', self.devices, self.path)
            if not retake:
                self.pages_shot += len(self.devices)

            self.on_capture_succeeded.send(self,
                                           images=self.images[-num_devices:])
Beispiel #3
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)
Beispiel #4
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)