forked from TelematicaUSM/Tidys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
111 lines (91 loc) · 2.96 KB
/
run.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
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
# -*- coding: UTF-8 -*-
def start():
global ioloop, t
import controller
from threading import Thread
from tornado.ioloop import IOLoop
from src import messages
messages.starting()
ioloop = IOLoop.instance()
t = Thread(target=lambda:ioloop.start())
t.start()
messages.wellcome()
def stop():
from src import messages
def callback():
from src import db
db.client.disconnect()
ioloop.stop()
ioloop.add_callback(callback)
t.join()
messages.stopped()
if __name__ == "__main__":
from src.utils import run_inside
from tornado.gen import coroutine
start()
@run_inside(ioloop.add_callback)
def clients():
from controller import MSGHandler
total = MSGHandler.client_count
current = len(MSGHandler.clients)
print('Connected clients: %d' % current)
print('Total connections opened: %d' % total)
print(
'Total connections closed: %d' % (total-current)
)
@run_inside(ioloop.add_callback)
def bcast(message):
from controller import MSGHandler
MSGHandler.broadcast(message)
def q():
from sys import exit
stop()
exit()
def h():
from sys import modules
help(modules[__name__])
def make(goal):
from os import system
system('make %s' % goal)
@run_inside(ioloop.add_callback)
def clients():
from controller import MSGHandler
total = MSGHandler.client_count
current = len(MSGHandler.clients)
print('Connected clients: %d' % current)
print('Total connections opened: %d' % total)
print(
'Total connections closed: %d' % (total-current)
)
@run_inside(ioloop.add_callback)
def bcast(message):
from controller import MSGHandler
MSGHandler.broadcast(message)
@run_inside(ioloop.add_callback)
@coroutine
def add_room(room_name, svg_path,
output_path='./qrmaster'):
import src.utils.qrmaster as qrm
from pymongo.errors import DuplicateKeyError, \
OperationFailure
from conf import app_name, proxy_url, \
app_logo_path
from src.db.room import Room, CodeType
from src import messages as msg
try:
_, code_objs = yield Room.create(room_name,
svg_path)
codes = (
[
c.id,
c.room_id if c.code_type ==
CodeType.room.value else c.seat_id
]
for c in code_objs
)
qrm.generate(codes, url=proxy_url,
title=app_name,
img_path=app_logo_path,
output_path=output_path)
except OperationFailure:
pass