-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·60 lines (50 loc) · 1.81 KB
/
main.py
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
52
53
54
55
56
57
58
59
60
import sys
from classes.parking_lot import ParkingLot
from commands import *
def execute_command(parking_lot, command):
if command[0] == "create_parking_lot":
parking_lot = ParkingLot(int(command[1]))
print("Created a parking lot with {0} slots".format(command[1]))
elif command[0] == "park":
print(park_new_car(parking_lot, command[1], command[2]))
elif command[0] == "leave":
print(car_departure(parking_lot, int(command[1])))
elif command[0] == "status":
get_status(parking_lot)
elif command[0] == "registration_numbers_for_cars_with_colour":
result = get_registration_by_colour(parking_lot, command[1])
if type(result) is str:
print(result)
else:
print(*result, sep=', ')
elif command[0] == "slot_numbers_for_cars_with_colour":
result = get_slot_by_colour(parking_lot, command[1])
if type(result) is str:
print(result)
else:
print(*result, sep=', ')
elif command[0] == "slot_number_for_registration_number":
print(get_slot_by_registration(parking_lot, command[1]))
else:
print('No such command')
return parking_lot
def interactive_mode():
parking_lot = None
command = input().split()
while not command[0] == 'exit':
parking_lot = execute_command(parking_lot, command)
command = input().split()
def file_read_mode(file_name):
parking_lot = None
with open(file_name) as file:
commands = file.readlines()
for command in commands:
command = command.replace('\n', '').split(' ')
parking_lot = execute_command(parking_lot, command)
def main():
if len(sys.argv) > 1:
file_read_mode(sys.argv[1])
else:
interactive_mode()
if __name__ == "__main__":
main()