works on linux now.

pull/32/merge
Apex Liu 2017-03-27 17:10:26 +00:00
parent 91b0d0bfb2
commit b3a617614e
15 changed files with 163 additions and 135 deletions

1
.gitignore vendored
View File

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

View File

@ -6,7 +6,7 @@
VER_PYTHON="3.4.4" VER_PYTHON="3.4.4"
VER_PYTHON_SHORT="3.4" VER_PYTHON_SHORT="3.4"
VER_OPENSSL="1.0.2h" VER_OPENSSL="1.0.2h"
VER_SQLITE="3160200" VER_SQLITE="3170000"
VER_PSUTIL="4.2.0" VER_PSUTIL="4.2.0"
VER_PYTHON_LIB="${VER_PYTHON_SHORT}m" 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); 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_a(int level, const char* fmt, va_list valist);
void log_w(int level, const wchar_t* fmt, va_list valist); void log_w(int level, const wchar_t* fmt, va_list valist);
bool write(const char* buf); bool write_a(const char* buf);
bool write(const wchar_t* buf); bool write_w(const wchar_t* buf);
protected: protected:
bool _open_file(); bool _open_file();

View File

@ -1,33 +1,27 @@
#include <ex/ex_log.h> #include <ex/ex_log.h>
#include <ex/ex_path.h> #include <ex/ex_path.h>
#include <ex/ex_thread.h> //#include <ex/ex_thread.h>
#include <vector> //#include <vector>
#include <deque> //#include <deque>
#include <algorithm> //#include <algorithm>
#ifdef EX_OS_WIN32 #ifdef EX_OS_WIN32
# include <io.h> # include <io.h>
# include <stdio.h> # include <stdio.h>
# include <direct.h> # include <direct.h>
#else #else
# include <dirent.h> //# include <dirent.h>
# include <sys/time.h> //# include <sys/time.h>
#endif #endif
#define EX_LOG_CONTENT_MAX_LEN 2048 #define EX_LOG_CONTENT_MAX_LEN 2048
//typedef std::deque<unsigned long long> log_file_deque; //typedef std::deque<unsigned long long> log_file_deque;
//ExLogger g_ex_logger; static ExLogger* g_exlog = NULL;
static ExLogger* g_exlog = NULL;//&g_ex_logger;
void EXLOG_USE_LOGGER(ExLogger* logger) void EXLOG_USE_LOGGER(ExLogger* logger)
{ {
// if (NULL == logger)
// g_exlog = &g_ex_logger;
// else
// g_exlog = logger;
g_exlog = logger; g_exlog = logger;
} }
@ -99,7 +93,7 @@ void ExLogger::log_a(int level, const char* fmt, va_list valist)
return; return;
char szTmp[4096] = { 0 }; char szTmp[4096] = { 0 };
int offset = 0; size_t offset = 0;
if (level == EX_LOG_LEVEL_ERROR) if (level == EX_LOG_LEVEL_ERROR)
{ {
@ -112,6 +106,8 @@ void ExLogger::log_a(int level, const char* fmt, va_list valist)
#ifdef EX_OS_WIN32 #ifdef EX_OS_WIN32
vsnprintf_s(szTmp+offset, 4096-offset, 4095-offset, fmt, valist); vsnprintf_s(szTmp+offset, 4096-offset, 4095-offset, fmt, valist);
if(to_console)
{
if (NULL != console_handle) if (NULL != console_handle)
{ {
printf_s("%s", szTmp); printf_s("%s", szTmp);
@ -119,15 +115,30 @@ void ExLogger::log_a(int level, const char* fmt, va_list valist)
} }
else else
{ {
if(debug_mode)
OutputDebugStringA(szTmp); OutputDebugStringA(szTmp);
} }
}
#else #else
vsnprintf(szTmp+offset, 4095-offset, fmt, valist); vsnprintf(szTmp+offset, 4095-offset, fmt, valist);
printf("%s", szTmp); 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); fflush(stdout);
// printf("%s", szTmp);
// fflush(stdout);
}
#endif #endif
write(szTmp); write_a(szTmp);
} }
void ExLogger::log_w(int level, const wchar_t* fmt, va_list valist) 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; return;
wchar_t szTmp[4096] = { 0 }; wchar_t szTmp[4096] = { 0 };
int offset = 0; size_t offset = 0;
if (level == EX_LOG_LEVEL_ERROR) if (level == EX_LOG_LEVEL_ERROR)
{ {
@ -149,6 +160,8 @@ void ExLogger::log_w(int level, const wchar_t* fmt, va_list valist)
#ifdef EX_OS_WIN32 #ifdef EX_OS_WIN32
_vsnwprintf_s(szTmp+offset, 4096-offset, 4095-offset, fmt, valist); _vsnwprintf_s(szTmp+offset, 4096-offset, 4095-offset, fmt, valist);
if(to_console)
{
if (NULL != console_handle) if (NULL != console_handle)
{ {
wprintf_s(_T("%s"), szTmp); wprintf_s(_T("%s"), szTmp);
@ -156,18 +169,23 @@ void ExLogger::log_w(int level, const wchar_t* fmt, va_list valist)
} }
else else
{ {
if(debug_mode)
OutputDebugStringW(szTmp); OutputDebugStringW(szTmp);
} }
}
#else #else
vswprintf(szTmp+offset, 4095-offset, fmt, valist); vswprintf(szTmp+offset, 4095-offset, fmt, valist);
if(to_console)
{
wprintf(L"%ls", szTmp); wprintf(L"%ls", szTmp);
fflush(stdout); fflush(stdout);
}
#endif #endif
write(szTmp); write_w(szTmp);
} }
#define EX_PRINTF_X(fn, level) \ #define EX_PRINTF_XA(fn, level) \
void fn(const char* fmt, ...) \ void fn(const char* fmt, ...) \
{ \ { \
if(NULL == g_exlog) \ if(NULL == g_exlog) \
@ -179,7 +197,9 @@ void fn(const char* fmt, ...) \
va_start(valist, fmt); \ va_start(valist, fmt); \
g_exlog->log_a(level, fmt, valist); \ g_exlog->log_a(level, fmt, valist); \
va_end(valist); \ va_end(valist); \
} \ }
#define EX_PRINTF_XW(fn, level) \
void fn(const wchar_t* fmt, ...) \ void fn(const wchar_t* fmt, ...) \
{ \ { \
if(NULL == g_exlog) \ if(NULL == g_exlog) \
@ -193,11 +213,17 @@ void fn(const wchar_t* fmt, ...) \
va_end(valist); \ va_end(valist); \
} }
EX_PRINTF_X(ex_printf_d, EX_LOG_LEVEL_DEBUG) EX_PRINTF_XA(ex_printf_d, EX_LOG_LEVEL_DEBUG)
EX_PRINTF_X(ex_printf_v, EX_LOG_LEVEL_VERBOSE) EX_PRINTF_XA(ex_printf_v, EX_LOG_LEVEL_VERBOSE)
EX_PRINTF_X(ex_printf_i, EX_LOG_LEVEL_INFO) EX_PRINTF_XA(ex_printf_i, EX_LOG_LEVEL_INFO)
EX_PRINTF_X(ex_printf_w, EX_LOG_LEVEL_WARN) EX_PRINTF_XA(ex_printf_w, EX_LOG_LEVEL_WARN)
EX_PRINTF_X(ex_printf_e, EX_LOG_LEVEL_ERROR) 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 #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; unsigned int i = 0;
char szTmp[128] = { 0 }; char szTmp[128] = { 0 };
int _offset = 0; size_t _offset = 0;
while (offset < bin_size) while (offset < bin_size)
{ {
@ -529,7 +555,7 @@ bool ExLogFile::_backup_file()
} }
#endif // if 0 #endif // if 0
bool ExLogger::write(const char* buf) bool ExLogger::write_a(const char* buf)
{ {
if (NULL == m_file) if (NULL == m_file)
return false; return false;
@ -561,7 +587,7 @@ bool ExLogger::write(const char* buf)
return false; 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); 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); fwrite(szTime, lenTime, 1, m_file);
m_filesize += lenTime; m_filesize += lenTime;
fwrite(buf, len, 1, m_file); fwrite(buf, len, 1, m_file);
@ -573,11 +599,11 @@ bool ExLogger::write(const char* buf)
return _rotate_file(); return _rotate_file();
} }
bool ExLogger::write(const wchar_t* buf) bool ExLogger::write_w(const wchar_t* buf)
{ {
ex_astr _buf; ex_astr _buf;
ex_wstr2astr(buf, _buf, EX_CODEPAGE_UTF8); 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 ; 'replay-path' define the replay file location. if not set, default location
; to $INSTDIR%/data/replay/ ; 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 web-server-rpc=http://127.0.0.1:7190/rpc
[rpc] [rpc]
; Request by web server. `ip` should be the ip of core server, default to ; Request by web server. `bind-ip` should be the ip of core server. If
; 127.0.0.1 because web server and core server running at the same machine. ; web server and core server running at the same machine, it should be
;ip=127.0.0.1 ; 127.0.0.1
port=52080 bind-ip=127.0.0.1
bind-port=52080
[protocol-ssh] [protocol-ssh]
enabled=true enabled=true

View File

@ -121,12 +121,6 @@ int _app_main(int argc, wchar_t** argv)
if (!_process_cmd_line(argc, argv)) if (!_process_cmd_line(argc, argv))
return 1; return 1;
if (!g_env.init())
{
EXLOGE("[core] env init failed.\n");
return 1;
}
#ifdef EX_DEBUG #ifdef EX_DEBUG
EXLOG_LEVEL(EX_LOG_LEVEL_DEBUG); EXLOG_LEVEL(EX_LOG_LEVEL_DEBUG);
#endif #endif
@ -134,14 +128,30 @@ int _app_main(int argc, wchar_t** argv)
#ifdef EX_OS_WIN32 #ifdef EX_OS_WIN32
if (g_run_type == RUN_INSTALL_SRV) if (g_run_type == RUN_INSTALL_SRV)
{ {
if (!g_env.init(false))
{
EXLOGE("[core] env init failed.\n");
return 1;
}
return service_install(); return service_install();
} }
else if (g_run_type == RUN_UNINST_SRV) else if (g_run_type == RUN_UNINST_SRV)
{ {
if (!g_env.init(false))
{
EXLOGE("[core] env init failed.\n");
return 1;
}
return service_uninstall(); return service_uninstall();
} }
#endif #endif
if (!g_env.init(true))
{
EXLOGE("[core] env init failed.\n");
return 1;
}
if (!g_is_debug) if (!g_is_debug)
{ {
if (!_run_daemon()) if (!_run_daemon())

View File

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

View File

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

View File

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

View File

@ -8,7 +8,7 @@ TsEnv::TsEnv()
TsEnv::~TsEnv() TsEnv::~TsEnv()
{} {}
bool TsEnv::init(bool for_web) bool TsEnv::init(bool load_config)
{ {
EXLOG_LEVEL(EX_LOG_LEVEL_INFO); EXLOG_LEVEL(EX_LOG_LEVEL_INFO);
@ -17,7 +17,7 @@ bool TsEnv::init(bool for_web)
m_exec_path = m_exec_file; m_exec_path = m_exec_file;
ex_dirname(m_exec_path); ex_dirname(m_exec_path);
if (!for_web) if (!load_config)
return true; return true;
// check development flag file, if exists, run in development mode for trace and debug. // check development flag file, if exists, run in development mode for trace and debug.
@ -34,7 +34,7 @@ bool TsEnv::init(bool for_web)
ex_path_join(base_path, true, L"..", L"..", L"..", L"..", L"server", NULL); ex_path_join(base_path, true, L"..", L"..", L"..", L"..", L"server", NULL);
conf_file = base_path; 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; log_path = base_path;
ex_path_join(log_path, false, L"share", L"log", NULL); 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; m_www_path = base_path;
ex_path_join(m_www_path, false, L"www", NULL); 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())) if (!ex_is_file_exists(conf_file.c_str()))
{ {
EXLOGE("[tpweb] web.ini not found.\n"); EXLOGE("[tpweb] web.ini not found.\n");
@ -103,8 +76,6 @@ bool TsEnv::init(bool for_web)
ExIniSection* ps = cfg.GetDumySection(); ExIniSection* ps = cfg.GetDumySection();
if (!ps->GetStr(L"log_file", 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"tpweb.log", log_path.c_str()); EXLOG_FILE(L"tpweb.log", log_path.c_str());
} }
else 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'\'') if (log_file[ log_file.length() - 1 ] == L'"' || log_file[log_file.length() - 1] == L'\'')
log_file.erase(log_file.length() - 1, 1); log_file.erase(log_file.length() - 1, 1);
// ex_wstr log_path = log_file;
log_path = log_file; log_path = log_file;
ex_dirname(log_path); ex_dirname(log_path);
ex_wstr file_name; ex_wstr file_name;
@ -131,8 +101,5 @@ bool TsEnv::init(bool for_web)
EXLOG_LEVEL(log_level); EXLOG_LEVEL(log_level);
} }
// EXLOGI("==============================\n");
// EXLOGI("[tpweb] start...\n");
return true; return true;
} }

