<commit_before>import codecs
import distutils
import regulations
import os
import shutil
import subprocess

from django.core.management.base import BaseCommand, CommandError
from django.core.management import call_command

class Command(BaseCommand):
    help = 'Build the frontend, including overrides.'

    def find_regulations_directory(self):
        child = regulations.__file__
        child_dir = os.path.split(child)[0]
        return os.path.split(child_dir)[0]

    def run_collectstatic(self):
        call_command("collectstatic", noinput=True)

    def write_file(self, filename, markup):
        """ Write out a file using the UTF-8 codec. """
        f = codecs.open(filename, 'w', encoding='utf-8')
        f.write(markup)
        f.close()

    def get_regulation_version(self, **options):
        """ Get the regulation part and regulation version from the command line arguments. """
        regulation_part = options.get('regulation_part')
        regulation_version = options.get('regulation_version')

        if not regulation_part or not regulation_version:
            usage_string = "Usage: python manage.py generate_regulation  %s\n"  % Command.args
            raise CommandError(usage_string)
        return (regulation_part, regulation_version)

    def handle(self, *args, **options):
        import rlcompleter; import pdb; zcomp = locals(); zcomp.update(globals()); pdb.Pdb.complete = rlcompleter.Completer(zcomp).complete; pdb.set_trace()
        target = "./frontend_build"
        # put in some checks before this?
        shutil.rmtree("./compiled")
        os.environ["TMDDIR"] = target
        self.run_collectstatic()
        regulations_directory = self.find_regulations_directory()
        for f in (
            "package.json",
            "bower.json",
            "Gruntfile.js",
            ".eslintrc"
        ):
            shutil.copy("%s/%s" %(regulations_directory, f), target)
        with codecs.open("%s/config.json" % target, "w", encoding="utf-8") as f:
            f.write('{"frontEndPath": "static/regulations"}')
        os.chdir(target)
        return_code = subprocess.call(["npm", "install", "grunt-cli", "bower"])
        return_code = subprocess.call(["npm", "install"])
        shutil.copytree("./static/regulations", "../compiled")
        os.chdir("..")<commit_msg>Working version of compile_frontend command.<commit_after>import codecs
import distutils
import regulations
import os
import shutil
import subprocess

from django.core.management.base import BaseCommand, CommandError
from django.core.management import call_command

class Command(BaseCommand):
    help = 'Build the frontend, including local overrides.'

    def find_regulations_directory(self):
        child = regulations.__file__
        child_dir = os.path.split(child)[0]
        return os.path.split(child_dir)[0]

    def run_collectstatic(self):
        return_code = subprocess.call(["python", "manage.py", "collectstatic",
                                       "--noinput"])

    def handle(self, *args, **options):
        build_dir = "./frontend_build"
        target_dir = "./compiled"
        for dirpath in (build_dir, target_dir):
            if os.path.exists(dirpath):
                shutil.rmtree(dirpath)
        os.environ["TMPDIR"] = build_dir
        self.run_collectstatic()
        regulations_directory = self.find_regulations_directory()
        for f in (
            "package.json",
            "bower.json",
            "Gruntfile.js",
            ".eslintrc"
        ):
            shutil.copy("%s/%s" %(regulations_directory, f),
                        "%s/" % build_dir)
        with codecs.open("%s/config.json" % build_dir, "w", encoding="utf-8") as f:
            f.write('{"frontEndPath": "static/regulations"}')
        os.chdir(build_dir)
        return_code = subprocess.call(["npm", "install", "grunt-cli", "bower"])
        return_code = subprocess.call(["npm", "install"])
        os.chdir("..")
        shutil.copytree("%s/static/regulations" % build_dir, target_dir)
{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.001976284584980237, 'mean_word_length': 2.711274060494959, 'pattern_counts': {'":': 2, '<': 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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3743865', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1158, 'n_words': 259}