# Path: kibitzr/compat.py

# 
# Path: kibitzr/utils.py
# def normalize_filename(text):
#     """
#     ORIGIN: https://github.com/django/django/blob/master/django/utils/text.py
# 
#     Returns the given string converted to a string that can be used for a clean
#     filename. Specifically, leading and trailing spaces are removed; other
#     spaces are converted to underscores; and anything that is not a unicode
#     alphanumeric, dash, underscore, or dot, is removed.
#     >>> get_valid_filename("john's portrait in 2004.jpg")
#     'johns_portrait_in_2004.jpg'
#     """
#     return RE_VALID_FILENAME.sub('', text.strip().replace(' ', '_'))


import os
import itertools
import io
import shutil
from kibitzr.compat import sh
from .utils import normalize_filename




def report_changes(conf, content):
    return PageHistory(conf).report_changes(content)


class PageHistory(object):
    """
    Single file changes history using git
    """
    STORAGE_DIR = "pages"

    def __init__(self, conf, storage_dir=None, style=None):
        self.storage_dir = storage_dir or self.STORAGE_DIR
        self.cwd = os.path.join(
            self.storage_dir,
            normalize_filename(conf['name']),
        )
        self.target = os.path.join(self.cwd, "content")

# Path: kibitzr/compat.py

# 
# Path: kibitzr/utils.py
# def normalize_filename(text):
#     """
#     ORIGIN: https://github.com/django/django/blob/master/django/utils/text.py
# 
#     Returns the given string converted to a string that can be used for a clean
#     filename. Specifically, leading and trailing spaces are removed; other
#     spaces are converted to underscores; and anything that is not a unicode
#     alphanumeric, dash, underscore, or dot, is removed.
#     >>> get_valid_filename("john's portrait in 2004.jpg")
#     'johns_portrait_in_2004.jpg'
#     """
#     return RE_VALID_FILENAME.sub('', text.strip().replace(' ', '_'))


# Path: kibitzr/storage.py
import os
import itertools
import io
import shutil
from kibitzr.compat import sh
from .utils import normalize_filename





def report_changes(conf, content):
    return PageHistory(conf).report_changes(content)


class PageHistory(object):
    """
    Single file changes history using git
    """
    STORAGE_DIR = "pages"

    def __init__(self, conf, storage_dir=None, style=None):
        self.storage_dir = storage_dir or self.STORAGE_DIR
        self.cwd = os.path.join(
            self.storage_dir,
            normalize_filename(conf['name']),
        )
        self.target = os.path.join(self.cwd, "content")

        self.git = sh.Command('git').bake(