Merge branch 'dev' of github.com:eomsoft/teleport into dev

# Conflicts:
#	server/tp_core/core/main.cpp
#	server/tp_core/core/ts_env.cpp
#	server/tp_core/core/ts_env.h
#	server/www/teleport/app/eom_app/app/db.py
pull/32/merge
apexliu 2017-03-28 01:16:30 +08:00
commit c473b1973b
14 changed files with 143 additions and 130 deletions

1
.gitignore vendored
View File

@ -14,6 +14,7 @@ CMakeFiles
cmake_install.cmake
Makefile
cmake-build
cmake-build-debug
# for Python
__pycache__

View File

@ -6,7 +6,7 @@
VER_PYTHON="3.4.4"
VER_PYTHON_SHORT="3.4"
VER_OPENSSL="1.0.2h"
VER_SQLITE="3160200"
VER_SQLITE="3170000"
VER_PSUTIL="4.2.0"
VER_PYTHON_LIB="${VER_PYTHON_SHORT}m"

View File

@ -22,8 +22,8 @@ public:
bool set_log_file(const ex_wstr& log_path, const ex_wstr& log_name, ex_u32 max_filesize, ex_u8 max_count);
void log_a(int level, const char* fmt, va_list valist);
void log_w(int level, const wchar_t* fmt, va_list valist);
bool write(const char* buf);
bool write(const wchar_t* buf);
bool write_a(const char* buf);
bool write_w(const wchar_t* buf);
protected:
bool _open_file();

View File

