<commit_before>"""


SPIN UP - Get a virtual development environment 
running on your computer.

This script installs virtualbox, vagrant, and puppet 
on your computer, then it sets up a virtual box
 that you can use as your development server.

It currently only supports OSes in the Ubuntu Linux 
family. Perhaps someday it will be expanded to handle 
OSes in the Redhat family, OS X, and Windows too.

"""

#########################################################
#########################################################
# A utilities class:

class Utilities:
    """
    A class that has a number of helper methods.
    """

    @staticmethod
    def show_error(message):
        """
        For prettier error messages. This function
        splits up a message into lines with 6 words
        each, then prints it out in a nicer format.
        """
        words = message.split()
        line_length = 6
        formatted_message = ''
        for word in range(0, len(words), line_length):
            words_for_line = words[word:word+line_length]
            formatted_message += '\n\r  |  ' + ' '.join(words_for_line)
        print ' '
        print '  ----------------------------------------'
        print '  |'
        print '  |  Oops! '
        print '  ----------------------------------------'
        print '  | ' + formatted_message
        print '  |'
        print '  ----------------------------------------'
        print ' '
        exit()


    @staticmethod
    def import_or_catch(package):
        """ 
        Try to import a package, but catch the error 
        if it fails and show a pretty message.
        """
        try:
            module = __import__(package)
        except:
            message = """
                I couldn't import the \"""" + package + """\" package.
                Make sure it's installed and in your python path.
            """
            Utilities.show_error(message)
        else:
            return module


    @staticmethod
    def file_exists(file):
        """ 
        Make sure a file exists. 
        """
        try:
            with open(file): return True
        except IOError:
            return False


    @staticmethod
    def create_folder(folder):
        """
        Attempts to create a folder in the current directory.
        Returns a tuple:
        -- (True, exception) if the folder exists already.
        -- (False, 'permissions') if access was denied.
        -- (False, exception) for all other errors.
        """
        try:
            os.mkdir(folder, 0740)
        except OSError as exception:
            if exception.errno == errno.EEXIST:
                return (True, exception)
            elif exception.errno == errno.EACCES:
                return (False, 'permissions')
            else:
                return (False, exception)
        else:
            return (True, None)


    @staticmethod
    def write_file(path, contents):
        """
        Attempts to write a file to disk.
        Returns a tuple:
        -- (True, path) if successful.
        -- (False, 'permissions') if access was denied.
        -- (False, exception) for all other errors.
        """
        try:
            file = open(path, 'w+')
        except IOError as exception:
            if exception.errno == errno.EACCES:
                return (False, 'permissions')
            else:
                return (False, exception)
        else:
            file.write(contents)
            file.close()
            return (True, path)



#########################################################
#########################################################
# Import the modules we need

subprocess = Utilities.import_or_catch('subprocess')
errno = Utilities.import_or_catch('errno')
cmd = Utilities.import_or_catch('cmd')
platform = Utilities.import_or_catch('platform')
sys = Utilities.import_or_catch('sys')
os = Utilities.import_or_catch('os')
fileinput = Utilities.import_or_catch('fileinput')



#########################################################
#########################################################
# A dictionary for data

class Data:
    """
    A dictionary to store data in.
    """
    vagrant_folder = '.devbox'
    vagrant_file = vagrant_folder + os.sep + 'Vagrantfile'
    manifests_folder = vagrant_folder + os.sep + 'manifests'
    manifests_file = manifests_folder + os.sep + 'default.pp'
    port = 8500
    box = 'lucid64'
    box_url = 'http://files.vagrantup.com/lucid64.box'
    code_folder_name = 'root'
    code_folder_path_on_box = '/var/www/' + code_folder_name



#########################################################
#########################################################
# An installer class

class Installer:
    """
    This class tries to install the following 
    required software:
    -- Virtual Box
    -- Vagrant
    -- Puppet
    """

    # The required software that needs to be installed.
    required_software = ['virtualbox', 'vagrant', 'puppet']

    # Linux package managers/installers.
    linux_installers = ['apt-get', 'yum']


    def __init__(self, data):
        """
        Initializes the installer by storing some data.
        """
        self.data = data


    def program_exists_on_nix(self, program):
        """
        Checks if a program exists on a *nix system.
        Returns the path to the program if it exists,
        False otherwise.
        """
        try:
            return subprocess.check_output(['which', program])
        except subprocess.CalledProcessError:
            return False


    def find_linux_package_manager(self):
        """
        Tries to identify the Linux package manager (apt-get, yum, etc.).
        """

        # See if any package manager/installers exist on the system.
        installer = None
        for program in self.linux_installers:<commit_msg>Fixed the installation part. It was incorrectly detecting the presence of required software.<commit_after>"""


SPIN UP - Get a virtual development environment 
running on your computer.

This script installs virtualbox, vagrant, and puppet 
on your computer, then it sets up a virtual box
 that you can use as your development server.

It currently only supports OSes in the Ubuntu Linux 
family. Perhaps someday it will be expanded to handle 
OSes in the Redhat family, OS X, and Windows too.

"""

#########################################################
#########################################################
# A utilities class:

class Utilities:
    """
    A class that has a number of helper methods.
    """

    @staticmethod
    def show_error(message):
        """
        For prettier error messages. This function
        splits up a message into lines with 6 words
        each, then prints it out in a nicer format.
        """
        words = message.split()
        line_length = 6
        formatted_message = ''
        for word in range(0, len(words), line_length):
            words_for_line = words[word:word+line_length]
            formatted_message += '\n\r  |  ' + ' '.join(words_for_line)
        print ' '
        print '  ----------------------------------------'
        print '  |'
        print '  |  Oops! '
        print '  ----------------------------------------'
        print '  | ' + formatted_message
        print '  |'
        print '  ----------------------------------------'
        print ' '
        exit()


    @staticmethod
    def import_or_catch(package):
        """ 
        Try to import a package, but catch the error 
        if it fails and show a pretty message.
        """
        try:
            module = __import__(package)
        except:
            message = """
                I couldn't import the \"""" + package + """\" package.
                Make sure it's installed and in your python path.
            """
            Utilities.show_error(message)
        else:
            return module


    @staticmethod
    def file_exists(file):
        """ 
        Make sure a file exists. 
        """
        try:
            with open(file): return True
        except IOError:
            return False


    @staticmethod
    def create_folder(folder):
        """
        Attempts to create a folder in the current directory.
        Returns a tuple:
        -- (True, exception) if the folder exists already.
        -- (False, 'permissions') if access was denied.
        -- (False, exception) for all other errors.
        """
        try:
            os.mkdir(folder, 0740)
        except OSError as exception:
            if exception.errno == errno.EEXIST:
                return (True, exception)
            elif exception.errno == errno.EACCES:
                return (False, 'permissions')
            else:
                return (False, exception)
        else:
            return (True, None)


    @staticmethod
    def write_file(path, contents):
        """
        Attempts to write a file to disk.
        Returns a tuple:
        -- (True, path) if successful.
        -- (False, 'permissions') if access was denied.
        -- (False, exception) for all other errors.
        """
        try:
            file = open(path, 'w+')
        except IOError as exception:
            if exception.errno == errno.EACCES:
                return (False, 'permissions')
            else:
                return (False, exception)
        else:
            file.write(contents)
            file.close()
            return (True, path)



#########################################################
#########################################################
# Import the modules we need

subprocess = Utilities.import_or_catch('subprocess')
errno = Utilities.import_or_catch('errno')
cmd = Utilities.import_or_catch('cmd')
platform = Utilities.import_or_catch('platform')
sys = Utilities.import_or_catch('sys')
os = Utilities.import_or_catch('os')
fileinput = Utilities.import_or_catch('fileinput')



#########################################################
#########################################################
# A dictionary for data

class Data:
    """
    A dictionary to store data in.
    """
    vagrant_folder = '.devbox'
    vagrant_file = vagrant_folder + os.sep + 'Vagrantfile'
    manifests_folder = vagrant_folder + os.sep + 'manifests'
    manifests_file = manifests_folder + os.sep + 'default.pp'
    port = 8500
    box = 'lucid64'
    box_url = 'http://files.vagrantup.com/lucid64.box'
    code_folder_name = 'root'
    code_folder_path_on_box = '/var/www/' + code_folder_name



#########################################################
#########################################################
# An installer class

class Installer:
    """
    This class tries to install the following 
    required software:
    -- Virtual Box
    -- Vagrant
    -- Puppet
    """

    # The required software that needs to be installed.
    required_software = ['virtualbox', 'vagrant', 'puppet']

    # Linux package managers/installers.
    linux_installers = ['apt-get', 'yum']


    def __init__(self, data):
        """
        Initializes the installer by storing some data.
        """
        self.data = data


    def program_exists_on_nix(self, program):
        """
        Checks if a program exists on a *nix system.
        Returns the path to the program if it exists,
        False otherwise.
        """
        try:
            result = subprocess.check_call(['which', program])
            if result is 0:
                return True
        except subprocess.CalledProcessError:
            return False


    def find_linux_package_manager(self):
        """
        Tries to identify the Linux package manager (apt-get, yum, etc.).
        """

        # See if any package manager/installers exist on the system.
        installer = None
        for program in self.linux_installers:
{'fraction_non_alphanumeric': 0.17999494396224824, 'fraction_numerical': 0.002612286171736749, 'mean_word_length': 2.029096477794793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2785274', 'n_tokens_mistral': 3154, 'n_tokens_neox': 2981, 'n_words': 961}