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 Toonloop Web server for files and RSS feeds.
27 """
28 import os
29 import sys
30
31 from twisted.internet import reactor
32 from nevow import static
33 from nevow import appserver
34 from nevow import rend
35
36 from toon import rss
37 from toon import rst
38
39 -class Index(rst.ReStructured, rend.Page):
40 """
41 Class representing the root (/) of the web server.
42 """
43 addSlash = True
44
46 self.static_files_path = os.curdir
47 self.index_file_path = os.path.join(os.path.dirname(__file__), 'data', 'index.rst')
48 self.port = 8000
49 self.__dict__.update(**kwargs)
50
51 print "Static files root:", self.static_files_path
52 try:
53 self.toonloop = toonloop
54 except AttributeError, e:
55 print 'web_server: Index', e.message
56 self.toonloop = None
57 try:
58 rst.ReStructured.__init__(self, self.index_file_path)
59 except IOError, e:
60 print "Error reading rst file.", e.message, self.index_file_path
61
62
63 self.child_files = static.File(self.static_files_path)
64 self.child_data = static.File(os.path.join(os.path.dirname(__file__), 'data'))
65 self.child_rss = rss.RSSPage(port=self.port, root=self.static_files_path)
66
72
73 -def start(toonloop, port=8000, **kwargs):
74 """
75 Called from the main application to start the web UI.
76 Config argmuments ARE overriden from the application.
77
78 :param toonloop: The application
79 :param port: web server port
80 """
81
82 web_config = {
83 'static_files_path':os.path.expanduser("~/Documents/toonloop"),
84 'index_file_path':os.path.join(os.path.dirname(__file__), 'data', 'index.rst'),
85 'port':port
86 }
87 web_config.update(kwargs)
88
89
90 site = appserver.NevowSite(Index(toonloop, **web_config))
91 if toonloop.config.verbose:
92 print 'Starting web server on port', port
93 print 'Static Documentation Files Path : ', web_config['index_file_path']
94 reactor.listenTCP(port, site)
95
96 if __name__ == '__main__':
97
98 start(None)
99 try:
100 reactor.run()
101 except:
102 raise
103