Skip to content

Commit

Permalink
项目目录调整
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxiaobai authored and liuxiaobai committed May 16, 2018
1 parent c29cf05 commit 83c2dc5
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 47 deletions.
Empty file added __init__.py
Empty file.
50 changes: 10 additions & 40 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,33 @@
import logging
import os.path
import logging.config
from concurrent.futures import ThreadPoolExecutor

import tornado.escape
import tornado.ioloop
from tornado.options import define, options
import tornado.web
import tornado.websocket
from handlers.socket import SocketHandler
from handlers.web import WebHandler, UpdateHandler, RegHandler
from db import torndb

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger()
logger.setLevel(logging.INFO)
from tornado.options import define, options

from db import torndb
from settings import settings, DATABASE, LOGGING
from urls import url_patterns

define("host", default="localhost", help="DB host")
define("database", default="ddz", help="DB used")
define("user", default="root", help="DB username")
define("password", default="123123", help="DB Password")
logging.config.dictConfig(LOGGING)


class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r'/', WebHandler),
(r'/update', UpdateHandler),
(r'/reg', RegHandler),
(r'/ws', SocketHandler),
]
settings = dict(
title='Tornado Poker',
cookie_secret='fiDSpuZ7QFe8fm0XP9Jb7ZIPNsOegkHYtgKSd4I83Hs=',
template_path=os.path.join(BASE_DIR, 'static'),
static_path=os.path.join(BASE_DIR, 'static'),
login_url='/',
xsrf_cookies=True,
debug=True,
)
tornado.options.parse_config_file("server.conf")
super(Application, self).__init__(handlers, **settings)
self.db = torndb.Connection(
host=options.host,
database=options.database,
user=options.user,
password=options.password)
super().__init__(url_patterns, **settings)
self.db = torndb.Connection(**DATABASE)
self.executor = ThreadPoolExecutor()


def main():
tornado.options.parse_command_line()
app = Application()
app.listen(8080)
logger.info('listening on 8080')
app.listen(options.port)
logging.info(f'listening on {options.port}')
tornado.ioloop.IOLoop.current().start()


if __name__ == '__main__':
main()

5 changes: 2 additions & 3 deletions db/torndb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class Connection(object):
def __init__(self, host: str, database: str, user: str, password: str, **kwargs):
def __init__(self, host: str, database: str, user: str, password: str):
self.host = host
self.max_idle_time = float(7 * 3600)

Expand All @@ -17,8 +17,7 @@ def __init__(self, host: str, database: str, user: str, password: str, **kwargs)
"user": user,
"password": password,
"port": 3306,

'charset': 'utf8',
'charset': 'utf8mb4',
'use_unicode': True,
'sql_mode': 'TRADITIONAL',
'init_command': 'SET time_zone = "+0:00"',
Expand Down
4 changes: 0 additions & 4 deletions server.conf

This file was deleted.

80 changes: 80 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os

import tornado.template
from tornado.options import define, options

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

define("port", default=8080, help="run on the given port", type=int)
define("debug", default=False, help="debug mode")
define("host", default="localhost", help="Database host")
define("database", default="ddz", help="Database name")
define("user", default="root", help="username")
define("password", default="123456", help="password")
tornado.options.parse_command_line()

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
TEMPLATE_ROOT = os.path.join(BASE_DIR, 'templates')

settings = {
'title': 'Tornado Poker',
'login_url': '/',
'static_path': STATIC_ROOT,
'template_path': TEMPLATE_ROOT,
'xsrf_cookies': True,
'cookie_secret': 'fiDSpuZ7QFe8fm0XP9Jb7ZIPNsOegkHYtgKSd4I83Hs=',
'debug': options.debug,
}

DATABASE = {
'host': options.host,
'database': options.database,
'user': options.user,
'password': options.password,
}

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'root': {
'level': 'INFO',
'handlers': ['file', 'console'],
},
'formatters': {
'simple': {
'format': '%(asctime).19s %(message)s'
},
'verbose': {
'format': '%(asctime)s %(levelname)s %(module)s %(process)d %(thread)d %(message)s'
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'file': {
'level': 'INFO',
'filename': 'ddz.log',
'class': 'logging.FileHandler',
},
},
'loggers': {
'db': {
'level': 'INFO',
'handlers': ['console', 'file'],
'propagate': False,
},
'core': {
'level': 'INFO',
'handlers': ['console'],
'propagate': False,
},
'handlers': {
'level': 'INFO',
'handlers': ['console'],
'propagate': False,
},
},
}
File renamed without changes.
9 changes: 9 additions & 0 deletions urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from handlers.socket import SocketHandler
from handlers.web import WebHandler, UpdateHandler, RegHandler

url_patterns = [
(r'/', WebHandler),
(r'/update', UpdateHandler),
(r'/reg', RegHandler),
(r'/ws', SocketHandler),
]

0 comments on commit 83c2dc5

Please sign in to comment.