-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
52 lines (42 loc) · 1.41 KB
/
Copy pathserver.py
File metadata and controls
52 lines (42 loc) · 1.41 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
import logging
import time
import tornado.ioloop
import tornado.web
from config import LOGGING_FORMAT
from config import PORT
from handler.chunks import ChunksHandler
from handler.file import FileHandler
from handler.files import FilesHandler
from handler.groups import GroupsHandler
from handler.main import MainHandler
from storage.groups import groups
from storage.hashring import hashring
def make_app():
settings = {
'gzip': True,
'debug': True,
'static_path': 'static/',
'template_path': 'template/' # todo: Bug : fix bug cwd not xfilehub
}
return tornado.web.Application([
(r'/', MainHandler),
(r'/chunks', ChunksHandler),
(r'/files', FilesHandler),
(r'/files/(?P<filename>.*)', FileHandler),
(r'/groups', GroupsHandler),
], **settings)
def init():
logging.basicConfig(format=LOGGING_FORMAT, level=logging.INFO)
while hashring.size() != 10:
logging.info('try to insert groups to hashring')
for group_name, group_info in groups.get_all().items():
hashring.insert(group_name)
logging.info('insert %s to hashring' % group_name)
time.sleep(0.5)
logging.info('haring has %s group' % hashring.size())
if __name__ == '__main__':
app = make_app()
app.listen(PORT)
init()
logging.info('front server running at %s' % PORT)
tornado.ioloop.IOLoop.current().start()