forked from ben-abraham/raven-trader-pro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_instance.py
61 lines (52 loc) · 1.84 KB
/
app_instance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os.path, logging
from logging.handlers import TimedRotatingFileHandler
from util import *
LOG_STORAGE_PATH = "~/.raventrader/logs/raventrader.log"
class AppInstance:
settings = None
storage = None
wallet = None
server = None
@staticmethod
def setup_logging():
path = os.path.expanduser(LOG_STORAGE_PATH)
ensure_directory(os.path.dirname(path))
logger = logging.getLogger()
handler = TimedRotatingFileHandler(path, when='D', interval=1, backupCount=7)
fmt = '%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s'
formatter = logging.Formatter(fmt=fmt, datefmt='%m/%d/%Y %H:%M:%S')
handler.setFormatter(formatter)
handler.setLevel(logging.INFO)
# tee output to console as well
console = logging.StreamHandler()
console.setFormatter(formatter)
console.setLevel(logging.INFO)
logger.addHandler(console)
logger.addHandler(handler)
logger.setLevel(logging.INFO)
@staticmethod
def on_init():
AppInstance.storage = AppStorage()
AppInstance.wallet = WalletManager()
AppInstance.server = ServerConnection()
AppInstance.on_load()
@staticmethod
def on_load():
AppInstance.storage.on_load()
AppInstance.wallet.invalidate_all()
AppInstance.wallet.on_load()
#AppInstance.server.on_load()
check_path_registration(AppInstance.settings.protocol_enabled(), get_registration_program(), AppInstance.settings.protocol_path())
@staticmethod
def on_close():
AppInstance.wallet.on_close()
AppInstance.storage.on_close()
AppInstance.settings.on_close()
@staticmethod
def on_exit(error=None):
if error:
logging.error(error)
AppInstance.on_close()
from app_storage import AppStorage
from wallet_manager import WalletManager
from server_connection import ServerConnection