Esempio n. 1
0
def FPmem():
    while True:
        try: 
            print("How many partition does the machine have: [1-5] [C/c to cancel]")
            partitionCount = input("> ")
            partSizes = []
            if partitionCount.lower() == "c":
                return
            partitionCount = int(partitionCount)
            if partitionCount < 1 or partitionCount > 5:
                raise ValueError
            partSizesChoices = ["1","2","3","4","5","6","7","8","9","10"]
            for i in range(partitionCount):
                partSize = "0"
                while partSize not in partSizesChoices:
                    partSize = input(f"Enter partition {i} size: [1-10] ")
                    if partSize in partSizesChoices:
                        partSizes.append(int(partSize))
                        break
                    else:
                        print("ERROR: Please input a valid size")
                        input("press ENTER to continue")
            Machine = Memory.FP(partSizes)
            break
        except ValueError:
            print("ERROR: Please input a valid choice")

    while True:
        print()
        Machine.printMemory(freeSymbol,takenSymbol)
        Machine.printJobs()
        print("\n[1] Add job")
        print("[2] Deallocate job")
        print("[3] EXIT")

        option = "0"
        optionChoices = ["1","2","3"]
        while option not in optionChoices:
            print("Choose an option")
            option = input("> ")
            if option not in optionChoices:
                print("ERROR: Please pick a valid option")
        
        if option == "1": ##########################################
            addJob(Machine, "FP")
        elif option == "2": ###############################################
            jobAmount = 0
            for obj in Machine.objects:
                jobAmount += len(obj.objects)
            if jobAmount == 0:
                print("ERROR: No jobs to deallocate")
                input("press ENTER to continue")
            else:
                deleteJob(Machine, "FP")
        elif option == "3":
            return