<commit_before>"""Script for activating/creating a project in the projects folder."""
import argparse
import os
from plumbum import local
from plumbum.cmd import ln


class DefaultsInstaller:
    """Adds subdirectories to defaults/commands and defaults/projects."""

    def _args(self):
        """Get command line args."""
        parser = argparse.ArgumentParser()

        group = parser.add_mutually_exclusive_group(required=True)
        group.add_argument(
            '--git',
            action="store_true",
            dest="use_git",
            help='Use a git repository'
        )
        group.add_argument(
            '--ln',
            action="store_false",
            dest="use_git",
            help='Use a symlink'
        )

        group = parser.add_mutually_exclusive_group(required=True)
        group.add_argument('--commands')
        group.add_argument('--projects')
        return parser.parse_args()

    def _install(self, dest_folder, url, use_git):
        """Install resource 'url' into dest_folder."""
        if use_git:
            with local.cwd(dest_folder):
                local['git']['clone', url]()
        else:
            ln("-s", os.path.abspath(url), dest_folder)

    def _install_commands(self, url, use_git):
        """Install the folder with the default commands."""
        commands_dir = os.path.join(
            self.source_folder, "defaults", "commands"
        )
        self._install(commands_dir, url, use_git)

    def _install_projects(self, url, use_git):
        """Install the folder with the default commands."""
        projects_dir = os.path.join(
            self.source_folder, "defaults", "projects"
        )
        self._install(projects_dir, url, use_git)

    def run(self):
        """Activate or create a project in the projects folder."""
        bin_folder = os.path.dirname(__file__)
        self.source_folder = os.path.dirname(bin_folder)
        args = self._args()

        url, install = (
            (args.commands, self._install_commands)
            if args.commands else
            (args.projects, self._install_projects)
        )

        if not args.use_git and not os.path.exists(url):
            print("Error: path not found: %s" % url)
            return

        install(url, args.use_git)<commit_msg>Improve error messages for dodo-install-defaults<commit_after>"""Script for activating/creating a project in the projects folder."""
import argparse
import os
import sys

from plumbum import local
from plumbum.cmd import ln
from plumbum.commands.processes import ProcessExecutionError


class DefaultsInstaller:
    """Adds subdirectories to defaults/commands and defaults/projects."""

    def _args(self):
        """Get command line args."""
        parser = argparse.ArgumentParser()

        group = parser.add_mutually_exclusive_group(required=True)
        group.add_argument(
            '--git',
            action="store_true",
            dest="use_git",
            help='Use a git repository'
        )
        group.add_argument(
            '--ln',
            action="store_false",
            dest="use_git",
            help='Use a symlink'
        )

        group = parser.add_mutually_exclusive_group(required=True)
        group.add_argument('--commands')
        group.add_argument('--projects')
        return parser.parse_args()

    def _report_error(self, msg):
        sys.stderr.write(msg + os.linesep)

    def _install(self, dest_folder, url, use_git):
        """Install resource 'url' into dest_folder."""
        try:
            if use_git:
                with local.cwd(dest_folder):
                    local['git']['clone', url]()
            else:
                if not os.path.exists(url):
                    self._report_error("Error: path not found: %s" % url)
                    return False
                ln("-s", os.path.abspath(url), dest_folder)
        except ProcessExecutionError:
            if use_git:
                self._report_error((
                    "Could not clone into %s. Check that the " +
                    "destination does not already exist.") % dest_folder
                )
            else:
                dest_path = os.path.join(dest_folder, os.path.basename(url))
                msg = (
                    "%s already exists (no changes were made)." % dest_path
                    if os.path.exists(dest_path) else
                    "Error: could not create a symlink in %s." % dest_folder
                )
                self._report_error(msg)
            return False

        return True

    def _install_commands(self, url, use_git):
        """Install the folder with the default commands."""
        commands_dir = os.path.join(
            self.source_folder, "defaults", "commands"
        )
        return self._install(commands_dir, url, use_git)

    def _install_projects(self, url, use_git):
        """Install the folder with the default commands."""
        projects_dir = os.path.join(
            self.source_folder, "defaults", "projects"
        )
        return self._install(projects_dir, url, use_git)

    def run(self):
        """Activate or create a project in the projects folder."""
        bin_folder = os.path.dirname(__file__)
        self.source_folder = os.path.dirname(bin_folder)
        args = self._args()

        url, install = (
            (args.commands, self._install_commands)
            if args.commands else
            (args.projects, self._install_projects)
        )

        install(url, args.use_git)
{'fraction_non_alphanumeric': 0.1053484602917342, 'fraction_numerical': 0.0, 'mean_word_length': 1.9892357373519913, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5497174', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1489, 'n_words': 382}