-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsys_gen.py
54 lines (39 loc) · 1.38 KB
/
sys_gen.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
#!/usr/bin/env python
#
# Author: Anna Cristina Karingal
# Name: sys_gen.py
# Created: February 27, 2015
# Last Updated: May 4, 2015
# Description: Prompts user for input and generates instances of devices
# in system based on user input
import sys
import devices
import io
valid_device_types = frozenset(["Disk Drive", "Printer", "CD/RW"])
def generate():
"""
Generates all system device instances based on user input.
Returns list of all system devices.
"""
print io.sys_mode("System Setup")
# Dictionary of type of devices and how many devices of each type
system_device_types = {}
print "For each device type, please specify the number of devices."
for d in valid_device_types:
# Add device type & how many of each type
system_device_types[d] = None
system_device_types[d] = io.get_valid_int(d)
print io.sys_mode("Initialize Disk Drive",'-')
# List of all individual devices in system
system_devices = []
for dev_type, num_of_dev in system_device_types.iteritems():
name_prefix = dev_type[0].lower()
# Create new device, add to list of system_devices
for i in range(num_of_dev):
name = name_prefix + str(i+1)
if (dev_type == "Disk Drive"):
cyl = io.get_valid_int("Num of cylinders for " + name)
system_devices.append(devices.DiskDrive(name,cyl))
else:
system_devices.append(devices.Device(name, dev_type))
return system_devices