py.lib

John Y. 2019-01-13 Parent:f5082aa9fe60 Child:15fa2da6627d

6:8c951e942fee Go to Latest

py.lib/pgAdmin4_server.py

+ Управляем ещё и логами

History
1 # coding: utf-8
2 # devel.a0fs.net: pgadmin.selfServerAsync - v0.1 by awgur $
4 ##########################################################################
5 #
6 # pgAdmin 4 - PostgreSQL Tools
7 #
8 # Copyright (C) 2013 - 2018, The pgAdmin Development Team
9 # This software is released under the PostgreSQL Licence
10 #
11 ##########################################################################
13 from gevent import monkey; monkey.patch_all()
14 from gevent.pywsgi import WSGIServer
15 import os
16 import sys
17 import logging
18 from logging.handlers import SysLogHandler
21 def prepLogger():
22 _format = 'lo.ad.pgadmin[%(process)d]: %(message)s'
23 _logHandler = SysLogHandler(address='/dev/log', facility='user')
24 _logHandler.setFormatter(logging.Formatter(_format))
25 logging.basicConfig(level=logging.INFO)
26 _log = logging.getLogger()
27 _log.handlers = [_logHandler,]
29 root = os.path.dirname(os.path.realpath(__file__))
30 if sys.path[0] != root:
31 sys.path.insert(0, root)
33 if sys.version_info[0] >= 3:
34 import builtins
35 else:
36 import __builtin__ as builtins
38 # Ensure the global server mode is set.
39 builtins.SERVER_MODE = True
41 import config
42 # Monkey Path Dumy pgAdmin CONFIG
43 config.DATA_DIR = os.getenv('DATA_DIR') or config.DATA_DIR
44 config.SQLITE_PATH = os.getenv('SQLITE_PATH') or os.path.join(config.DATA_DIR, 'pgadmin4.db')
45 config.SESSION_DB_PATH = os.path.join(config.DATA_DIR, 'sessions')
46 config.STORAGE_DIR = os.path.join(config.DATA_DIR, 'storage')
47 config.TEST_SQLITE_PATH = os.path.join(config.DATA_DIR, 'test_pgadmin4.db')
48 config.LOG_FILE = os.path.join(config.DATA_DIR, 'pgadmin4.log')
51 # When running it as a WSGI application, directory for the configuration file
52 # must present.
53 if not os.path.exists(os.path.dirname(config.SQLITE_PATH)):
54 raise Exception(
55 """
56 Required configuration file is not present!
57 Please run setup.py first!"""
58 )
60 from pgAdmin4 import app as application
61 prepLogger()
62 log = logging.getLogger()
64 WSGIServer(('0.0.0.0', 44000), application, log=log, error_log=log).serve_forever()