# Path: toughwlan/manage/base.py
# ADMIN_MENUS = (MenuSys, MenuRes, MenuUser) = (u"系统管理", u"资源管理", u"用户管理")
# MENU_ICONS = {
#     u"系统管理": "fa fa-cog",
#     u"资源管理": "fa fa-desktop",
#     u"用户管理": "fa fa-users"
# }
# class BaseHandler(cyclone.web.RequestHandler):
#     def __init__(self, *argc, **argkw):
#     def initialize(self):
#     def on_finish(self):
#     def get_error_html(self, status_code=500, **kwargs):
#     def render(self, template_name, **template_vars):
#     def render_error(self, **template_vars):
#     def render_json(self, **template_vars):
#     def render_string(self, template_name, **template_vars):
#     def render_from_string(self, template_string, **template_vars):
#     def get_page_data(self, query):
#     def get_page_url(self, page, form_id=None):
#     def set_session_user(self, username, ipaddr, opr_type, login_time):
#     def clear_session(self):
#     def get_current_user(self):
#     def get_params(self):
#     def get_params_obj(self, obj):
#     def add_oplog(self,message):


import os
import subprocess
import os.path
import cyclone.web
        import traceback
from toughwlan.manage.base import BaseHandler, MenuSys
from toughlib.permit import permit
def warp_html(code, value):
    _value = value.replace("\n", "<br>")
    _value = _value.replace("RUNNING", "<strong><font color=green>RUNNING</font></strong>")
    _value = _value.replace("STARTING", "<strong><font color='#CC9900'>STARTING</font></strong>")
    _value = _value.replace("FATAL", "<strong><font color=red>FATAL</font></strong>")
    if code > 0:
        _value = '<font color="#CC0000">%s</font>' % _value
    return _value


def execute(cmd):
    try:
        rcode, stdout, stderr = run_command(cmd, True)
        return dict(value=warp_html(rcode, (stdout or stderr)))
    except ToughError, err:
        traceback.print_exc()
        return dict(value=warp_html(1, err.message))


##############################################################################
# web handler
##############################################################################

@permit.route(r"/dashboard", u"控制面板", MenuSys, order=1.0000, is_menu=True, is_open=False)
class DashboardHandler(BaseHandler):

    @cyclone.web.authenticated
    def get(self):
        self.render("index.html", config=self.settings.config)


# Path: toughwlan/manage/base.py
# ADMIN_MENUS = (MenuSys, MenuRes, MenuUser) = (u"系统管理", u"资源管理", u"用户管理")
# MENU_ICONS = {
#     u"系统管理": "fa fa-cog",
#     u"资源管理": "fa fa-desktop",
#     u"用户管理": "fa fa-users"
# }
# class BaseHandler(cyclone.web.RequestHandler):
#     def __init__(self, *argc, **argkw):
#     def initialize(self):
#     def on_finish(self):
#     def get_error_html(self, status_code=500, **kwargs):
#     def render(self, template_name, **template_vars):
#     def render_error(self, **template_vars):
#     def render_json(self, **template_vars):
#     def render_string(self, template_name, **template_vars):
#     def render_from_string(self, template_string, **template_vars):
#     def get_page_data(self, query):
#     def get_page_url(self, page, form_id=None):
#     def set_session_user(self, username, ipaddr, opr_type, login_time):
#     def clear_session(self):
#     def get_current_user(self):
#     def get_params(self):
#     def get_params_obj(self, obj):
#     def add_oplog(self,message):


# Path: toughwlan/manage/system/dashboard.py
import os
import subprocess
import os.path
import cyclone.web
        import traceback
from toughwlan.manage.base import BaseHandler, MenuSys
from toughlib.permit import permit

def warp_html(code, value):
    _value = value.replace("\n", "<br>")
    _value = _value.replace("RUNNING", "<strong><font color=green>RUNNING</font></strong>")
    _value = _value.replace("STARTING", "<strong><font color='#CC9900'>STARTING</font></strong>")
    _value = _value.replace("FATAL", "<strong><font color=red>FATAL</font></strong>")
    if code > 0:
        _value = '<font color="#CC0000">%s</font>' % _value
    return _value


def execute(cmd):
    try:
        rcode, stdout, stderr = run_command(cmd, True)
        return dict(value=warp_html(rcode, (stdout or stderr)))
    except ToughError, err:
        traceback.print_exc()
        return dict(value=warp_html(1, err.message))


##############################################################################
# web handler
##############################################################################

@permit.route(r"/dashboard", u"控制面板", MenuSys, order=1.0000, is_menu=True, is_open=False)
class DashboardHandler(BaseHandler):

    @cyclone.web.authenticated
    def get(self):
        self.render("index.html", config=self.settings.config)


@permit.route(r"/dashboard/initdb", u"初始化数据库", MenuSys, order=1.0001, is_menu=False)