py.lib

John Y. 2019-01-20 Parent:8c951e942fee

7:15fa2da6627d Go to Latest

py.lib/pgAdmin4_server.py

+ Смена сервера с gevent на waitress + Организация членораздельного информирования в случае отсутствия модуля waitress

History
1 # coding: utf-8
2 # devel.a0fs.net: pgadmin.selfServer - v0.2 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 import os
14 import sys
16 try:
17 import waitress
18 except ImportError:
19 sys.stderr.write('\n ERROR: You need to install weitress module to you python instance\n\n')
20 sys.exit(1)
22 import logging
23 from logging.handlers import SysLogHandler
26 def prepLogger():
27 _format = 'lo.ad.pgadmin[%(process)d]: %(message)s'
28 _logHandler = SysLogHandler(address='/dev/log', facility='user')
29 _logHandler.setFormatter(logging.Formatter(_format))
30 logging.basicConfig(level=logging.INFO)
31 _log = logging.getLogger()
32 _log.handlers = [_logHandler,]
34 root = os.path.dirname(os.path.realpath(__file__))
35 if sys.path[0] != root:
36 sys.path.insert(0, root)
38 if sys.version_info[0] >= 3:
39 import builtins
40 else:
41 import __builtin__ as builtins
43 # Ensure the global server mode is set.
44 builtins.SERVER_MODE = True
46 import config
47 config.DATA_DIR = os.getenv('DATA_DIR') or config.DATA_DIR
48 config.SQLITE_PATH = os.getenv('SQLITE_PATH') or os.path.join(config.DATA_DIR, 'pgadmin4.db')
49 config.SESSION_DB_PATH = os.path.join(config.DATA_DIR, 'sessions')
50 config.STORAGE_DIR = os.path.join(config.DATA_DIR, 'storage')
51 config.TEST_SQLITE_PATH = os.path.join(config.DATA_DIR, 'test_pgadmin4.db')
52 config.LOG_FILE = os.path.join(config.DATA_DIR, 'pgadmin4.log')
54 # When running it as a WSGI application, directory for the configuration file
55 # must present.
56 if not os.path.exists(os.path.dirname(config.SQLITE_PATH)):
57 raise Exception(
58 """
59 Required configuration file is not present!
60 Please run setup.py first!"""
61 )
63 from pgAdmin4 import app as application
64 prepLogger()
65 log = logging.getLogger()
67 waitress.serve(application, host='0.0.0.0', port=44000)