<commit_before>"""The generate command."""

import os
import tarfile
from .base import Base
from paci.helpers import file_helper
from paci.helpers.pkg_index import PkgIndex


class Generate(Base):
    """Generate index files!"""

    def run(self):
        if self.options['pkg-index']:
            print("Regenerating the index file for all installed packages...\n")

        if self.options['repo-index']:
            repo_path = self.options['<path>']
            print("Generating the index file for all packages inside a repository...\n")

            if os.path.isabs(repo_path):
                repo_db = PkgIndex(repo_path + "/index.json")

                for root, dirs, files in os.walk(repo_path):
                    files = [f for f in files if not f[0] == '.']
                    dirs[:] = [d for d in dirs if not d[0] == '.']

                    if 'RECIPE.yml' in files:
                        pkg_conf = file_helper.get_pkg_conf(root + "/RECIPE.yml")
                        repo_db.add({
                            'pkg_ver': pkg_conf['version'],
                            'pkg_desc': pkg_conf['summary'],
                            'pkg_name': pkg_conf['name']
                        })
                tar = os.path.join(repo_path, "index.json.gz")
                print(tar)
                #
                # a + "," + b + "\nii"
                # "%s, %d" % (a, b)
                with tarfile.open(tar, "w:gz") as archive:
                    archive.add(repo_path + "/index.json", arcname='.')
                    # archive.addfile(tarfile.TarInfo("index.json.gz"), file("/path/to/filename.txt"))

            else:
                print("Error! Please provide an absolute path to your repository!")
                exit(1)<commit_msg>adds support for generating repo index files<commit_after>"""The generate command."""

import os
from .base import Base
from paci.helpers import file_helper
from paci.helpers.pkg_index import PkgIndex


class Generate(Base):
    """Generate index files!"""

    def run(self):
        if self.options["pkg-index"]:
            print("Regenerating the index file for all installed packages...\n")

        if self.options["repo-index"]:
            repo_path = self.options["<path>"]
            print("Generating the index file for all packages inside a repository...\n")

            if os.path.isabs(repo_path):
                repo_file = os.path.join(repo_path, "index.json")

                # Fresh new start
                file_helper.safe_delete(repo_file)
                repo_db = PkgIndex(repo_file)

                for root, dirs, files in os.walk(repo_path):
                    files = [f for f in files if not f[0] == "."]
                    dirs[:] = [d for d in dirs if not d[0] == "."]

                    if "RECIPE.yml" in files:
                        pkg_conf = file_helper.get_pkg_conf(root + "/RECIPE.yml")
                        repo_db.add({
                            "pkg_ver": pkg_conf["version"],
                            "pkg_desc": pkg_conf["summary"],
                            "pkg_name": pkg_conf["name"]
                        })

                print("Index file successfully written to: {}".format(repo_file))
            else:
                print("Error! Please provide an absolute path to your repository!")
                exit(1)
{'fraction_non_alphanumeric': 0.12094131665177242, 'fraction_numerical': 0.0017873100983020554, 'mean_word_length': 1.5672782874617737, 'pattern_counts': {'":': 3, '<': 5, '<?xml version=': 0, '>': 5, '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': '7117656', 'n_tokens_mistral': 960, 'n_tokens_neox': 897, 'n_words': 244}