py.lib

John Y. 2019-01-13 Parent:cb88c7d80d6f Child:8c951e942fee

5:f5082aa9fe60 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')
50 # When running it as a WSGI application, directory for the configuration file
51 # must present.
52 if not os.path.exists(os.path.dirname(config.SQLITE_PATH)):
53 raise Exception(
54 """
55 Required configuration file is not present!
56 Please run setup.py first!"""
57 )
59 from pgAdmin4 import app as application
60 prepLogger()
61 log = logging.getLogger()
63 WSGIServer(('0.0.0.0', 44000), application, log=log, error_log=log).serve_forever()