<commit_before># coding=utf-8
import logging
import os
from ledman import DEBUG, config
import json

__author__ = '<NAME>'

logger = logging.getLogger(__name__)
fh = logging.FileHandler('ledman.log')
fh.setLevel(logging.INFO)
fh.setFormatter(logging.Formatter(fmt='%(asctime)s:%(levelname)s:%(name)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S'))
logger.addHandler(fh)
statefile = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ledstate.json')


def store_state(pin, brightness):
    store = open(statefile, "r")
    state = store.read()
    store.close()

    try:
        statejson = json.loads(state)
    except:
        statejson = {}

    statejson[get_color_by_pin(pin)] = brightness
    ujson = json.dumps(statejson)

    store = open(statefile,'w')
    store.write(ujson)
    store.close()


def set_gpio(pin, brightness):
    if DEBUG:
        logger.info('not actually doing echo '+pin+'='+brightness+' > /dev/pi-blaster')
        store_state(pin, brightness)
    else:
        os.system('echo "'+pin+'='+brightness+'" > /dev/pi-blaster')
        store_state(pin, brightness)
        logger.info('set pin '+pin+' at level '+brightness)

def turn_on():
    set_gpio(config.GPIO_RED, config.RED_DEFAULT)<commit_msg>fix: don't fail if no state<commit_after># coding=utf-8
import logging
import os
from ledman import DEBUG, config
import json

__author__ = '<NAME>'

logger = logging.getLogger(__name__)
fh = logging.FileHandler('ledman.log')
fh.setLevel(logging.INFO)
fh.setFormatter(logging.Formatter(fmt='%(asctime)s:%(levelname)s:%(name)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S'))
logger.addHandler(fh)
statefile = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ledstate.json')


def store_state(pin, brightness):
    try:
        store = open(statefile, "r")
        state = store.read()
        store.close()
        statejson = json.loads(state)
    except:
        statejson = {}

    statejson[get_color_by_pin(pin)] = brightness
    ujson = json.dumps(statejson)

    store = open(statefile,'w')
    store.write(ujson)
    store.close()


def set_gpio(pin, brightness):
    if DEBUG:
        logger.info('not actually doing echo '+pin+'='+brightness+' > /dev/pi-blaster')
        store_state(pin, brightness)
    else:
        os.system('echo "'+pin+'='+brightness+'" > /dev/pi-blaster')
        store_state(pin, brightness)
        logger.info('set pin '+pin+' at level '+brightness)

def turn_on():
    set_gpio(config.GPIO_RED, config.RED_DEFAULT)
{'fraction_non_alphanumeric': 0.1613809714973906, 'fraction_numerical': 0.0008028904054596548, 'mean_word_length': 3.915187376725838, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1811209', 'n_tokens_mistral': 888, 'n_tokens_neox': 854, 'n_words': 162}