def prompt(ref):
    sys.stdin = open('/dev/tty')

    def_uID, def_pID, def_mID, def_tID, def_status = getDefaults()
   
    if def_uID != None:
        uID = def_uID
    else:
        sys.stdout.write('Email: ')
        sys.stdout.flush()
        email = raw_input()
        uID = firebase_utils.getUserID(ref,email)

    if def_pID != None:
        print 'Active projects (defaults to '+def_pID+'):'
    else:
        print 'Active projects:'
    sys.stdout.flush()
    idsByIndex = [] ; index = 1
    for pID, pName in firebase_utils.getActiveProjects(ref,uID).iteritems():
        print ' - '+str(index)+'. '+pName
        idsByIndex = idsByIndex + [pID]
        index = index + 1
    sys.stdout.write('Project: ')
    sys.stdout.flush()
    project = raw_input()
    if project.isdigit() and int(project) <= len(idsByIndex):
        pID = idsByIndex[int(project)-1]
    elif project == '' and def_pID != 0:
        pID = def_pID
    else:
        pID = firebase_utils.getProjectID(ref,project)

    if def_mID != None:
        print 'Active milestones (defaults to '+def_mID+'):'
    else:
        print 'Active milestones:'
    sys.stdout.flush()
    idsByIndex = [] ; index = 1
    for mID, mName in firebase_utils.getActiveMilestones(ref,uID,pID).iteritems():
        print ' - '+str(index)+'. '+mName
        idsByIndex = idsByIndex + [mID]
        index = index + 1
    sys.stdout.write('Milestone: ')
    sys.stdout.flush()
    milestone = raw_input()
    if milestone.isdigit() and int(milestone) <= len(idsByIndex):
        mID = idsByIndex[int(milestone)-1]
    elif milestone == '' and def_mID != 0:
        mID = def_mID
    else:
        mID = firebase_utils.getMilestoneID(ref,pID,milestone)

    if def_tID != None:
        def_task = firebase_utils.getTask(ref,pID,mID,def_tID)
        print 'Tasks assigned to you (defaults to '+def_task+'):'
    else:
        print 'Tasks assigned to you:'
    idsByIndex = [] ; index = 1
    for tID, tName in firebase_utils.getAssignedTasks(ref,uID,pID,mID).iteritems():
        print ' - '+str(index)+'. '+tName
        idsByIndex = idsByIndex + [tID]
        index = index + 1
    sys.stdout.write('Task: ')
    sys.stdout.flush()
    task = raw_input()
    if task.isdigit() and int(task) <= len(idsByIndex):
        tID = idsByIndex[int(task)-1]
    elif task == '' and def_tID != 0:
        tID = def_tID
    else:
        tID = getTaskID(pID,mID,task)


    sys.stdout.write('Hours: ')
    sys.stdout.flush()
    hours = raw_input()


    if def_status != None:
        print 'Select status (defaults to '+def_status+'):'
    else:
        print 'Select status:'
    possibleStatuses = ['New', 'Implementation', 'Testing', 'Verify', 'Regression', 'Closed']
    for i in range(len(possibleStatuses)):
        print ' - ' + str(i+1) + ': ', possibleStatuses[i]
    sys.stdout.write('Status: ')
    sys.stdout.flush()
    status = raw_input()
    if status.isdigit() and (int(status) <= len(possibleStatuses)):
        status = possibleStatuses[int(status)-1]
    elif status == '' and def_status != 0:
        status = def_status
    else:
        print 'HENRY: Invalid status, commit failed'
        exit(1)
    print 'I should be returning' 
    return uID,pID,mID,tID,hours,status
