<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, absolute_import

import os
import logging
import time
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
import simiki
from simiki.generators import PageGenerator
from simiki.utils import write_file

_site_config = None
_base_path = None

class YAPatternMatchingEventHandler(PatternMatchingEventHandler):
    '''Observe .md files under content directory'''
    patterns = ['*.{0}'.format(e) for e in simiki.allowed_extensions]

    def process(self, event):
        pg = PageGenerator(_site_config, _base_path, event.src_path)
        html = pg.to_html()
        category, filename = os.path.split(event.src_path)
        category = os.path.relpath(category, _site_config['source'])
        output_fname = os.path.join(
            _base_path,
            _site_config['destination'],
            category,
            '{0}.html'.format(os.path.splitext(filename)[0])
        )
        write_file(output_fname, html)

    def on_created(self, event):
        self.process(event)

    def on_modified(self, event):
        self.process(event)


def watch(site_config, base_path):
    global _site_config, _base_path
    _site_config = site_config
    _base_path = base_path

    observe_path = os.path.join(_base_path, _site_config['source'])
    event_handler = YAPatternMatchingEventHandler()<commit_msg>Add moved event<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, absolute_import

import os
import logging
import time
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
import simiki
from simiki.generators import PageGenerator
from simiki.utils import write_file

_site_config = None
_base_path = None

class YAPatternMatchingEventHandler(PatternMatchingEventHandler):
    '''Observe .md files under content directory.
    Temporary only regenerate, not delete unused files'''
    patterns = ['*.{0}'.format(e) for e in simiki.allowed_extensions]

    @staticmethod
    def generate_page(_file):
        pg = PageGenerator(_site_config, _base_path, _file)
        html = pg.to_html()
        category, filename = os.path.split(_file)
        category = os.path.relpath(category, _site_config['source'])
        output_fname = os.path.join(
            _base_path,
            _site_config['destination'],
            category,
            '{0}.html'.format(os.path.splitext(filename)[0])
        )
        write_file(output_fname, html)
        logging.debug('Regenerating: {0}'.format(_file))

    def process(self, event):
        if event.event_type in ('moved',):
            _file = event.dest_path
        else:
            _file = event.src_path
        self.generate_page(_file)

    def on_created(self, event):
        self.process(event)

    def on_modified(self, event):
        self.process(event)

    def on_moved(self, event):
        self.process(event)

def watch(site_config, base_path):
    global _site_config, _base_path
    _site_config = site_config
    _base_path = base_path

    observe_path = os.path.join(_base_path, _site_config['source'])
    event_handler = YAPatternMatchingEventHandler()
{'fraction_non_alphanumeric': 0.09764309764309764, 'fraction_numerical': 0.0027548209366391185, 'mean_word_length': 3.3806970509383376, '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': '1953569', 'n_tokens_mistral': 980, 'n_tokens_neox': 980, 'n_words': 221}