<commit_before>import re

class FormatterMarkup(object):
    def __init__(self, parserdata, project):
        self.parserdata = parserdata
        self.project = project
        """ Example parserdata:
        [ { "author": "test",
        "description": "<PASSWORD>",
        "task_names": ["str1", "str2"],
        "rolename" : None,
        "relative_path" : "./myplaybook.yml"}, ] """
        self.role_outfiles = {}
        self.playbook_outfiles = {}

        self.parse_data()

        self.write_files()

    def parse_data(self):
        for sourcefile in self.parserdata:
            self.write_doc(sourcefile)

    def write_doc(self, sourcefile):
        # sourcefile expected: { "author": "", "description": "", "task_names": "", .....}
        # Parse a Role
        if sourcefile["rolename"] is not None:
            m = re.match("^(.*?)%s/tasks" % sourcefile["rolename"], sourcefile["relative_path"])
            if m :
                roledir = m.group(1)
                if roledir not in self.role_outfiles:
                    self.role_outfiles[roledir] = []
                self.role_outfiles[roledir].append("Role: %s" % sourcefile["rolename"])
                self.role_outfiles[roledir].append("========================")
                self.role_outfiles[roledir].append("Author: %s\n" % sourcefile["author"])
                self.role_outfiles[roledir].append("Description: %s\n" % sourcefile["description"])
                for task_name in sourcefile["task_names"]:
                    self.role_outfiles[roledir].append("Task: %s\n" % task_name)
                self.role_outfiles[roledir].append("")
        # Parse a Playbook
        else:
            playbookpath = self.project
            if playbookpath not in self.playbook_outfiles:
                self.playbook_outfiles[playbookpath] = []
            self.playbook_outfiles[playbookpath].append("Playbook: %s" % sourcefile["relative_path"].replace(playbookpath, ""))
            self.playbook_outfiles[playbookpath].append("========================")
            self.playbook_outfiles[playbookpath].append("Author: %s\n" % sourcefile["author"])
            self.playbook_outfiles[playbookpath].append("Description: %s\n" % sourcefile["description"])
            for task_name in sourcefile["task_names"]:
                self.playbook_outfiles[playbookpath].append("Task: %s\n" % task_name)
            self.playbook_outfiles[playbookpath].append("")

        # DEBUG DEBUG DEBUG
        # print(sourcefile)

    def write_files(self):
        # Write Role Markup Files
        for rolepath in self.role_outfiles:
            filename = "%s%s" % (rolepath, "README.md")
            with open(filename, "w") as p:
                for line in self.role_outfiles[rolepath]:
                    p.write("%s\n" % line)

        # Write Playbook Markup Files
        for playbookpath in self.playbook_outfiles:
            filename = "%s%s" % (playbookpath, "README.md")
            with open(filename, "w") as p:
                for line in self.playbook_outfiles[playbookpath]:
                    p.write("%s\n" % line)<commit_msg>fixed #6. output notification of what files were generated based on annotation.<commit_after>import re

class FormatterMarkup(object):
    def __init__(self, parserdata, project):
        self.parserdata = parserdata
        self.project = project
        """ Example parserdata:
        [ { "author": "test",
        "description": "test2",
        "task_names": ["str1", "str2"],
        "rolename" : None,
        "relative_path" : "./myplaybook.yml"}, ] """
        self.role_outfiles = {}
        self.playbook_outfiles = {}

        self.parse_data()

        self.write_files()

    def parse_data(self):
        for sourcefile in self.parserdata:
            self.write_doc(sourcefile)

    def write_doc(self, sourcefile):
        # sourcefile expected: { "author": "", "description": "", "task_names": "", .....}
        # Parse a Role
        if sourcefile["rolename"] is not None:
            m = re.match("^(.*?)%s/tasks" % sourcefile["rolename"], sourcefile["relative_path"])
            if m :
                roledir = m.group(1)
                if roledir not in self.role_outfiles:
                    self.role_outfiles[roledir] = []
                self.role_outfiles[roledir].append("Role: %s" % sourcefile["rolename"])
                self.role_outfiles[roledir].append("========================")
                self.role_outfiles[roledir].append("Author: %s\n" % sourcefile["author"])
                self.role_outfiles[roledir].append("Description: %s\n" % sourcefile["description"])
                for task_name in sourcefile["task_names"]:
                    self.role_outfiles[roledir].append("Task: %s\n" % task_name)
                self.role_outfiles[roledir].append("")
        # Parse a Playbook
        else:
            playbookpath = self.project
            if playbookpath not in self.playbook_outfiles:
                self.playbook_outfiles[playbookpath] = []
            self.playbook_outfiles[playbookpath].append("Playbook: %s" % sourcefile["relative_path"].replace(playbookpath, ""))
            self.playbook_outfiles[playbookpath].append("========================")
            self.playbook_outfiles[playbookpath].append("Author: %s\n" % sourcefile["author"])
            self.playbook_outfiles[playbookpath].append("Description: %s\n" % sourcefile["description"])
            for task_name in sourcefile["task_names"]:
                self.playbook_outfiles[playbookpath].append("Task: %s\n" % task_name)
            self.playbook_outfiles[playbookpath].append("")

        # DEBUG DEBUG DEBUG
        # print(sourcefile)

    def write_files(self):
        # Write Role Markup Files
        for rolepath in self.role_outfiles:
            filename = "%s%s" % (rolepath, "README.md")
            with open(filename, "w") as p:
                for line in self.role_outfiles[rolepath]:
                    p.write("%s\n" % line)
            print("Generated Markup File %s" % filename)

        # Write Playbook Markup Files
        for playbookpath in self.playbook_outfiles:
            filename = "%s%s" % (playbookpath, "README.md")
            with open(filename, "w") as p:
                for line in self.playbook_outfiles[playbookpath]:
                    p.write("%s\n" % line)
            print("Generated Markup File %s" % filename)
{'fraction_non_alphanumeric': 0.145128604832424, 'fraction_numerical': 0.0012470771628994544, 'mean_word_length': 2.2970195272353546, 'pattern_counts': {'":': 12, '<': 4, '<?xml version=': 0, '>': 4, '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': '233492', 'n_tokens_mistral': 1885, 'n_tokens_neox': 1828, 'n_words': 352}