-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
ParkingLot.py
executable file
·59 lines (48 loc) · 1.77 KB
/
ParkingLot.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
#!/usr/bin/env python3
import sys
from Constants import *
from Utilities import (ParkingLot, create_parking_lot, park_car, car_departure,
lot_status, car_by_colour, slot_by_car_number, slot_by_colour)
def executeCommand(parkingLot, command):
if command[0] == CREATE_PARKING_LOT:
parkingLot = create_parking_lot(command[1])
elif command[0] == PARK_CAR:
print(park_car(parkingLot, command[1], command[2]))
elif command[0] == CAR_DEPARTURE:
print(car_departure(parkingLot, command[1]))
elif command[0] == LOT_STATUS:
print(lot_status(parkingLot).rstrip('\n'))
elif command[0] == SEARCH_SLOT_BY_CAR_NUMBER:
print(slot_by_car_number(parkingLot, command[1]).rstrip(', '))
elif command[0] == SEARCH_CAR_BY_COLOUR:
print(car_by_colour(parkingLot, command[1]).rstrip(', '))
elif command[0] == SEARCH_SLOT_BY_COLOUR:
print(slot_by_colour(parkingLot, command[1]).rstrip(', '))
else:
print('Command is not applicable')
return parkingLot
def commandMode(parkingLot):
try:
command = input().split()
while command[0] != EXIT:
parkingLot = executeCommand(parkingLot, command)
command = input().split()
except Exception as e:
print(e)
def fileReaderMode(parkingLot, fileName):
try:
with open(fileName) as file:
commands = file.readlines()
for command in commands:
parkingLot = executeCommand(
parkingLot, command.replace('\n', '').split())
except Exception as e:
print(e)
def main():
parkingLot = None
if len(sys.argv) > 1:
fileReaderMode(parkingLot, sys.argv[1])
else:
commandMode(parkingLot)
if __name__ == '__main__':
main()