<commit_before>"""Sundara jāla: for a beautiful web.
"""

import os
from pygit2 import Repository

from sundara.jala import Jala

class Sundara():
    def __init__(self, dir):
        self.dir = dir
        self.generate_dir = os.path.join(dir, 'www')

    def get_files(self):
        repo = Repository(self.dir)
        return [ f.path for f in repo.index if (f.path.endswith('.md')
                and f.path.startswith('md/')) ]

    def generate(self):
        jala = Jala()
        for file in self.get_files():
            html = jala.convert(open(file).read())
            newfilename = os.path.join(self.generate_dir, file[3:-3],
                    'index.html')
            dir = os.path.dirname(newfilename)
            if dir != '' and not os.path.exists(dir):
                os.makedirs(dir)
            with open(newfilename, "w+") as newfile:
                newfile.write(html)
<commit_msg>Special treatment for index.md, added beginning of init.<commit_after>"""Sundara jāla: for a beautiful web.
"""

import os
from pygit2 import Repository

from sundara.jala import Jala

class Sundara():
    def __init__(self, dir):
        self.dir = dir
        self.md_dir = os.path.join(self.dir, 'md')
        self.generate_dir = os.path.join(self.dir, 'www')

    def get_files(self):
        repo = Repository(self.dir)
        return [ f.path[3:] for f in repo.index if (f.path.endswith('.md')
                and f.path.startswith(self.md_dir + os.path.sep)) ]

    def generate(self):
        jala = Jala()
        for file in self.get_files():
            html = jala.convert(open(file).read())
            if file == os.path.join(self.md_dir, 'index.md'):
                newfilename = os.path.join(self.generate_dir, 'index.html')
            else:
                newfilename = os.path.join(self.generate_dir, file[3:-3],
                        'index.html')
                dir = os.path.dirname(newfilename)
                if dir != '' and not os.path.exists(dir):
                    os.makedirs(dir)
            with open(newfilename, "w+") as newfile:
                newfile.write(html)

    def init(self):
        pygit2.init_repository(self.dir)
        os.makedirs(self.md_dir)
        os.makedirs(self.generate_dir)

{'fraction_non_alphanumeric': 0.12607944732297063, 'fraction_numerical': 0.0034542314335060447, 'mean_word_length': 1.825609756097561, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4358186', 'n_tokens_mistral': 763, 'n_tokens_neox': 715, 'n_words': 160}