# Path: common/constants.py
# STATUS_INVALID = 8 # Invalid status
# 
# EXEC_STATUS = {'stopped':STATUS_STOP, 'paused':STATUS_PAUSED, 'running':STATUS_RUNNING, 'resume':STATUS_RESUME,
# 	'invalid':STATUS_INVALID, 'interact': STATUS_INTERACT, 'restart': STATUS_RESTART}


import os, sys
import json
import platform
import mako
import cherrypy
from mako.template import Template
from binascii import unhexlify as decode
from common.constants  import STATUS_INVALID, EXEC_STATUS
from common.helpers    import calcMemory, calcCpu, dirList
from common.tsclogging import logWarning, logFull, logDebug, LOG_FILE


if mako.__version__ < '0.7':
    logWarning('Warning! Mako-template version is old: `{}`! Some pages might crash!\n'.format(mako.__version__))

#

def prepare_log(log_file, pos=0):
    """ return log content """
    if not os.path.isfile(log_file):
        return 'File `{}` does not exist!'.format(log_file)
    f_p = open(log_file, 'rb')
    f_p.seek(pos)
    log = f_p.read().rstrip()
    f_p.close()
    del f_p

    max_len = 50000
    if len(log) > max_len:
        log = '[... log size exceded ...]   ' + log[-max_len:]

    log = log.replace('<', '&lt;').replace('\n', '<br>\n').replace(' ', '&nbsp;')

    body = '''
    <style>
    .nfo {color:gray; text-shadow: 1px 1px 1px #aaa}
    .dbg {color:gray; text-shadow: 1px 1px 1px #aaa}
    .err {color:orange; text-shadow: 1px 1px 1px #aaa}
    .warn {color:orange; text-shadow: 1px 1px 1px #aaa}
    .crit {color:red; text-shadow: 1px 1px 1px #aaa}

# Path: common/constants.py
# STATUS_INVALID = 8 # Invalid status
# 
# EXEC_STATUS = {'stopped':STATUS_STOP, 'paused':STATUS_PAUSED, 'running':STATUS_RUNNING, 'resume':STATUS_RESUME,
# 	'invalid':STATUS_INVALID, 'interact': STATUS_INTERACT, 'restart': STATUS_RESTART}


# Path: server/CeWebUi.py
import os, sys
import json
import platform
import mako
import cherrypy
from mako.template import Template
from binascii import unhexlify as decode
from common.constants  import STATUS_INVALID, EXEC_STATUS
from common.helpers    import calcMemory, calcCpu, dirList
from common.tsclogging import logWarning, logFull, logDebug, LOG_FILE



if mako.__version__ < '0.7':
    logWarning('Warning! Mako-template version is old: `{}`! Some pages might crash!\n'.format(mako.__version__))

#

def prepare_log(log_file, pos=0):
    """ return log content """
    if not os.path.isfile(log_file):
        return 'File `{}` does not exist!'.format(log_file)
    f_p = open(log_file, 'rb')
    f_p.seek(pos)
    log = f_p.read().rstrip()
    f_p.close()
    del f_p

    max_len = 50000
    if len(log) > max_len:
        log = '[... log size exceded ...]   ' + log[-max_len:]

    log = log.replace('<', '&lt;').replace('\n', '<br>\n').replace(' ', '&nbsp;')

    body = '''
    <style>
    .nfo {color:gray; text-shadow: 1px 1px 1px #aaa}
    .dbg {color:gray; text-shadow: 1px 1px 1px #aaa}
    .err {color:orange; text-shadow: 1px 1px 1px #aaa}
    .warn {color:orange; text-shadow: 1px 1px 1px #aaa}
    .crit {color:red; text-shadow: 1px 1px 1px #aaa}

    </style>