-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
41 lines (36 loc) · 1.29 KB
/
server.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
import sys
from src.controller_server import ControllerServer
from src.model import Model
from src.utils import *
from src.document import Document
if __name__ == "__main__":
args = parse_args("filename")
with open(args.filename) as f:
text = f.read()
site_id = 12345
model = Model(site_id)
controller = ControllerServer(site_id, args.filename)
model.initialise(controller)
controller.initialise(model, None)
model.create_document(text)
while True:
try:
command = input(':::')
if command == 'set_r':
(host, port, right) = input('host port 0/1:::').split(' ')
right = True if right == '1' else False
controller.set_rights(host, port, right)
elif command == 'r':
print(controller.rights)
elif command == 'txt':
print(controller.model.get_document().lines)
elif command == 'blame':
index = input('index:::')
print(controller.blame(int(index)))
elif command == 'r_all':
for (host, port) in controller.rights:
controller.set_rights(host, port, True)
elif command == 'q':
sys.exit()
except Exception:
pass