forked from mailgyc/doudizhu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liuxiaobai
authored and
liuxiaobai
committed
May 16, 2018
1 parent
c29cf05
commit 83c2dc5
Showing
7 changed files
with
101 additions
and
47 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |