Skip to content
This repository
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 51 lines (35 sloc) 1.306 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51


"""
Helpers for getting user input for configuration
"""


def get_int(message, value=''):
    """
Prompts a user for an input int. Uses the default value if no
value is entered by the user. Uses default value of parse error happens
"""
    msg2 = ' '.join([message, ' (', str(value), ') (int): '])
    new_value = raw_input(msg2)
    if(new_value == "" or new_value == "\n"):
        return int(value)

    try:
        return int(new_value)
    except ValueError:
        print "Invalid integer, '%s', using default value" % (str(new_value))
        return int(value)


def get_string(message, default):
    """get a string value from the command line"""
    msg2 = ''.join([message, ' (', str(default), ') (string): '])
    value = raw_input(msg2)

    if not len(value):
        return default

    return value


def get_yes_or_no(message, value=True):
    """Get yes/no value from the command line"""

    msg2 = ''.join([message, ' (', str(value), ') (Y,n): '])
    new_value = raw_input(msg2)

    if(new_value == "" or new_value == "\n"):
        return value

    if(new_value == 'Y' or new_value == 'Yes' or new_value == 'y'):
        return True

    elif(new_value == 'n' or new_value == 'no' or new_value == 'N'):
        return False

    raise InputError("Please choose y/n")
Something went wrong with that request. Please try again.