예제 #1
0
파일: workflow.py 프로젝트: jamescr/spreads
    def prepare_capture(self):
        self._logger.info("Preparing capture.")
        self._update_status(step='capture')
        self._pool_executor = ThreadPoolExecutor(
            max_workers=multiprocessing.cpu_count())
        if any(dev.target_page is None for dev in self.devices):
            raise util.DeviceException(
                "Target page for at least one of the devicescould not be"
                "determined, please run 'spread configure' to configure your"
                "your devices.")
        with ThreadPoolExecutor(len(self.devices)) as executor:
            futures = []
            self._logger.debug("Preparing capture in devices")
            for dev in self.devices:
                futures.append(executor.submit(dev.prepare_capture, self.path))
        util.check_futures_exceptions(futures)

        flip_target = ('flip_target_pages' in self.config['device'].keys()
                       and self.config['device']['flip_target_pages'].get())
        if flip_target:
            (self.devices[0].target_page,
             self.devices[1].target_page) = (self.devices[1].target_page,
                                             self.devices[0].target_page)
        self._run_hook('prepare_capture', self.devices, self.path)
        self._run_hook('start_trigger_loop', self.capture)
        self._update_status(prepared=True)
예제 #2
0
파일: workflow.py 프로젝트: adongy/spreads
    def prepare_capture(self):
        """ Prepare capture on devices and initialize trigger plugins. """
        self._logger.info("Preparing capture.")
        self._update_status(step='capture')
        if any(dev.target_page is None for dev in self.devices):
            raise util.DeviceException(
                "Target page for at least one of the devices could not be"
                "determined, please run 'spread configure' to configure your"
                "devices.")
        with concfut.ThreadPoolExecutor(len(self.devices)) as executor:
            futures = []
            self._logger.debug("Preparing capture in devices")
            for dev in self.devices:
                futures.append(executor.submit(dev.prepare_capture))
        util.check_futures_exceptions(futures)

        flip_target = ('flip_target_pages' in self.config['device'].keys() and
                       self.config['device']['flip_target_pages'].get())
        if flip_target:
            (self.devices[0].target_page,
             self.devices[1].target_page) = (self.devices[1].target_page,
                                             self.devices[0].target_page)
        self._run_hook('prepare_capture', self.devices)
        self._run_hook('start_trigger_loop', self.capture)
        self._update_status(prepared=True)
예제 #3
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:])
예제 #4
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:])
예제 #5
0
    def prepare_capture(self):
        self._logger.info("Preparing capture.")
        self.step = 'capture'
        if any(dev.target_page is None for dev in self.devices):
            raise DeviceException(
                "Target page for at least one of the devicescould not be"
                "determined, please run 'spread configure' to configure your"
                "your devices.")
        with ThreadPoolExecutor(len(self.devices)) as executor:
            futures = []
            self._logger.debug("Preparing capture in devices")
            for dev in self.devices:
                futures.append(executor.submit(dev.prepare_capture, self.path))
        check_futures_exceptions(futures)

        flip_target = ('flip_target_pages' in self.config['device'].keys()
                       and self.config['device']['flip_target_pages'].get())
        if flip_target:
            (self.devices[0].target_page,
             self.devices[1].target_page) = (self.devices[1].target_page,
                                             self.devices[0].target_page)
        self._run_hook('prepare_capture', self.devices, self.path)
        self._run_hook('start_trigger_loop', self.capture)
        self.prepared = True
        self.active = True
예제 #6
0
    def prepare_capture(self):
        """ Prepare capture on devices and initialize trigger plugins. """
        self._logger.info("Preparing capture.")
        self._update_status(step='capture')
        is_multicam = len(self.devices) > 1
        are_targets_set = all(dev.target_page is not None
                              for dev in self.devices)
        if is_multicam and not are_targets_set:
            raise util.DeviceException(
                "Target page for at least one of the devices could not be"
                "determined, please run 'spread configure' to configure your"
                "devices.")
        with concfut.ThreadPoolExecutor(len(self.devices)) as executor:
            futures = []
            self._logger.debug("Preparing capture in devices")
            for dev in self.devices:
                futures.append(executor.submit(dev.prepare_capture))
        util.check_futures_exceptions(futures)

        flip_target = ('flip_target_pages' in self.config['device'].keys() and
                       self.config['device']['flip_target_pages'].get())
        if flip_target:
            (self.devices[0].target_page,
             self.devices[1].target_page) = (self.devices[1].target_page,
                                             self.devices[0].target_page)
        self._run_hook('prepare_capture', self.devices)
        self._run_hook('start_trigger_loop', self.capture)
        self._update_status(prepared=True)
