<commit_before>"""
Installs a package from whatever the native package manager is
(apt-get for debian-based, brew for OS X)
[env]
recipe = sprinter.recipes.package
debian = git
brew = git
"""

from sprinter.recipestandard import RecipeStandard
from sprinter import lib


class PackageRecipe(RecipeStandard):

    def __init__(self, environment):
        super(PackageRecipe, self).__init__(environment)
        self.package_manager, self.manager_installed, self.sudo_required = self.__get_package_manager()


    def setup(self, feature_name, config):
        if self.package_manager in config:
            if not self.manager_installed:
                if self.package_manager == "brew":
                    if not self.__install_brew():
                        self.logger.info("Unable to install package! skipping...")
                        return
            package = config[self.package_manager]
            self.logger.info("Installing %s..." % package)
            call_command = "%s install %s" % (self.package_manager, package)
            if self.sudo_required:
                call_command = "sudo " + call_command
            self.logger.info(lib.call(call_command))
        super(PackageRecipe, self).setup(feature_name, config)

    def __get_package_manager(self):
        """
        Installs and verifies package manager
        """
        package = ""
        sudo_required = True
        if self.system.isOSX():
            package = "brew"
            sudo_required = False
        elif self.system.isDebianBased():
            package = "apt-get"
        elif self.system.isFedoraBased():
            package = "yum"
        installed =  lib.which(package) is not None
        if not installed:
            self.logger.error("package manager %s is not installed!" % package)
        return package, installed, sudo_required

    def __install_brew():
        """<commit_msg>Adding in args variable to package, to add flags<commit_after>"""
Installs a package from whatever the native package manager is
(apt-get for debian-based, brew for OS X)
[env]
recipe = sprinter.recipes.package
debian = git
brew = git
"""

from sprinter.recipestandard import RecipeStandard
from sprinter import lib


class PackageRecipe(RecipeStandard):

    def __init__(self, environment):
        super(PackageRecipe, self).__init__(environment)
        self.package_manager, self.manager_installed, self.sudo_required, self.args = self.__get_package_manager()


    def setup(self, feature_name, config):
        if self.package_manager in config:
            if not self.manager_installed:
                if self.package_manager == "brew":
                    if not self.__install_brew():
                        self.logger.info("Unable to install package! skipping...")
                        return
            package = config[self.package_manager]
            self.logger.info("Installing %s..." % package)
            call_command = "%s %s install %s" % (self.package_manager, self.args, package)
            if self.sudo_required:
                call_command = "sudo " + call_command
            self.logger.info(lib.call(call_command))
        super(PackageRecipe, self).setup(feature_name, config)

    def __get_package_manager(self):
        """
        Installs and verifies package manager
        """
        package = ""
        args = "
        sudo_required = True
        if self.system.isOSX():
            package = "brew"
            sudo_required = False
        elif self.system.isDebianBased():
            package = "apt-get"
            args = "-y"
        elif self.system.isFedoraBased():
            package = "yum"
        installed =  lib.which(package) is not None
        if not installed:
            self.logger.error("package manager %s is not installed!" % package)
        return package, installed, sudo_required, args

    def __install_brew():
        """
{'fraction_non_alphanumeric': 0.09500640204865557, 'fraction_numerical': 0.0, 'mean_word_length': 2.2388059701492535, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1332964', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1015, 'n_words': 279}