@ -1,33 +1,27 @@
#include <ex/ex_log.h>
#include <ex/ex_path.h>
#include <ex/ex_thread.h>
#include <vector>
#include <deque>
#include <algorithm>
//#include <ex/ex_thread.h>
//#include <vector>
//#include <deque>
//#include <algorithm>
#ifdef EX_OS_WIN32
# include <io.h>
# include <stdio.h>
# include <direct.h>
#else
# include <dirent.h>
# include <sys/time.h>
//# include <dirent.h>
//# include <sys/time.h>
#endif
#define EX_LOG_CONTENT_MAX_LEN 2048
//typedef std::deque<unsigned long long> log_file_deque;
//ExLogger g_ex_logger;
static ExLogger* g_exlog = NULL;//&g_ex_logger;
static ExLogger* g_exlog = NULL;
void EXLOG_USE_LOGGER(ExLogger* logger)
{
// if (NULL == logger)
// g_exlog = &g_ex_logger;
// else
// g_exlog = logger;
g_exlog = logger;
}
@ -99,7 +93,7 @@ void ExLogger::log_a(int level, const char* fmt, va_list valist)
return;
char szTmp[4096] = { 0 };
int offset = 0;
size_t offset = 0;
if (level == EX_LOG_LEVEL_ERROR)
{
@ -112,22 +106,39 @@ void ExLogger::log_a(int level, const char* fmt, va_list valist)
#ifdef EX_OS_WIN32
vsnprintf_s(szTmp+offset, 4096-offset, 4095-offset, fmt, valist);
if (NULL != console_handle)
if(to_console)
{
printf_s("%s", szTmp);
fflush(stdout);
}
else
{
OutputDebugStringA(szTmp);
if (NULL != console_handle)
{
printf_s("%s", szTmp);
fflush(stdout);
}
else
{
if(debug_mode)
OutputDebugStringA(szTmp);
}
}
#else
vsnprintf(szTmp+offset, 4095-offset, fmt, valist);
printf("%s", szTmp);
fflush(stdout);
if(to_console)
{
// On linux, the stdout only output the first time output format (char or wchar_t).
// e.g.: first time you use printf(), then after that, every wprintf() not work, and vice versa.
// so we always use wprintf() to fix that.
ex_astr tmp(szTmp);
ex_wstr _tmp;
ex_astr2wstr(tmp, _tmp);
wprintf(L"%ls", _tmp.c_str());
fflush(stdout);
// printf("%s", szTmp);
// fflush(stdout);
}
#endif
write(szTmp);
write_a(szTmp);
}
void ExLogger::log_w(int level, const wchar_t* fmt, va_list valist)
@ -136,7 +147,7 @@ void ExLogger::log_w(int level, const wchar_t* fmt, va_list valist)
return;
wchar_t szTmp[4096] = { 0 };
int offset = 0;
size_t offset = 0;
if (level == EX_LOG_LEVEL_ERROR)
{
@ -149,25 +160,32 @@ void ExLogger::log_w(int level, const wchar_t* fmt, va_list valist)
#ifdef EX_OS_WIN32
_vsnwprintf_s(szTmp+offset, 4096-offset, 4095-offset, fmt, valist);
if (NULL != console_handle)
if(to_console)
{
wprintf_s(_T("%s"), szTmp);
fflush(stdout);
}
else
{
OutputDebugStringW(szTmp);
if (NULL != console_handle)
{
wprintf_s(_T("%s"), szTmp);
fflush(stdout);
}
else
{
if(debug_mode)
OutputDebugStringW(szTmp);
}
}
#else
vswprintf(szTmp+offset, 4095-offset, fmt, valist);
wprintf(L"%ls", szTmp);
fflush(stdout);
if(to_console)
{
wprintf(L"%ls", szTmp);
fflush(stdout);
}
#endif
write(szTmp);
write_w(szTmp);
}
#define EX_PRINTF_X(fn, level) \
#define EX_PRINTF_XA(fn, level) \
void fn(const char* fmt, ...) \
{ \
if(NULL == g_exlog) \
@ -179,7 +197,9 @@ void fn(const char* fmt, ...) \
va_start(valist, fmt); \
g_exlog->log_a(level, fmt, valist); \
va_end(valist); \
} \
}
#define EX_PRINTF_XW(fn, level) \
void fn(const wchar_t* fmt, ...) \
{ \
if(NULL == g_exlog) \
@ -193,11 +213,17 @@ void fn(const wchar_t* fmt, ...) \
va_end(valist); \
}
EX_PRINTF_X(ex_printf_d, EX_LOG_LEVEL_DEBUG)
EX_PRINTF_X(ex_printf_v, EX_LOG_LEVEL_VERBOSE)
EX_PRINTF_X(ex_printf_i, EX_LOG_LEVEL_INFO)
EX_PRINTF_X(ex_printf_w, EX_LOG_LEVEL_WARN)
EX_PRINTF_X(ex_printf_e, EX_LOG_LEVEL_ERROR)
EX_PRINTF_XA(ex_printf_d, EX_LOG_LEVEL_DEBUG)
EX_PRINTF_XA(ex_printf_v, EX_LOG_LEVEL_VERBOSE)
EX_PRINTF_XA(ex_printf_i, EX_LOG_LEVEL_INFO)
EX_PRINTF_XA(ex_printf_w, EX_LOG_LEVEL_WARN)
EX_PRINTF_XA(ex_printf_e, EX_LOG_LEVEL_ERROR)
EX_PRINTF_XW(ex_printf_d, EX_LOG_LEVEL_DEBUG)
EX_PRINTF_XW(ex_printf_v, EX_LOG_LEVEL_VERBOSE)
EX_PRINTF_XW(ex_printf_i, EX_LOG_LEVEL_INFO)
EX_PRINTF_XW(ex_printf_w, EX_LOG_LEVEL_WARN)
EX_PRINTF_XW(ex_printf_e, EX_LOG_LEVEL_ERROR)
#ifdef EX_OS_WIN32
@ -268,7 +294,7 @@ void ex_printf_bin(const ex_u8* bin_data, size_t bin_size, const char* fmt, ...)
unsigned int i = 0;
char szTmp[128] = { 0 };
int _offset = 0;
size_t _offset = 0;
while (offset < bin_size)
{
@ -529,7 +555,7 @@ bool ExLogFile::_backup_file()
}
#endif // if 0
bool ExLogger::write(const char* buf)
bool ExLogger::write_a(const char* buf)
{
if (NULL == m_file)
return false;
@ -561,7 +587,7 @@ bool ExLogger::write(const char* buf)
return false;
sprintf(szTime, "[%04d-%02d-%02d %02d:%02d:%02d] ", p->tm_year + 1900, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
int lenTime = strlen(szTime);
size_t lenTime = strlen(szTime);
fwrite(szTime, lenTime, 1, m_file);
m_filesize += lenTime;
fwrite(buf, len, 1, m_file);
@ -573,11 +599,11 @@ bool ExLogger::write(const char* buf)
return _rotate_file();
}
bool ExLogger::write(const wchar_t* buf)
bool ExLogger::write_w(const wchar_t* buf)
{
ex_astr _buf;
ex_wstr2astr(buf, _buf, EX_CODEPAGE_UTF8);
return write(_buf.c_str());
return write_a(_buf.c_str());
}

View File

@ -15,15 +15,16 @@ log-level=0
; 'replay-path' define the replay file location. if not set, default location
; to $INSTDIR%/data/replay/
;replay-path=/usr/local/eom/teleport/data/replay
;replay-path=/var/lib/teleport/data/replay
web-server-rpc=http://127.0.0.1:7190/rpc
[rpc]
; Request by web server. `ip` should be the ip of core server, default to
; 127.0.0.1 because web server and core server running at the same machine.
;ip=127.0.0.1
port=52080
; Request by web server. `bind-ip` should be the ip of core server. If
; web server and core server running at the same machine, it should be
; 127.0.0.1
bind-ip=127.0.0.1
bind-port=52080
[protocol-ssh]
enabled=true

View File

@ -9,7 +9,7 @@ TsEnv::TsEnv()
TsEnv::~TsEnv()
{}
bool TsEnv::init(bool run_core)
bool TsEnv::init(bool load_config)
{
EXLOG_LEVEL(EX_LOG_LEVEL_INFO);
@ -18,38 +18,54 @@ bool TsEnv::init(bool run_core)
m_exec_path = m_exec_file;
ex_dirname(m_exec_path);
if(!run_core)
if(!load_config)
return true;
// 定位 log, etc 路径
// 默认情况下,以上三个目录均位于本可执行程序的 ../ 相对位置,
// 如果不存在则可能是开发调试模式则尝试从源代码仓库根目录下的share目录中查找。
// check development flag file, if exists, run in development mode for trace and debug.
ex_wstr dev_flag_file = m_exec_path;
ex_path_join(dev_flag_file, false, L"dev_mode", NULL);
ex_wstr base_path = m_exec_path;
ex_path_join(base_path, true, L"..", NULL);
ex_wstr log_path;
ex_wstr conf_file;
m_etc_path = base_path;
ex_path_join(m_etc_path, false, L"etc", NULL);
ex_wstr conf_file = m_etc_path;
ex_path_join(conf_file, false, L"core.ini", NULL);
if (!ex_is_file_exists(conf_file.c_str()))
if (ex_is_file_exists(dev_flag_file.c_str()))
{
EXLOGW("[core] ===== DEVELOPMENT MODE =====\n");
base_path = m_exec_path;
ex_path_join(base_path, true, L"..", L"..", L"..", L"..", L"server", L"share", NULL);
EXLOGW("===== DEVELOPMENT MODE =====\n");
ex_path_join(base_path, true, L"..", L"..", L"..", L"..", L"server", NULL);
m_etc_path = base_path;
ex_path_join(m_etc_path, false, L"etc", NULL);
ex_path_join(m_etc_path, false, L"share", L"etc", NULL);
conf_file = m_etc_path;
ex_path_join(conf_file, false, L"core.ini", NULL);
}
if (!ex_is_file_exists(conf_file.c_str()))
m_replay_path = base_path;
ex_path_join(m_replay_path, false, L"share", L"data", L"replay", NULL);
log_path = base_path;
ex_path_join(log_path, false, L"share", L"log", NULL);
}
else // not in development mode
{
EXLOGE("[core] core.ini not found.\n");
return false;
#ifdef EX_OS_WIN
base_path = m_exec_path;
ex_path_join(base_path, true, L"..", NULL);
m_etc_path = base_path;
ex_path_join(m_etc_path, false, L"etc", NULL);
conf_file = m_etc_path;
ex_path_join(conf_file, false, L"core.ini", NULL);
m_replay_path = base_path;
ex_path_join(m_replay_path, false, L"data", L"replay", NULL);
log_path = base_path;
ex_path_join(log_path, false, L"log", NULL);
#else
m_etc_path = L"/etc/teleport";
conf_file = L"/etc/teleport/core.ini";
m_replay_path = L"/var/lib/teleport/data/replay";
log_path = L"/var/log/teleport";
#endif
}
if (!m_ini.LoadFromFile(conf_file))
@ -60,24 +76,26 @@ bool TsEnv::init(bool run_core)
ExIniSection* ps = m_ini.GetSection(L"common");
if (!ps->GetStr(L"replay-path", m_replay_path))
ex_wstr replay_path;
if (ps->GetStr(L"replay-path", replay_path))
{
m_replay_path = base_path;
ex_path_join(m_replay_path, false, L"data", L"replay", NULL);
m_replay_path = replay_path;
}
ex_wstr log_file;
if (!ps->GetStr(L"log-file", log_file))
{
ex_wstr log_path = base_path;
ex_path_join(log_path, false, L"log", NULL);
EXLOG_FILE(L"tpcore.log", log_path.c_str());
}
else
{
ex_remove_white_space(log_file);
if (log_file[0] == L'"' || log_file[0] == L'\'')
log_file.erase(0, 1);
if (log_file[ log_file.length() - 1 ] == L'"' || log_file[log_file.length() - 1] == L'\'')
log_file.erase(log_file.length() - 1, 1);
ex_wstr log_path = log_file;
log_path = log_file;
ex_dirname(log_path);
ex_wstr file_name;
file_name.assign(log_file, log_path.length() + 1, log_file.length());
@ -88,7 +106,6 @@ bool TsEnv::init(bool run_core)
int log_level = EX_LOG_LEVEL_INFO;
if (ps->GetInt(L"log-level", log_level))
{
EXLOGV("log-level: %d\n", log_level);
EXLOG_LEVEL(log_level);
}

View File

@ -9,7 +9,7 @@ public:
TsEnv();
~TsEnv();
bool init(bool run_core);
bool init(bool load_config);
ExIniFile& get_ini(void) { return m_ini; }

View File

@ -534,7 +534,7 @@ static bool _run_daemon(void)
//===============================================================
// 演示如何加入内建模块供脚本调用
// 加入内建模块供脚本调用
//===============================================================
PyObject* _py_log_output(PyObject* self, PyObject* args)
{
@ -551,8 +551,8 @@ PyObject* _py_log_output(PyObject* self, PyObject* args)
ex_wstr tmp;
ex_astr2wstr(msg, tmp, EX_CODEPAGE_UTF8);
// EXLOGE(L"(%d) %ls.\n", level, tmp.c_str());
//EXLOGV(msg);
switch (level)
{
case EX_LOG_LEVEL_DEBUG:
@ -572,7 +572,7 @@ PyObject* _py_log_output(PyObject* self, PyObject* args)
break;
default:
PYLIB_RETURN_FALSE;
break;
// break;
}
//return pylib_PyLong_FromLong(0x010001);
@ -602,6 +602,8 @@ PyObject* _py_log_console(PyObject* self, PyObject* args)
PYLIB_RETURN_FALSE;
}
// EXLOGE("to_console=%s\n", to_console?"true":"false");
EXLOG_CONSOLE(to_console);
PYLIB_RETURN_TRUE;

View File

@ -8,7 +8,7 @@ TsEnv::TsEnv()
TsEnv::~TsEnv()
{}
bool TsEnv::init(bool for_web)
bool TsEnv::init(bool load_config)
{
EXLOG_LEVEL(EX_LOG_LEVEL_INFO);
@ -17,7 +17,7 @@ bool TsEnv::init(bool for_web)
m_exec_path = m_exec_file;
ex_dirname(m_exec_path);
if (!for_web)
if (!load_config)
return true;
// check development flag file, if exists, run in development mode for trace and debug.
@ -30,11 +30,11 @@ bool TsEnv::init(bool for_web)
if (ex_is_file_exists(dev_flag_file.c_str()))
{
EXLOGW("===== DEVELOPMENT MODE =====\n");
EXLOGW("===== DEVELOPMENT MODE =====\n");
ex_path_join(base_path, true, L"..", L"..", L"..", L"..", L"server", NULL);
conf_file = base_path;
ex_path_join(conf_file, false, L"share", L"etc", L"web.ini.in", NULL);
ex_path_join(conf_file, false, L"share", L"etc", L"web.ini", NULL);
log_path = base_path;
ex_path_join(log_path, false, L"share", L"log", NULL);
@ -59,33 +59,6 @@ bool TsEnv::init(bool for_web)
m_www_path = base_path;
ex_path_join(m_www_path, false, L"www", NULL);
// // 定位 log, etc, www 路径
// // 默认情况下,以上三个目录均位于本可执行程序的 ../ 相对位置,
// // 如果不存在则可能是开发调试模式则尝试从源代码仓库根目录下的share目录中查找。
// ex_wstr base_path = m_exec_path;
// ex_path_join(base_path, true, L"..", NULL);
//
// ex_wstr conf_file = base_path;
// ex_path_join(conf_file, false, L"etc", L"web.ini", NULL);
//
// if (ex_is_file_exists(conf_file.c_str()))
// {
// m_www_path = base_path;
// ex_path_join(m_www_path, false, L"www", NULL);
// }
// else
// {
// EXLOGW("===== DEVELOPMENT MODE =====\n");
// base_path = m_exec_path;
// ex_path_join(base_path, true, L"..", L"..", L"..", L"..", L"server", L"share", NULL);
//
// conf_file = base_path;
// ex_path_join(conf_file, false, L"etc", L"web.ini", NULL);
//
// m_www_path = m_exec_path;
// ex_path_join(m_www_path, true, L"..", L"..", L"..", L"..", L"server", L"www", NULL);
// }
if (!ex_is_file_exists(conf_file.c_str()))
{
EXLOGE(L"[tpweb] `%s` not found.\n", conf_file.c_str());
@ -103,8 +76,6 @@ bool TsEnv::init(bool for_web)
ExIniSection* ps = cfg.GetDumySection();
if (!ps->GetStr(L"log_file", log_file))
{
// ex_wstr log_path = base_path;
// ex_path_join(log_path, false, L"log", NULL);
EXLOG_FILE(L"tpweb.log", log_path.c_str());
}
else
@ -115,7 +86,6 @@ bool TsEnv::init(bool for_web)
if (log_file[ log_file.length() - 1 ] == L'"' || log_file[log_file.length() - 1] == L'\'')
log_file.erase(log_file.length() - 1, 1);
// ex_wstr log_path = log_file;
log_path = log_file;
ex_dirname(log_path);
ex_wstr file_name;
@ -131,8 +101,5 @@ bool TsEnv::init(bool for_web)
EXLOG_LEVEL(log_level);
}
// EXLOGI("==============================\n");
// EXLOGI("[tpweb] start...\n");
return true;
}

View File

@ -9,7 +9,7 @@ public:
TsEnv();
~TsEnv();
bool init(bool for_web);
bool init(bool load_config);
public:
ex_wstr m_exec_file;

View File

@ -11,7 +11,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/app" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="py" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">

View File

@ -109,5 +109,5 @@ PRIMARY KEY (`name` ASC)
return True
except:
log.e('ERROR')
log.e('ERROR\n')
return False

View File

@ -8,6 +8,7 @@ import datetime
from eom_common.eomcore import utils
from eom_common.eomcore.logger import log
from eom_common.eomcore import utils
# from .configs import app_cfg
from .database.create import create_and_init
from .database.upgrade import DatabaseUpgrade
@ -60,7 +61,6 @@ class TPDatabase:
return False
# 看看数据库中是否存在指定的数据表(如果不存在,可能是一个空数据库文件),则可能是一个新安装的系统
# ret = self.query('SELECT COUNT(*) FROM `sqlite_master` WHERE `type`="table" AND `name`="{}account";'.format(self._table_prefix))
ret = self.is_table_exists('{}group'.format(self._table_prefix))
if ret is None or not ret:
# if ret is None or ret[0][0] == 0:
@ -248,7 +248,7 @@ class TPSqlitePool(TPDatabasePool):
try:
return sqlite3.connect(self._db_file)
except:
log.e('[sqlite] can not connect, does the database file correct?')
log.e('[sqlite] can not connect, does the database file correct?\n')
return None
def _do_query(self, conn, sql):

View File

@ -22,7 +22,6 @@ USE_TPWEB_LOG = False
try:
import tpweb
USE_TPWEB_LOG = True
LOG_DEBUG = tpweb.EX_LOG_LEVEL_DEBUG
LOG_VERBOSE = tpweb.EX_LOG_LEVEL_VERBOSE