Пример #1
0
 def stopFramework(self):
     # 清空数据库
     database.db_clear()
     database.db_init()
     # 添加超级用户
     privilegeM.priv_add_superuser()
     # 初始化权限管理模块
     privilegeM.priv_init()
Пример #2
0
    def run():
        #加锁,只能启动一个服务
        if ServerClass._lock:
            log.logError("server is already running..")
            return
        ServerClass._lock = True
        #初始化数据库
        database.db_init()
        #添加超级用户
        privilegeM.priv_add_superuser()
        #初始化权限管理模块
        privilegeM.priv_init()

        #解析命令行, 有了这行,还可以看到日志...
        #options.parse_command_line()
        settings = {
                    'debug': False,
                    'gzip': True,
                    'autoescape': None,
                    'xsrf_cookies': False,
                    'cookie_secret':"61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
                    'template_path':os.path.join(os.path.dirname(__file__), "playground"),
                    'static_path':os.path.join(os.path.dirname(__file__), "playground/main/static"),
                    'login_url':'/playground/login'
                }
        application = web.Application(
            [
                (HTTP_RES['root'], handlers.rootHandle),
                (HTTP_RES['user'], handlers.usersHandle),
                (HTTP_RES['userOne'], handlers.userOneHandle),
                (HTTP_RES['device'], handlers.devicesHandle),
                (HTTP_RES['deviceOne'], handlers.deviceOneHandle),
                (HTTP_RES['sensor'], handlers.sensorsHandle),
                (HTTP_RES['sensorOne'], handlers.sensorOneHandle),
                (HTTP_RES['dataSet'], handlers.datasetHandle),
                (HTTP_RES['commandSet'], handlers.commandsetHandle),
                (HTTP_RES['commandSetOne'], handlers.commandsetOneHandle),
                (HTTP_RES['deviceAuth'], handlers.deviceauthHandle),
                (HTTP_RES['accessKey'], handlers.accessKeyHandle),
                (HTTP_RES['userLogin'], handlers.userLoginHandle),
                (HTTP_RES['userLogout'], handlers.userLogoutHandle),
                ##playgruod below
                (r'/playground', playground.rootHandle),
                (r'/playground/login', playground.loginHandle),
            ], **settings)
        ServerClass.server = HTTPServer(application)
        ServerClass.server.listen(configure.server_port,configure.server_ip)
        try:
            ioloop.IOLoop.instance().start()
        except Exception,e:
            log.logFatal("start server fail, exception:"+e.message)
            ServerClass._lock = False