def test_capture_flip_target_pages(workflow): workflow.config["device"]["parallel_capture"] = False workflow.config["device"]["flip_target_pages"] = True workflow.prepare_capture() workflow.capture() # TODO: Verify workflow.finish_capture()
def test_capture_flip_target_pages(workflow): workflow.config['device']['parallel_capture'] = False workflow.config['device']['flip_target_pages'] = True workflow.prepare_capture() workflow.capture() # TODO: Verify workflow.finish_capture()
def test_prepare_capture(self): flow.prepare_capture(self.cams) for cam in self.cams: assert cam.prepare_capture.call_count == 1 for plug in self.plugins: assert plug.obj.prepare_capture.call_count == 1 assert plug.obj.prepare_capture.call_args_list == ( [call(self.cams)])
def test_prepare_capture(self): flow.prepare_capture(self.cams) for cam in self.cams: assert cam.prepare_capture.call_count == 1 for plug in self.plugins: assert plug.obj.prepare_capture.call_count == 1 assert plug.obj.prepare_capture.call_args_list == ([ call(self.cams) ])
def test_capture_noparallel(workflow): workflow.config["device"]["parallel_capture"] = False workflow.config["device"]["flip_target_pages"] = False for dev in workflow.devices: dev.delay = 0.25 workflow.prepare_capture() workflow.capture() assert len(workflow.pages) == 2 assert round(workflow.pages[1].raw_image.stat().st_ctime - workflow.pages[0].raw_image.stat().st_ctime, 2) >= 0.25 workflow.finish_capture()
def test_capture_noparallel(workflow): workflow.config['device']['parallel_capture'] = False workflow.config['device']['flip_target_pages'] = False for dev in workflow.devices: dev.delay = 1.0 # subsecond checks fails on some filesystems workflow.prepare_capture() workflow.capture() assert len(workflow.pages) == 2 assert round(workflow.pages[1].raw_image.stat().st_ctime - workflow.pages[0].raw_image.stat().st_ctime, 2) >= 1.0 workflow.finish_capture()
def test_capture(workflow): workflow.config['device']['parallel_capture'] = True workflow.config['device']['flip_target_pages'] = False for dev in workflow.devices: dev.delay = 1.0 # subsecond checks fails on some filesystems workflow.prepare_capture() workflow.capture() assert len(workflow.pages) == 2 assert (workflow.pages[1].raw_image.stat().st_ctime - workflow.pages[0].raw_image.stat().st_ctime) < 1.0 workflow.finish_capture()
def test_capture_noparallel(workflow): workflow.config['device']['parallel_capture'] = False workflow.config['device']['flip_target_pages'] = False for dev in workflow.devices: dev.delay = 0.25 workflow.prepare_capture() workflow.capture() assert len(workflow.pages) == 2 assert round(workflow.pages[1].raw_image.stat().st_ctime - workflow.pages[0].raw_image.stat().st_ctime, 2) >= 0.25 workflow.finish_capture()
def capture(args=None, devices=None): if not devices: devices = get_devices() if len(devices) != 2: raise DeviceException("Please connect and turn on two" " pre-configured devices! ({0} were" " found)".format(len(devices))) print(colorama.Fore.GREEN + "Found {0} devices!".format(len(devices))) if any(not x.orientation for x in devices): raise DeviceException("At least one of the devices has not been" " properly configured, please re-run the" " program with the \'configure\' option!") # Set up for capturing print("Setting up devices for capturing.") workflow.prepare_capture(devices) # Start capture loop print(colorama.Fore.BLUE + "Press 'b' to capture.") shot_count = 0 start_time = time.time() pages_per_hour = 0 capture_keys = config['capture']['capture_keys'].as_str_seq() while True: if not getch().lower() in capture_keys: break workflow.capture(devices) shot_count += len(devices) pages_per_hour = (3600/(time.time() - start_time))*shot_count status = ("\rShot {0} pages [{1:.0f}/h]" .format(colorama.Fore.GREEN + unicode(shot_count), pages_per_hour)) sys.stdout.write(status) sys.stdout.flush() workflow.finish_capture(devices) sys.stdout.write("\rShot {0} pages in {1:.1f} minutes, average speed was" " {2:.0f} pages per hour" .format(colorama.Fore.GREEN + str(shot_count), (time.time() - start_time)/60, pages_per_hour)) sys.stdout.flush()
def capture(config): path = config['path'].get() workflow = spreads.workflow.Workflow(config=config, path=path) spreads.workflow.on_created.send(workflow) capture_keys = workflow.config['core']['capture_keys'].as_str_seq() # Some closures def refresh_stats(): # Callback to print statistics if refresh_stats.start_time is not None: pages_per_hour = ((3600/(time.time() - refresh_stats.start_time)) * len(workflow.pages)) else: pages_per_hour = 0.0 refresh_stats.start_time = time.time() status = ("\rShot {0: >3} pages [{1: >4.0f}/h] " .format(len(workflow.pages), pages_per_hour)) sys.stdout.write(status) sys.stdout.flush() refresh_stats.start_time = None def trigger_loop(): is_posix = sys.platform != 'win32' old_count = len(workflow.pages) if is_posix: import select old_settings = termios.tcgetattr(sys.stdin) data_available = lambda: (select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], [])) read_char = lambda: sys.stdin.read(1) else: data_available = msvcrt.kbhit read_char = msvcrt.getch try: if is_posix: tty.setcbreak(sys.stdin.fileno()) while True: time.sleep(0.01) if len(workflow.pages) != old_count: old_count = len(workflow.pages) refresh_stats() if not data_available(): continue char = read_char() if char in tuple(capture_keys) + ('r', ): workflow.capture(retake=(char == 'r')) refresh_stats() elif char == 'f': break finally: if is_posix: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings) if len(workflow.devices) != 2: raise DeviceException("Please connect and turn on two" " pre-configured devices! ({0} were" " found)".format(len(workflow.devices))) print(colorize("Found {0} devices!".format(len(workflow.devices)), colorama.Fore.GREEN)) if any(not x.target_page for x in workflow.devices): raise DeviceException("At least one of the devices has not been" " properly configured, please re-run the" " program with the \'configure\' option!") # Set up for capturing print("Setting up devices for capturing.") workflow.prepare_capture() print("({0}) capture | (r) retake last shot | (f) finish " .format("/".join(capture_keys))) # Start trigger loop trigger_loop() workflow.finish_capture()
def test_prepare_capture(workflow): workflow.prepare_capture() assert workflow.status["prepared"] assert workflow.status["step"] == "capture" workflow.finish_capture()
def test_prepare_capture(workflow): workflow.prepare_capture() assert workflow.status['prepared'] assert workflow.status['step'] == 'capture' workflow.finish_capture()
def test_finish_capture(workflow): workflow.prepare_capture() workflow.finish_capture()
def test_prepare_capture(workflow): workflow.prepare_capture() assert workflow.prepared assert workflow.active assert workflow.step == 'capture'
def capture(config): """ Dialog to run through the capture process. :param config: Currently active global configuration :type config: :py:class:`spreads.config.Configuration` """ path = config['path'].get() workflow = spreads.workflow.Workflow(config=config, path=path) spreads.workflow.on_created.send(workflow) capture_keys = workflow.config['core']['capture_keys'].as_str_seq() # Some closures def _refresh_stats(): """ Callback that prints up-to-date capture statistics to stdout """ if _refresh_stats.start_time is not None: pages_per_hour = ((3600 / (time.time() - _refresh_stats.start_time)) * len(workflow.pages)) else: pages_per_hour = 0.0 _refresh_stats.start_time = time.time() status = ("\rShot {0: >3} pages [{1: >4.0f}/h] ".format( len(workflow.pages), pages_per_hour)) sys.stdout.write(status) sys.stdout.flush() _refresh_stats.start_time = None def _trigger_loop(): """ Waits for input on stdin and launches appropriate actions. """ is_posix = sys.platform != 'win32' old_count = len(workflow.pages) if is_posix: import select old_settings = termios.tcgetattr(sys.stdin) def data_available(): return (select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], [])) def read_char(): return sys.stdin.read(1) else: data_available = msvcrt.kbhit read_char = msvcrt.getch try: if is_posix: tty.setcbreak(sys.stdin.fileno()) while True: time.sleep(0.01) if len(workflow.pages) != old_count: old_count = len(workflow.pages) _refresh_stats() if not data_available(): continue char = read_char() if char in tuple(capture_keys) + ('r', ): # Capture or retake workflow.capture(retake=(char == 'r')) _refresh_stats() elif char == 'f': # Finish capturing break finally: if is_posix: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings) if len(workflow.devices) not in (1, 2): raise DeviceException("Please connect and turn on one or two" " pre-configured devices! ({0} were" " found)".format(len(workflow.devices))) print( colorize("Found {0} devices!".format(len(workflow.devices)), colorama.Fore.GREEN)) if any(not x.target_page for x in workflow.devices): raise DeviceException("At least one of the devices has not been" " properly configured, please re-run the" " program with the \'configure\' option!") # Set up for capturing print("Setting up devices for capturing.") workflow.prepare_capture() print("({0}) capture | (r) retake last shot | (f) finish ".format( "/".join(capture_keys))) # Start trigger loop _trigger_loop() workflow.finish_capture()
def capture(config): """ Dialog to run through the capture process. :param config: Currently active global configuration :type config: :py:class:`spreads.config.Configuration` """ path = config['path'].get() workflow = spreads.workflow.Workflow(config=config, path=path) spreads.workflow.on_created.send(workflow) capture_keys = workflow.config['core']['capture_keys'].as_str_seq() # Some closures def _refresh_stats(): """ Callback that prints up-to-date capture statistics to stdout """ if _refresh_stats.start_time is not None: pages_per_hour = ((3600/(time.time() - _refresh_stats.start_time)) * len(workflow.pages)) else: pages_per_hour = 0.0 _refresh_stats.start_time = time.time() status = ("\rShot {0: >3} pages [{1: >4.0f}/h] " .format(len(workflow.pages), pages_per_hour)) sys.stdout.write(status) sys.stdout.flush() _refresh_stats.start_time = None def _trigger_loop(): """ Waits for input on stdin and launches appropriate actions. """ is_posix = sys.platform != 'win32' old_count = len(workflow.pages) if is_posix: import select old_settings = termios.tcgetattr(sys.stdin) def data_available(): return (select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], [])) def read_char(): return sys.stdin.read(1) else: data_available = msvcrt.kbhit read_char = msvcrt.getch try: if is_posix: tty.setcbreak(sys.stdin.fileno()) while True: time.sleep(0.01) if len(workflow.pages) != old_count: old_count = len(workflow.pages) _refresh_stats() if not data_available(): continue char = read_char() if char in tuple(capture_keys) + ('r', ): # Capture or retake workflow.capture(retake=(char == 'r')) _refresh_stats() elif char == 'f': # Finish capturing break finally: if is_posix: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings) if len(workflow.devices) not in (1, 2): raise DeviceException("Please connect and turn on one or two" " pre-configured devices! ({0} were" " found)".format(len(workflow.devices))) print(colorize("Found {0} devices!".format(len(workflow.devices)), colorama.Fore.GREEN)) if any(not x.target_page for x in workflow.devices): raise DeviceException("At least one of the devices has not been" " properly configured, please re-run the" " program with the \'configure\' option!") # Set up for capturing print("Setting up devices for capturing.") workflow.prepare_capture() print("({0}) capture | (r) retake last shot | (f) finish " .format("/".join(capture_keys))) # Start trigger loop _trigger_loop() workflow.finish_capture()
def capture(config): path = config['path'].get() workflow = spreads.workflow.Workflow(config=config, path=path) spreads.workflow.on_created.send(workflow) capture_keys = workflow.config['core']['capture_keys'].as_str_seq() # Some closures def refresh_stats(): # Callback to print statistics if refresh_stats.start_time is not None: pages_per_hour = ((3600 / (time.time() - refresh_stats.start_time)) * len(workflow.pages)) else: pages_per_hour = 0.0 refresh_stats.start_time = time.time() status = ("\rShot {0: >3} pages [{1: >4.0f}/h] ".format( len(workflow.pages), pages_per_hour)) sys.stdout.write(status) sys.stdout.flush() refresh_stats.start_time = None def trigger_loop(): is_posix = sys.platform != 'win32' old_count = len(workflow.pages) if is_posix: import select old_settings = termios.tcgetattr(sys.stdin) data_available = lambda: (select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], [])) read_char = lambda: sys.stdin.read(1) else: data_available = msvcrt.kbhit read_char = msvcrt.getch try: if is_posix: tty.setcbreak(sys.stdin.fileno()) while True: time.sleep(0.01) if len(workflow.pages) != old_count: old_count = len(workflow.pages) refresh_stats() if not data_available(): continue char = read_char() if char in tuple(capture_keys) + ('r', ): workflow.capture(retake=(char == 'r')) refresh_stats() elif char == 'f': break finally: if is_posix: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings) if len(workflow.devices) != 2: raise DeviceException("Please connect and turn on two" " pre-configured devices! ({0} were" " found)".format(len(workflow.devices))) print( colorize("Found {0} devices!".format(len(workflow.devices)), colorama.Fore.GREEN)) if any(not x.target_page for x in workflow.devices): raise DeviceException("At least one of the devices has not been" " properly configured, please re-run the" " program with the \'configure\' option!") # Set up for capturing print("Setting up devices for capturing.") workflow.prepare_capture() print("({0}) capture | (r) retake last shot | (f) finish ".format( "/".join(capture_keys))) # Start trigger loop trigger_loop() workflow.finish_capture()