<commit_before>import os
import sys
import logging
import time
import traceback
import RPi.GPIO as GPIO

import mpd
from PIL import Image
from PIL import ImageDraw
from Adafruit_LED_Backpack import BicolorMatrix8x8

import settings
from rotary.rotary_thread import RotaryThread
#from httpd.server import Server


logger = logging.getLogger('piradio')

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

# display = BicolorMatrix8x8.BicolorMatrix8x8()
# display.begin()


######################################################################
# Display Functions
######################################################################


def fill_display(r, g):
    display.clear()
    image = Image.new('RGB', (8, 8))
    draw = ImageDraw.Draw(image)
    draw.rectangle((0, 0, 7, 7), fill=(r, g, 0))
    display.set_image(image)
    display.write_display()


def drawPixel(x, y, c):
    display.clear()
    display.set_pixel(x, y, c)
    display.write_display()


def splash():
    fill_display(255, 0)
    time.sleep(1)
    fill_display(0, 255)
    time.sleep(1)
    fill_display(255, 255)
    time.sleep(1)
    display.clear()
    display.write_display()


######################################################################
# MPD Functions
######################################################################


def getMPDClient():
    client = mpd.MPDClient(use_unicode=True)
    client.connect("localhost", 6600)
    return client


######################################################################
# Callbacks
######################################################################


def rotary1_left():
    logger.debug("rotary1_left")
    client = getMPDClient()
    client.previous()
    client.close()


def rotary1_right():
    logger.debug("rotary1_right")
    client = getMPDClient()
    client.next()
    client.close()


def rotary1_push(ev=None):
    logger.debug("rotary1_push")
    client = getMPDClient()
    client.pause()
    client.close()
    time.sleep(.5)


def rotary2_left():
    logger.debug("rotary2_left")
    client = getMPDClient()
    status = client.status()
    volume = int(status['volume'])
    client.setvol(volume - 1)
    client.close()


def rotary2_right():
    logger.debug("rotary2_right")
    client = getMPDClient()
    status = client.status()
    volume = int(status['volume'])
    client.setvol(volume + 1)
    client.close()


def rotary2_push(ev=None):
    logger.debug("rotary2_push")
    client = getMPDClient()
    client.pause()
    client.close()
    time.sleep(.5)


######################################################################
# Main Loop
######################################################################


def main():
    # Setup Logging
    hdlr = logging.FileHandler(settings.LOG)
    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    hdlr.setFormatter(formatter)
    logger.addHandler(hdlr)
    hdlr = logging.StreamHandler(sys.stdout)
    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    hdlr.setFormatter(formatter)
    logger.addHandler(hdlr)
    if settings.DEBUG:
        logger.setLevel(logging.DEBUG)
        logger.info("DEBUG level logging")
    else:
        logger.setLevel(logging.INFO)
        logger.info("INFO level logging")
        logger.info("Starting up...")

    # Splash the display
    # splash()

    rotary1_thread = None<commit_msg>better debug statements<commit_after>import os
import sys
import logging
import time
import traceback
import RPi.GPIO as GPIO

import mpd
from PIL import Image
from PIL import ImageDraw
from Adafruit_LED_Backpack import BicolorMatrix8x8

import settings
from rotary.rotary_thread import RotaryThread
#from httpd.server import Server


logger = logging.getLogger('piradio')

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

# display = BicolorMatrix8x8.BicolorMatrix8x8()
# display.begin()


######################################################################
# Display Functions
######################################################################


def fill_display(r, g):
    display.clear()
    image = Image.new('RGB', (8, 8))
    draw = ImageDraw.Draw(image)
    draw.rectangle((0, 0, 7, 7), fill=(r, g, 0))
    display.set_image(image)
    display.write_display()


def drawPixel(x, y, c):
    display.clear()
    display.set_pixel(x, y, c)
    display.write_display()


def splash():
    fill_display(255, 0)
    time.sleep(1)
    fill_display(0, 255)
    time.sleep(1)
    fill_display(255, 255)
    time.sleep(1)
    display.clear()
    display.write_display()


######################################################################
# MPD Functions
######################################################################


def getMPDClient():
    client = mpd.MPDClient(use_unicode=True)
    client.connect("localhost", 6600)
    return client


######################################################################
# Callbacks
######################################################################


def rotary1_left():
    logger.debug("rotary1_left")
    client = getMPDClient()
    logger.debug("[ PREVIOUS ]")
    client.previous()
    client.close()


def rotary1_right():
    logger.debug("rotary1_right")
    client = getMPDClient()
    logger.debug("[ NEXT ]")
    client.next()
    client.close()


def rotary1_push(ev=None):
    logger.debug("rotary1_push")
    client = getMPDClient()
    logger.debug("[ PAUSE ]")
    client.pause()
    client.close()
    time.sleep(1)


def rotary2_left():
    logger.debug("rotary2_left")
    client = getMPDClient()
    status = client.status()
    volume = int(status['volume']) - 1
    logger.debug("[ VOLUME %d ]" % volume)
    client.setvol(volume)
    client.close()


def rotary2_right():
    logger.debug("rotary2_right")
    client = getMPDClient()
    status = client.status()
    volume = int(status['volume']) + 1
    logger.debug("[ VOLUME %d ]" % volume)
    client.setvol(volume)
    client.close()


def rotary2_push(ev=None):
    logger.debug("rotary2_push")
    client = getMPDClient()
    logger.debug("[ PAUSE ]")
    client.pause()
    client.close()
    time.sleep(1)


######################################################################
# Main Loop
######################################################################


def main():
    # Setup Logging
    hdlr = logging.FileHandler(settings.LOG)
    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    hdlr.setFormatter(formatter)
    logger.addHandler(hdlr)
    hdlr = logging.StreamHandler(sys.stdout)
    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    hdlr.setFormatter(formatter)
    logger.addHandler(hdlr)
    if settings.DEBUG:
        logger.setLevel(logging.DEBUG)
        logger.info("DEBUG level logging")
    else:
        logger.setLevel(logging.INFO)
        logger.info("INFO level logging")
        logger.info("Starting up...")

    # Splash the display
    # splash()

    rotary1_thread = None
{'fraction_non_alphanumeric': 0.268515870746354, 'fraction_numerical': 0.014583929082070346, 'mean_word_length': 4.263355906696765, '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': '990854', 'n_tokens_mistral': 2209, 'n_tokens_neox': 2033, 'n_words': 405}