Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

Commit 8b02851

Browse files
committed
simple skeleton
1 parent 4489ae0 commit 8b02851

17 files changed

+111
-12
lines changed

manager.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
import click
3+
import tornado
4+
5+
from spirit.app import Application
6+
from spirit.config import load_config
7+
8+
9+
@click.group()
10+
def main():
11+
pass
12+
13+
14+
@main.command()
15+
@click.option('--port', default=8000, help='number of port')
16+
@click.option('--mode', default='development', help='run mode')
17+
def runserver(port, mode):
18+
click.secho("server is running on port {} in {} mode".format(port, mode),
19+
fg="green")
20+
config = load_config(mode)
21+
app = Application(config)
22+
app.listen(port)
23+
tornado.ioloop.IOLoop.current().start()
24+
25+
26+
@main.command()
27+
def init_db():
28+
pass
29+
30+
31+
@main.command()
32+
def drop_db():
33+
pass
34+
35+
36+
if __name__ == '__main__':
37+
main()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
backports-abc==0.4
22
backports.ssl-match-hostname==3.5.0.1
33
certifi==2016.2.28
4+
click==6.6
45
singledispatch==3.4.0.3
56
six==1.10.0
67
tornado==4.3

spirit/__init__.pyc

159 Bytes
Binary file not shown.

spirit/app.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
import tornado.ioloop
1+
# -*- coding: utf-8 -*-
22
import tornado.web
33

4-
class MainHandler(tornado.web.RequestHandler):
5-
def get(self):
6-
self.write("Hello, world")
4+
from .routers import routers
75

8-
def make_app():
9-
return tornado.web.Application([
10-
(r"/", MainHandler),
11-
])
126

13-
if __name__ == "__main__":
14-
app = make_app()
15-
app.listen(8888)
16-
tornado.ioloop.IOLoop.current().start()
7+
class Application(tornado.web.Application):
8+
def __init__(self, config):
9+
settings = dict(
10+
autoescape=None,
11+
debug=config.DEBUG,
12+
# cookie_secret=base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes)
13+
cookie_secret=config.cookie_secret,
14+
template_path=config.template_path,
15+
static_path=config.static_path,
16+
xsrf_cookies=True,
17+
)
18+
19+
tornado.web.Application.__init__(self, routers, **settings)

spirit/app.pyc

936 Bytes
Binary file not shown.

spirit/config/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
from .base import load_config
3+
4+
5+
all = ['load_config']

spirit/config/__init__.pyc

246 Bytes
Binary file not shown.

spirit/config/base.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
import base64
3+
import os
4+
import uuid
5+
6+
7+
def load_config(mode):
8+
if mode == 'development':
9+
from .development import config
10+
elif mode == 'production':
11+
from .production import config
12+
return config
13+
14+
15+
class Config(object):
16+
def __init__(self):
17+
self.DEBUG = True
18+
self.cookie_secret = base64.b64encode(
19+
uuid.uuid4().bytes + uuid.uuid4().bytes)
20+
self.template_path = os.path.abspath('../views')
21+
self.static_path = os.path.abspath('../static')

spirit/config/base.pyc

1.21 KB
Binary file not shown.

spirit/config/development.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8 -*-
2+
from .base import Config
3+
4+
5+
class DevelopmentConfig(Config):
6+
pass
7+
8+
9+
config = DevelopmentConfig()

0 commit comments

Comments
 (0)