-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
239 lines (201 loc) · 5.95 KB
/
server.py
File metadata and controls
239 lines (201 loc) · 5.95 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# Hrishikesh Hiraskar
# 15CO121
# 12/3/17
import gevent
import time
import os
import threading
import shell, executer, file_allocator, banker
from gevent import monkey
from gevent.pywsgi import WSGIServer
from flask import Flask, request, Response, render_template, send_from_directory
monkey.patch_all(aggressive=False)
import subprocess
app = Flask(__name__, static_folder='webapp/')
# Terminal
@app.route('/terminal/shellcommand', methods=['POST', 'GET'])
def shell_command():
com = request.args['command']
print com
out = shell.execute(com)
print out
return out
@app.route('/terminal')
def page_terminal():
shell.init()
return app.send_static_file('terminal.html')
# Disk Scheduling
@app.route('/disk_scheduling/schedule', methods=['POST', 'GET'])
def disk_schedule():
scheduling = ['fcfs', 'sstf', 'scan', 'c_scan', 'look', 'c_look']
inp = request.args['input']
print inp
out = ""
for algo in scheduling:
out += executer.execute('disk_scheduling/'+algo, inp)
return out
@app.route('/disk_scheduling')
def page_disk_scheduling():
return app.send_static_file('disk_scheduling.html')
# Process Scheduling
@app.route('/process_scheduling/schedule', methods=['POST', 'GET'])
def process_schedule():
scheduling = ['fcfs', 'rr', 'sjf', 'non_preemptive', 'srtf', 'preemptive', 'multilevel_queue']
inp = request.args['input']
out = ""
for algo in scheduling:
out += executer.execute('process_scheduling/'+algo, inp)
return out
@app.route('/process_scheduling')
def page_process_scheduling():
return app.send_static_file('process_scheduling.html')
# Contigous File Alloction
@app.route('/contigous_file_allocation/execute', methods=['POST', 'GET'])
def contigous_file_allocation():
inp = request.args['input']
out = file_allocator.execute(1, inp)
return out
@app.route('/contigous_file_allocation')
def page_contigous_file_allocation():
file_allocator.init(1)
return app.send_static_file('contigous_file_allocation.html')
# Linked File Alloction
@app.route('/linked_file_allocation/execute', methods=['POST', 'GET'])
def linked_file_allocation():
inp = request.args['input']
out = file_allocator.execute(2, inp)
return out
@app.route('/linked_file_allocation')
def page_linked_file_allocation():
file_allocator.init(2)
return app.send_static_file('linked_file_allocation.html')
# Indexed File Alloction
@app.route('/indexed_file_allocation/execute', methods=['POST', 'GET'])
def indexed_file_allocation():
inp = request.args['input']
out = file_allocator.execute(3, inp)
return out
@app.route('/indexed_file_allocation')
def page_indexed_file_allocation():
file_allocator.init(3)
return app.send_static_file('indexed_file_allocation.html')
@app.route('/file_allocation', methods=['POST', 'GET'])
def page_file_allocation():
inp = request.args['input']
if inp == 'contigous':
inp = 1
else:
inp = 0
file_allocator.init(inp)
return app.send_static_file('file_allocation.html')
# Bankers
@app.route('/banker/execute', methods=['POST', 'GET'])
def deadlock():
inp = request.args['input']
out = banker.execute(inp)
return out
@app.route('/banker')
def page_deadlock():
banker.init()
return app.send_static_file('deadlock.html')
# Dining Philosopher
@app.route('/dining/execute', methods=['POST', 'GET'])
def dining():
inp = request.args['input']
out = executer.execute('process_sync/dining', inp)
return out
@app.route('/dining')
def page_dining():
return app.send_static_file('dining.html')
# Producer Consumer
@app.route('/producer/execute', methods=['POST', 'GET'])
def producer():
inp = request.args['input']
out = executer.execute('process_sync/producer_consumer', inp)
return out
@app.route('/producer')
def page_producer():
return app.send_static_file('producer_consumer.html')
# Reader Writer
@app.route('/reader/execute', methods=['POST', 'GET'])
def reader():
inp = request.args['input']
out = executer.execute('process_sync/readerwriter', inp)
return out
@app.route('/reader')
def page_reader():
return app.send_static_file('reader_writer.html')
# MVT
@app.route('/mvt/execute', methods=['POST', 'GET'])
def mvt():
inp = request.args['input']
out = file_allocator.execute(4, inp)
return out
@app.route('/mvt/change_fit', methods=['POST', 'GET'])
def mvt_change_fit():
fit = request.args['fit']
print fit
if file_allocator.mvt is not None:
file_allocator.execute(4, '0')
file_allocator.init(4)
print file_allocator.execute(4, '0 100 ' + fit)
return "Success"
@app.route('/mvt')
def page_mvt():
return app.send_static_file('mvt.html')
# MFT
@app.route('/mft/execute', methods=['POST', 'GET'])
def mft():
inp = request.args['input']
out = file_allocator.execute(5, inp)
return out
@app.route('/mft/init', methods=['POST', 'GET'])
def mft_init():
inp = request.args['input']
if file_allocator.mft is not None:
file_allocator.execute(5, '0')
file_allocator.init(5)
out = file_allocator.execute(5, inp)
print out
return out
@app.route('/mft')
def page_mft():
return app.send_static_file('mft.html')
# Page Replacement
@app.route('/page_replacement/execute', methods=['POST', 'GET'])
def pafe_replacement():
scheduling = ['fifo', 'lru', 'opt']
inp = request.args['input']
out = ""
for algo in scheduling:
out += executer.execute('page_replacement/'+algo, inp)
return out
@app.route('/page_replacement')
def page_page_replacement():
return app.send_static_file('page_replacement.html')
# RTOS
@app.route('/rtos/execute', methods=['POST', 'GET'])
def pafe_rtos():
inp = request.args['input']
out = executer.execute('RTOS/rate_monotonic', inp)
return out
@app.route('/rtos')
def page_rtos():
return app.send_static_file('rtos.html')
# Home
@app.route('/')
def page_home():
shell.init()
return app.send_static_file('index.html')
# Team
@app.route('/team')
def page_team():
return app.send_static_file('team.html')
@app.route('/<path:path>')
def static_file(path):
return app.send_static_file(path)
if __name__ == '__main__':
# Set server address 127.0.0.1:8000/
app.run(host="127.0.0.1", port=8000);
http_server = WSGIServer(app)
http_server.serve_forever()