예제 #7
0
 def finish_capture(self):
     self.step_done = True
     with ThreadPoolExecutor(len(self.devices)) as executor:
         futures = []
         self._logger.debug("Sending finish_capture command to devices")
         for dev in self.devices:
             futures.append(executor.submit(dev.finish_capture))
     check_futures_exceptions(futures)
     self._run_hook('finish_capture', self.devices, self.path)
     self._run_hook('stop_trigger_loop')
     self.prepared = False
     self.active = False
예제 #8
0
 def finish_capture(self):
     self.step_done = True
     with ThreadPoolExecutor(len(self.devices)) as executor:
         futures = []
         self._logger.debug("Sending finish_capture command to devices")
         for dev in self.devices:
             futures.append(executor.submit(dev.finish_capture))
     check_futures_exceptions(futures)
     self._run_hook('finish_capture', self.devices, self.path)
     self._run_hook('stop_trigger_loop')
     self.prepared = False
     self.active = False
예제 #9
0
파일: workflow.py 프로젝트: jamescr/spreads
 def finish_capture(self):
     if self._pool_executor:
         self._pool_executor.shutdown(wait=False)
         self._pool_executor = None
     with ThreadPoolExecutor(len(self.devices)) as executor:
         futures = []
         self._logger.debug("Sending finish_capture command to devices")
         for dev in self.devices:
             futures.append(executor.submit(dev.finish_capture))
     util.check_futures_exceptions(futures)
     self._run_hook('finish_capture', self.devices, self.path)
     self._run_hook('stop_trigger_loop')
     self._update_status(step=None, prepared=False)
예제 #10
0
파일: workflow.py 프로젝트: jamescr/spreads
 def finish_capture(self):
     if self._pool_executor:
         self._pool_executor.shutdown(wait=False)
         self._pool_executor = None
     with ThreadPoolExecutor(len(self.devices)) as executor:
         futures = []
         self._logger.debug("Sending finish_capture command to devices")
         for dev in self.devices:
             futures.append(executor.submit(dev.finish_capture))
     util.check_futures_exceptions(futures)
     self._run_hook('finish_capture', self.devices, self.path)
     self._run_hook('stop_trigger_loop')
     self._update_status(step=None, prepared=False)
예제 #11
0
파일: workflow.py 프로젝트: adongy/spreads
    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)
예제 #12
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)
예제 #13
0
파일: workflow.py 프로젝트: OliPelz/spreads
 def finish_capture(self):
     # Waits for last capture to finish
     with self._capture_lock:
         concfut.wait(self._pending_tasks)
     with concfut.ThreadPoolExecutor(len(self.devices)) as executor:
         futures = []
         self._logger.debug("Sending finish_capture command to devices")
         for dev in self.devices:
             futures.append(executor.submit(dev.finish_capture))
     util.check_futures_exceptions(futures)
     # NOTE: For performance reason, we only save the pages here, since
     # the ongoing hashing slows things down considerably during capture
     self._save_pages()
     self._run_hook('finish_capture', self.devices, self.path)
     self._run_hook('stop_trigger_loop')
     self._update_status(step=None, prepared=False)
예제 #14
0
파일: workflow.py 프로젝트: adongy/spreads
 def finish_capture(self):
     """ Wrap up capture process. """
     # Waits for last capture to finish
     with self._capture_lock:
         concfut.wait(self._pending_tasks)
     with concfut.ThreadPoolExecutor(len(self.devices)) as executor:
         futures = []
         self._logger.debug("Sending finish_capture command to devices")
         for dev in self.devices:
             futures.append(executor.submit(dev.finish_capture))
     util.check_futures_exceptions(futures)
     # NOTE: For performance reason, we only save the pages here, since
     # the ongoing hashing slows things down considerably during capture
     self._save_pages()
     self._run_hook('finish_capture', self.devices, self.path)
     self._run_hook('stop_trigger_loop')
     self._update_status(step=None, prepared=False)
예제 #15
0
파일: workflow.py 프로젝트: Gunirus/spreads
    def capture(self, retake=False):
        if self.capture_start is None:
            self.capture_start = time.time()
        self.logger.info("Triggering capture.")
        parallel_capture = ('parallel_capture' in self.config['device'].keys()
                            and self.config['device']['parallel_capture'].get()
                            )
        num_devices = 1 if not parallel_capture else 2

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

        with ThreadPoolExecutor(num_devices) as executor:
            futures = []
            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)
        self._pages_shot += len(self.devices)