<commit_before>import sys
import pyinotify as inf
import asyncore
import logbook

from storm import util
from storm import conf
from storm import bolt


class EventHandler(inf.ProcessEvent):
    font = conf.CONFIG['font']['name']
    separator_color = conf.CONFIG['colors']['sep']

    width = util.get_screen_size()

    def __init__(self, *args, **kwargs):
        # TODO: get LoggedClass to roll with multiple inheritance.
        name = self.__class__.__name__
        self.log = logbook.Logger(name)
        self.log.debug('Loaded logger for {0}', name)

    def setup(self):
        self.left = bolt.BoltLine()
        self.left.register_bolts(*conf.CONFIG['items']['left'])

        self.right = bolt.BoltLine()
        self.right.register_bolts(*conf.CONFIG['items']['right'])

    def handle(self, event):
        if event and 'debug' in conf.CONFIG:
            self.log.debug('{0} on: {1}', event.maskname, event.pathname)

        spacer = "^pa(%d)" % (self.width - self.right.width() - 90)
        line = "%s%s%s" % (self.left.compile(), spacer, self.right.compile())

        assert '\n' not in line, 'Line break in output'

        sys.stdout.write('\n' + line)
        sys.stdout.flush()

    process_IN_DELETE = handle
    process_IN_CLOSE_WRITE = handle
    process_IN_MODIFY = handle


class Cloud():
    def start(self):
        mask = inf.IN_DELETE | inf.IN_CREATE | inf.IN_MODIFY
        wm = inf.WatchManager()
        eh = EventHandler()
        eh.setup()
        inf.AsyncNotifier(wm, eh)
        wm.add_watch(conf.ROOT, mask, rec=True)

        # Run the initial grab of data
        eh.handle(None)

        asyncore.loop()


def main():
    cloud = Cloud()
    cloud.start()

if __name__ == '__main__':
    main()<commit_msg>Clean up cloud.py<commit_after>import sys
import pyinotify as inf
import asyncore
import logbook

from storm import util
from storm import conf
from storm import bolt


class Cloud(inf.ProcessEvent):
    """
    The representation layer

    This class is solely concerned with watching the data directory for
    changes, and send a newly constructed line into dzen upon changes.

    """

    def __init__(self, *args, **kwargs):
        # TODO: get LoggedClass to roll with multiple inheritance.
        name = self.__class__.__name__
        self.log = logbook.Logger(name)
        self.log.debug('Loaded logger for {0}', name)

    def setup(self):
        self.setup_lines()
        self.get_screen_width()

    def setup_lines(self):
        self.left = bolt.BoltLine()
        self.left.register_bolts(*conf.CONFIG['items']['left'])

        self.right = bolt.BoltLine()
        self.right.register_bolts(*conf.CONFIG['items']['right'])

    def get_screen_width(self):
        self.width = util.get_screen_size()

    def process_default(self, event):
        if event and 'debug' in conf.CONFIG:
            self.log.debug('{0} on: {1}', event.maskname, event.pathname)

        spacer = "^pa(%d)" % (self.width - self.right.width() - 90)
        line = "%s%s%s" % (self.left.compile(), spacer, self.right.compile())

        assert '\n' not in line, 'Line break in output'

        sys.stdout.write('\n' + line)
        sys.stdout.flush()

    def start(self):
        mask = inf.IN_DELETE | inf.IN_CREATE | inf.IN_MODIFY
        wm = inf.WatchManager()
        inf.AsyncNotifier(wm, self)
        wm.add_watch(conf.ROOT, mask, rec=True)

        # Run the initial grab of data
        self.process_default(None)

        asyncore.loop()


def main():
    cloud = Cloud()
    cloud.setup()
    cloud.start()

if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.12877319302132373, 'fraction_numerical': 0.0027693159789531985, 'mean_word_length': 2.6265060240963853, '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': '2076452', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1108, 'n_words': 290}