예제 #2
0
def promptAsNecessary(ref,userID,projectID,hours,milestone,task,status,email):
    # mac/linux
    sys.stdin = open('/dev/tty')

    # windows
    #sys.stdin = open('CON')

    def_mID, def_tID, def_status = getDefaults()

    if hours == None:
        sys.stdout.write('Hours: ')
        sys.stdout.flush()
        hours = raw_input()

    # prompt for milestone if necessary
    if milestone == None:
        if def_mID != None:
            def_milestone = firebase_utils.getMilestone(ref,projectID,def_mID)
            print 'Active milestones (defaults to '+def_milestone+'):'
        else:
            print 'Active milestones:'
        sys.stdout.flush()
        idsByIndex = [] ; index = 1
        for mID, mName in firebase_utils.getActiveMilestones(ref,userID,projectID).iteritems():
            print ' - '+str(index)+'. '+mName
            idsByIndex = idsByIndex + [mID]
            index = index + 1
        sys.stdout.write('Milestone: ')
        sys.stdout.flush()
        milestone = raw_input()
        if milestone.isdigit() and int(milestone) <= len(idsByIndex):
            mID = idsByIndex[int(milestone)-1]
        elif milestone == '' and def_mID != 0:
            mID = def_mID
        else:
            mID = firebase_utils.getMilestoneID(ref,projectID,milestone)
    else:
        mID = firebase_utils.getMilestoneID(ref,projectID,milestone)

    # prompt for task if necessary
    if task == None:
        if def_tID != None and mID == def_mID:
            def_task = firebase_utils.getTask(ref,projectID,mID,def_tID)
            print 'Tasks assigned to you (defaults to '+def_task+'):'
        else:
            print 'Tasks assigned to you:'
        idsByIndex = [] ; index = 1
        for tID, tName in firebase_utils.getAssignedTasks(ref,userID,projectID,mID).iteritems():
            print ' - '+str(index)+'. '+tName
            idsByIndex = idsByIndex + [tID]
            index = index + 1
        sys.stdout.write('Task: ')
        sys.stdout.flush()
        task = raw_input()
        if task.isdigit() and int(task) <= len(idsByIndex):
            tID = idsByIndex[int(task)-1]
        elif task == '' and def_tID != 0:
            tID = def_tID
        else:
            tID = firebase_utils.getTaskID(projectID,mID,task)
    else:
        tID = firebase_utils.getTaskID(projectID,mID,task)

    # prompt for status if necessary
    if status == None:
        # New, Implementation, Testing, Verify, Regression, Closed'
        if def_status != None:
            print 'Select status (defaults to '+def_status+'):'
        else:
            print 'Select status:'
        possibleStatuses = ['New', 'Implementation', 'Testing', 'Verify', 'Regression', 'Closed']
        for i in range(len(possibleStatuses)):
            print ' - ' + str(i + 1) + ': ', possibleStatuses[i]
        sys.stdout.write('Status: ')
        sys.stdout.flush()
        status = raw_input()
        if status.isdigit() and (int(status) <= len(possibleStatuses)):
            status = possibleStatuses[int(status) - 1]
        elif status == '' and def_status != 0:
            status = def_status
        else:
            print 'HENRY: Invalid status, commit failed'
            exit(1)

    sys.stdout.write('Pair programmed? (y/n): ')
    sys.stdout.flush()
    response = raw_input()
    if response.lower()[0] == 'y':
        team_emails = firebase_utils.teamEmails(ref,projectID)
        team_emails = [e for e in team_emails if e != email]
        if not team_emails:
            print 'HENRY: No team members, are you sure you pair programmed?'
            exit(1)
        index = 1
        for e in team_emails:
            print ' - '+str(index)+'. '+e
            index = index+1
        sys.stdout.write('Partner: ')
        sys.stdout.flush()
        partner = raw_input()
        if partner.isdigit() and int(partner) <= len(team_emails):
            pp = firebase_utils.getUserID(ref,team_emails[int(partner)-1])
        elif partner in team_emails:
            pp = firebase_utils.getUserID(ref,partner)
        else:
            print 'HENRY: Invalid team member'
            exit(1)
    else:
        pp = None

    return hours,mID,tID,status,pp