Commit e463ae37 authored by 广宏伟's avatar 广宏伟

Merged in dev (pull request #115)

[Update] 优化代码结构
parents 0e93727f 881cfea8
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
from . import logger
from .app import Coco from .app import Coco
...@@ -12,10 +12,9 @@ import signal ...@@ -12,10 +12,9 @@ import signal
from .config import config from .config import config
from .sshd import SSHServer from .sshd import SSHServer
from .httpd import HttpServer from .httpd import HttpServer
from .logger import create_logger
from .tasks import TaskHandler from .tasks import TaskHandler
from .utils import get_logger, ugettext as _, ignore_error from .utils import get_logger, ugettext as _, ignore_error
from .ctx import app_service from .service import app_service
from .recorder import get_replay_recorder from .recorder import get_replay_recorder
from .session import Session from .session import Session
from .models import Connection from .models import Connection
...@@ -56,9 +55,6 @@ class Coco: ...@@ -56,9 +55,6 @@ class Coco:
self._task_handler = TaskHandler() self._task_handler = TaskHandler()
return self._task_handler return self._task_handler
def make_logger(self):
create_logger()
@staticmethod @staticmethod
def load_extra_conf_from_server(): def load_extra_conf_from_server():
configs = app_service.load_config_from_server() configs = app_service.load_config_from_server()
...@@ -68,8 +64,6 @@ class Coco: ...@@ -68,8 +64,6 @@ class Coco:
config.update(configs) config.update(configs)
def bootstrap(self): def bootstrap(self):
self.make_logger()
# app_service.initial()
self.load_extra_conf_from_server() self.load_extra_conf_from_server()
self.keep_heartbeat() self.keep_heartbeat()
self.monitor_sessions() self.monitor_sessions()
......
...@@ -10,7 +10,7 @@ import telnetlib ...@@ -10,7 +10,7 @@ import telnetlib
import paramiko import paramiko
from paramiko.ssh_exception import SSHException from paramiko.ssh_exception import SSHException
from .ctx import app_service from .service import app_service
from .config import config from .config import config
from .utils import get_logger, get_private_key_fingerprint from .utils import get_logger, get_private_key_fingerprint
......
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
from werkzeug.local import LocalProxy from werkzeug.local import LocalProxy
from functools import partial from functools import partial
from .config import config
from jms.service import AppService
stack = {} stack = {}
__db_sessions = [] __db_sessions = []
...@@ -18,7 +15,4 @@ def _find(name): ...@@ -18,7 +15,4 @@ def _find(name):
raise ValueError("Not found in stack: {}".format(name)) raise ValueError("Not found in stack: {}".format(name))
app_service = AppService(config)
app_service.initial()
current_app = LocalProxy(partial(_find, 'current_app')) current_app = LocalProxy(partial(_find, 'current_app'))
# app_service = LocalProxy(partial(_find, 'app_service'))
...@@ -4,7 +4,7 @@ from functools import wraps ...@@ -4,7 +4,7 @@ from functools import wraps
from flask import request, abort, redirect from flask import request, abort, redirect
from ..ctx import app_service from ..service import app_service
def login_required(func): def login_required(func):
......
...@@ -9,7 +9,7 @@ from flask import Flask, request ...@@ -9,7 +9,7 @@ from flask import Flask, request
from ..models import Connection, WSProxy from ..models import Connection, WSProxy
from ..proxy import ProxyServer from ..proxy import ProxyServer
from ..utils import get_logger from ..utils import get_logger
from ..ctx import app_service from ..service import app_service
from ..config import config from ..config import config
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(os.path.dirname(__file__))
......
...@@ -9,7 +9,7 @@ from flask import request ...@@ -9,7 +9,7 @@ from flask import request
from ..models import Connection, WSProxy from ..models import Connection, WSProxy
from ..proxy import ProxyServer from ..proxy import ProxyServer
from ..utils import get_logger from ..utils import get_logger
from ..ctx import app_service from ..service import app_service
from .base import BaseNamespace from .base import BaseNamespace
from .utils import get_cached_volume from .utils import get_cached_volume
......
...@@ -12,7 +12,7 @@ from .utils import wrap_with_line_feed as wr, wrap_with_title as title, \ ...@@ -12,7 +12,7 @@ from .utils import wrap_with_line_feed as wr, wrap_with_title as title, \
wrap_with_warning as warning, is_obj_attr_has, is_obj_attr_eq, \ wrap_with_warning as warning, is_obj_attr_has, is_obj_attr_eq, \
sort_assets, ugettext as _, get_logger, net_input, format_with_zh, \ sort_assets, ugettext as _, get_logger, net_input, format_with_zh, \
item_max_length, size_of_str_with_zh, switch_lang item_max_length, size_of_str_with_zh, switch_lang
from .ctx import app_service from .service import app_service
from .proxy import ProxyServer from .proxy import ProxyServer
logger = get_logger(__file__) logger = get_logger(__file__)
......
...@@ -8,7 +8,7 @@ from collections import Iterable ...@@ -8,7 +8,7 @@ from collections import Iterable
from .utils import get_logger from .utils import get_logger
from .config import config from .config import config
from .ctx import app_service from .service import app_service
logger = get_logger(__file__) logger = get_logger(__file__)
......
...@@ -57,9 +57,9 @@ def create_logger(): ...@@ -57,9 +57,9 @@ def create_logger():
# 'engineio': main_setting, # 'engineio': main_setting,
} }
) )
dictConfig(config) dictConfig(config)
logger = logging.getLogger() logger = logging.getLogger()
return logger return logger
create_logger()
...@@ -8,7 +8,7 @@ import time ...@@ -8,7 +8,7 @@ import time
from .session import Session from .session import Session
from .models import Server, TelnetServer from .models import Server, TelnetServer
from .connection import SSHConnection, TelnetConnection from .connection import SSHConnection, TelnetConnection
from .ctx import app_service from .service import app_service
from .config import config from .config import config
from .utils import wrap_with_line_feed as wr, wrap_with_warning as warning, \ from .utils import wrap_with_line_feed as wr, wrap_with_warning as warning, \
get_logger, net_input, ugettext as _ get_logger, net_input, ugettext as _
......
...@@ -15,7 +15,7 @@ import jms_storage ...@@ -15,7 +15,7 @@ import jms_storage
from .config import config from .config import config
from .utils import get_logger, Singleton from .utils import get_logger, Singleton
from .struct import MemoryQueue from .struct import MemoryQueue
from .ctx import app_service from .service import app_service
logger = get_logger(__file__) logger = get_logger(__file__)
BUF_SIZE = 1024 BUF_SIZE = 1024
......
...@@ -8,7 +8,7 @@ import time ...@@ -8,7 +8,7 @@ import time
from .utils import get_logger, wrap_with_warning as warn, \ from .utils import get_logger, wrap_with_warning as warn, \
wrap_with_line_feed as wr, ugettext as _, ignore_error wrap_with_line_feed as wr, ugettext as _, ignore_error
from .ctx import app_service from .service import app_service
from .struct import SelectEvent from .struct import SelectEvent
from .recorder import get_recorder from .recorder import get_recorder
......
...@@ -9,7 +9,7 @@ from paramiko.sftp import SFTP_PERMISSION_DENIED, SFTP_NO_SUCH_FILE, \ ...@@ -9,7 +9,7 @@ from paramiko.sftp import SFTP_PERMISSION_DENIED, SFTP_NO_SUCH_FILE, \
from coco.utils import get_logger from coco.utils import get_logger
from .config import config from .config import config
from .ctx import app_service from .service import app_service
from .connection import SSHConnection from .connection import SSHConnection
CURRENT_DIR = os.path.dirname(__file__) CURRENT_DIR = os.path.dirname(__file__)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
from .ctx import app_service from .service import app_service
from .utils import get_logger from .utils import get_logger
from .session import Session from .session import Session
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment