<commit_before>from threading import Semaphore
from rx import Observable
from rx.concurrency import Scheduler
from time import sleep
from .input import observe_mouse, observe_keyboard, observe_getch
from . import ascii
from . import screen
from . import config
from . import raster
from . import output
from .statuses import status_generator
from .state import State, set_callback
from .camera import Camera

CAMERA = Camera()
OUTPUT_CONVERTOR = ascii.Convertor(stream_size=config.CAPTURE_RESIZE, size=config.RENDER_CHARS, contrast=config.RENDER_CONTRAST)
RASTERIZER = raster.TextImage(config.RASTER_FONT)
STATUS_GEN = status_generator()
THREADS = []
QUIT_LOCK = Semaphore(0)
STATE = State()

@set_callback(STATE, 'onready')
def ready(e):
    screen.status('Ready.', clear=True)
    CAMERA.start_preview()
    return True

@set_callback(STATE, 'oncapturing')
def beforecapture(e):
    pass

@set_callback(STATE, 'oncapture')
def capture_image(e):
    stream = CAMERA.capture()
    screen.status('Processing...')
    CAMERA.stop_preview()
    text = OUTPUT_CONVERTOR.convert(stream)
    screen.output(text, center=True)
    if e.output:
        STATE.trigger('output', text=text, share=e.share)
    else:
        STATE.idle()

@set_callback(STATE, 'onidle')
def idle(e):
    sleep(3)
    STATE.done()

@set_callback(STATE, 'onoutput')
def output_image(e):
    text = e.text
    share = e.share
    image = RASTERIZER.draw_image(text, footer=output.footer_line())
    image = raster.save_image(image).getvalue()
    try:
        output.save_image(image)

        if share:
            screen.status('Printing...', newline=False)
            output.printjob(image)
            screen.status('Sending to Twitter...')
            output.tweet(image, text=next(STATUS_GEN))
    except Exception as e:
        print(e)
        raise e
    STATE.idle()

def quit():
    screen.status('Quitting.')
    CAMERA.stop()<commit_msg>Do not re-raise output exceptions<commit_after>from threading import Semaphore
from rx import Observable
from rx.concurrency import Scheduler
from time import sleep
from .input import observe_mouse, observe_keyboard, observe_getch
from . import ascii
from . import screen
from . import config
from . import raster
from . import output
from .statuses import status_generator
from .state import State, set_callback
from .camera import Camera

CAMERA = Camera()
OUTPUT_CONVERTOR = ascii.Convertor(stream_size=config.CAPTURE_RESIZE, size=config.RENDER_CHARS, contrast=config.RENDER_CONTRAST)
RASTERIZER = raster.TextImage(config.RASTER_FONT)
STATUS_GEN = status_generator()
THREADS = []
QUIT_LOCK = Semaphore(0)
STATE = State()

@set_callback(STATE, 'onready')
def ready(e):
    screen.status('Ready.', clear=True)
    CAMERA.start_preview()
    return True

@set_callback(STATE, 'oncapturing')
def beforecapture(e):
    pass

@set_callback(STATE, 'oncapture')
def capture_image(e):
    stream = CAMERA.capture()
    screen.status('Processing...')
    CAMERA.stop_preview()
    text = OUTPUT_CONVERTOR.convert(stream)
    screen.output(text, center=True)
    if e.output:
        STATE.trigger('output', text=text, share=e.share)
    else:
        STATE.idle()

@set_callback(STATE, 'onidle')
def idle(e):
    sleep(3)
    STATE.done()

@set_callback(STATE, 'onoutput')
def output_image(e):
    text = e.text
    share = e.share
    image = RASTERIZER.draw_image(text, footer=output.footer_line())
    image = raster.save_image(image).getvalue()
    try:
        output.save_image(image)

        if share:
            screen.status('Printing...', newline=False)
            output.printjob(image)
            screen.status('Sending to Twitter...')
            output.tweet(image, text=next(STATUS_GEN))
    except Exception as e:
        print(e)
        # raise e
    STATE.idle()

def quit():
    screen.status('Quitting.')
    CAMERA.stop()
{'fraction_non_alphanumeric': 0.11456713322965267, 'fraction_numerical': 0.0010368066355624676, 'mean_word_length': 3.7349693251533744, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5486609', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1241, 'n_words': 285}