Пример #1
0
from types import FunctionType

import tornado.web
import tornado.ioloop
import tornado.web
from lxml import etree

from lib.autoconf import conf_drawer
from lib import path
from lib.tools import XMLUtils
from lib.halo import executor
from lib.tools import Log
from lib.web.err import BizError


logger = Log().getLog()


@conf_drawer.register_my_setup()
def setup():
    # automic scan dirs
    files_list = os.listdir(path._BIZ_PATH)
    files_list = set(['.'.join([os.path.basename(path._BIZ_PATH), x[:x.rfind(".")]])
                      for x in files_list if x.endswith(".py")])
    map(__import__, files_list)


class Application(tornado.web.Application):
    handlers = []

    @classmethod
Пример #2
0
# coding: utf-8
import threading
import time

from Message import *
from lib.tools import Log

logger = Log().getLog()


class User(object):
    __slots__ = ('uid', 'username', 'notify_handler')

    def __init__(self, username):
        self.username = username

    def set_notify_handler(self, handler):
        self.notify_handler = handler
        UserPool.mod_user(self.uid, self)

    def login(self):
        self.uid = str(int(UserPool._max_uid) + 1)
        UserPool.mod_user(self.uid, self)
        logger.info('%s(%s) login!', self.username, self.uid)
        UserPool.broadcast(
            Msg(level=Level.sys | Level.info,
                title='New Player',
                content='%s - %s came in!' %
                (time.strftime('%X'), self.username)).toString())

    def logout(self):
Пример #3
0
    conf_file | E(cpff.parseall) | E(conf_drawer.setup)


if __name__ == "__main__":
    port = 8888
    includes = None
    opts, argvs = getopt.getopt(sys.argv[1:], "c:p:h")
    for op, value in opts:
        if op == '-c':
            includes = value
            path._ETC_PATH = os.path.dirname(os.path.abspath(value))
        elif op == '-p':
            port = int(value)
        elif op == '-h':
            print u'''使用参数启动:
                        usage: [-p|-c]
                        -p [prot] ******启动端口,默认端口:%d
                        -c <file> ******加载配置文件
                   ''' % port
            sys.exit(0)
    if not includes:
        includes = os.path.join(path._ETC_PATH, 'includes_dev.json')
        print "no configuration found!,will use [%s] instead" % includes
    prepare(includes)

    app = core.Application()
    app.listen(port)
    logger = Log().getLog()
    logger.info("starting..., listen [%d], configured by (%s)", port, includes)
    tornado.ioloop.IOLoop.instance().start()