<commit_before>import datetime
import subprocess
import shlex
import re
import sys
import os

def termination_string():
    """
    Gets the current system time and appends it to a termination notice.
    """
    now = datetime.datetime.now()
    time = now.strftime("%Y-%m-%d %H:%M:%S")
    end_time = "Script exiting at %s\n" % time
    return end_time

def install(packagename, logfile):
    """
    Installs <packagename> and writes its output to <logfile>.
    Raises a CalledProcessError if an error occurs.
    Note that this does not log the console output of yum.
    
    Parameters:
       1. packagename: The name of the package to be installed.
       2. logfile: The logfile to write output to.
       
    Returns the tuple "result."
    result[0] is True if the installation succeeded and False if it did not.
    result[1] is a reference to the logfile passed in as parameter 2.
    """
    success = False
    now = datetime.datetime.now()
    time = now.strftime("%Y-%m-%d %H:%M:%S")
    start_time = "Script starting at %s\n" % time
    logfile.write(start_time)
    print start_time

    logfile.write("%s will be installed.\n" % packagename)
    print "%s will be installed.\n" % packagename
    try:
        # Install
        logfile.write("yum install -y %s" % packagename)
        print "yum install -y %s" % packagename
        install_result = subprocess.check_call(shlex.split("yum install -y %s" % packagename))
        # Any CalledProcessError would be raised at this point
        if install_result == 0:
            logfile.write("%s was successfully installed.\n" % packagename)
            print "%s was successfully installed.\n" % packagename
            success = True
    except subprocess.CalledProcessError as cpe:
        # Print and log the error message
        logfile.write("CalledProcessError: ")
        print "CalledProcessError: "
        logfile.write(cpe.output)
        print cpe.output
        closing = "Package %s did not install successfully.\n" % packagename
        logfile.write(closing)
        print closing
        end_time = termination_string()
        logfile.write(end_time)
        print end_time
        success = False
    # Return result tuple
    result = [success, logfile]
    return result

def run(logfile):
    """
    Uses yum to install dependencies needed to build Python 2.7.3 from 
    source. Writes its output to a logfile and prints it to the console. 
    It is left to the calling function to close the logfile, which is 
    returned.
    
    Intended to be run under Python 2.6.6 or later versions of 
    Python 2.6.
    
    Warning: This will install or update to the newest available 
    versions of all packages specified.
    
    Parameters:
        1.    logfile: The logfile to write output to. 
    """
    
    now = datetime.datetime.now()
    time = now.strftime("%Y-%m-%d %H:%M:%S")
    start_time = "Script starting at %s\n" % time
    logfile.write(start_time)
    print start_time
    try:
        #Confirm that the user wants to continue.
        logfile.write("This script will install these packages and their dependencies:\n\
        All packages in groupinstall of \"Development tools\",\n\
        zlib-devel,\n\
        bzip2-devel,\n\
        openssl-devel,\n\
        ncurses-devel,\n\
        sqlite-devel,\n\
        readline-devel,\n\
        tk-devel,\n\
        wget")
        print "This script will install these packages and their dependencies:\n\
        All packages in groupinstall of \"Development tools\",\n\
        zlib-devel,\n\
        bzip2-devel,\n\
        openssl-devel,\n\
        ncurses-devel,\n\
        sqlite-devel,\n\
        readline-devel,\n\
        tk-devel,\n\
        wget"
        value = raw_input("Do you wish to continue (Y/n)? ")
        while value != "Y" and value != "n":<commit_msg>install/redhat/pythonsetup.py: Small refactoring of output that asks user to allow packages to be installed.<commit_after>import datetime
import subprocess
import shlex
import re
import sys
import os

def termination_string():
    """
    Gets the current system time and appends it to a termination notice.
    """
    now = datetime.datetime.now()
    time = now.strftime("%Y-%m-%d %H:%M:%S")
    end_time = "Script exiting at %s\n" % time
    return end_time

def install(packagename, logfile):
    """
    Installs <packagename> and writes its output to <logfile>.
    Raises a CalledProcessError if an error occurs.
    Note that this does not log the console output of yum.
    
    Parameters:
       1. packagename: The name of the package to be installed.
       2. logfile: The logfile to write output to.
       
    Returns the tuple "result."
    result[0] is True if the installation succeeded and False if it did not.
    result[1] is a reference to the logfile passed in as parameter 2.
    """
    success = False
    now = datetime.datetime.now()
    time = now.strftime("%Y-%m-%d %H:%M:%S")
    start_time = "Script starting at %s\n" % time
    logfile.write(start_time)
    print start_time

    logfile.write("%s will be installed.\n" % packagename)
    print "%s will be installed.\n" % packagename
    try:
        # Install
        logfile.write("yum install -y %s" % packagename)
        print "yum install -y %s" % packagename
        install_result = subprocess.check_call(shlex.split("yum install -y %s" % packagename))
        # Any CalledProcessError would be raised at this point
        if install_result == 0:
            logfile.write("%s was successfully installed.\n" % packagename)
            print "%s was successfully installed.\n" % packagename
            success = True
    except subprocess.CalledProcessError as cpe:
        # Print and log the error message
        logfile.write("CalledProcessError: ")
        print "CalledProcessError: "
        logfile.write(cpe.output)
        print cpe.output
        closing = "Package %s did not install successfully.\n" % packagename
        logfile.write(closing)
        print closing
        end_time = termination_string()
        logfile.write(end_time)
        print end_time
        success = False
    # Return result tuple
    result = [success, logfile]
    return result

def run(logfile):
    """
    Uses yum to install dependencies needed to build Python 2.7.3 from 
    source. Writes its output to a logfile and prints it to the console. 
    It is left to the calling function to close the logfile, which is 
    returned.
    
    Intended to be run under Python 2.6.6 or later versions of 
    Python 2.6.
    
    Warning: This will install or update to the newest available 
    versions of all packages specified.
    
    Parameters:
        1.    logfile: The logfile to write output to. 
    """
    
    now = datetime.datetime.now()
    time = now.strftime("%Y-%m-%d %H:%M:%S")
    start_time = "Script starting at %s\n" % time
    logfile.write(start_time)
    print start_time
    try:
        #Confirm that the user wants to continue.
        packages_list = "This script will install these packages and their dependencies:\n\
        All packages in groupinstall of \"Development tools\",\n\
        zlib-devel,\n\
        bzip2-devel,\n\
        openssl-devel,\n\
        ncurses-devel,\n\
        sqlite-devel,\n\
        readline-devel,\n\
        tk-devel,\n\
        wget\n"
        logfile.write(packages_list)
        print packages_list

        value = raw_input("Do you wish to continue (Y/n)? ")
        while value != "Y" and value != "n":
{'fraction_non_alphanumeric': 0.09251863684771033, 'fraction_numerical': 0.00439297124600639, 'mean_word_length': 2.3317073170731706, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6412091', 'n_tokens_mistral': 2242, 'n_tokens_neox': 2170, 'n_words': 769}