Skip to content

Commit ebc77cb

Browse files
committed
Move web to a seperate package, add more functions
1 parent 140bea3 commit ebc77cb

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

cloudbot/bot.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@
1818
from cloudbot.plugin import PluginManager
1919
from cloudbot.event import Event, CommandEvent, RegexEvent, EventType
2020
from cloudbot.util import database, formatting
21-
from cloudbot.web import WebInterface
2221
from cloudbot.clients.irc import IrcClient
2322

23+
try:
24+
from cloudbot.web.main import WebInterface
25+
except ImportError:
26+
WebInterface = None
27+
2428
logger = logging.getLogger("cloudbot")
2529

2630

cloudbot/web/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__author__ = 'Luke'

cloudbot/web.py renamed to cloudbot/web/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import asyncio
22

3+
from tornado import gen
34
from tornado.web import RequestHandler, Application, url
45
from tornado.platform.asyncio import AsyncIOMainLoop
56

7+
from jinja2 import Environment, PackageLoader
8+
9+
10+
def get_template_env():
11+
env = Environment(loader=PackageLoader('cloudbot.web.templates'))
12+
return env
13+
614

715
def get_application():
816
app = Application([
@@ -12,6 +20,7 @@ def get_application():
1220

1321

1422
class TestHandler(RequestHandler):
23+
@gen.coroutine
1524
def get(self):
1625
self.write("Hello world!\n")
1726

@@ -22,6 +31,9 @@ def __init__(self, bot, port=8080, address="0.0.0.0"):
2231
self.port = port
2332
self.address = address
2433

34+
self.template = get_application()
35+
self.template_env = get_template_env()
36+
2537
self.app = None
2638

2739
# Install tornado IO loop.

cloudbot/web/templates/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__author__ = 'Luke'

0 commit comments

Comments
 (0)