View File

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

View File

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

View File

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

View File

@ -7,6 +7,7 @@ import threading
import datetime import datetime
from eom_common.eomcore.logger import log from eom_common.eomcore.logger import log
from eom_common.eomcore import utils
# from .configs import app_cfg # from .configs import app_cfg
from .database.create import create_and_init from .database.create import create_and_init
from .database.upgrade import DatabaseUpgrade from .database.upgrade import DatabaseUpgrade
@ -59,7 +60,6 @@ class TPDatabase:
return False 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)) ret = self.is_table_exists('{}group'.format(self._table_prefix))
if ret is None or not ret: if ret is None or not ret:
# if ret is None or ret[0][0] == 0: # if ret is None or ret[0][0] == 0:
@ -123,6 +123,9 @@ class TPDatabase:
return ret return ret
def create_and_init(self, step_begin, step_end): def create_and_init(self, step_begin, step_end):
if self.db_source['type'] == self.DB_TYPE_SQLITE:
_folder = os.path.dirname(self.db_source['file'])
utils.make_dir(_folder)
if create_and_init(self, step_begin, step_end): if create_and_init(self, step_begin, step_end):
self.need_create = False self.need_create = False
return True return True
@ -239,7 +242,7 @@ class TPSqlitePool(TPDatabasePool):
try: try:
return sqlite3.connect(self._db_file) return sqlite3.connect(self._db_file)
except: 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 return None
def _do_query(self, conn, sql): def _do_query(self, conn, sql):

View File

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