File: trytond

package info (click to toggle)
tryton-server 7.0.40-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,748 kB
  • sloc: python: 53,502; xml: 5,194; sh: 803; sql: 217; makefile: 28
file content (92 lines) | stat: -rwxr-xr-x 2,906 bytes parent folder | download | duplicates (2)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
# PYTHON_ARGCOMPLETE_OK
# This file is part of Tryton.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import glob
import logging
import os
import sys
import threading

try:
    import argcomplete
except ImportError:
    argcomplete = None

DIR = os.path.abspath(os.path.normpath(os.path.join(__file__,
    '..', '..', 'trytond')))
if os.path.isdir(DIR):
    sys.path.insert(0, os.path.dirname(DIR))

import trytond.commandline as commandline
from trytond.config import config, split_netloc

parser = commandline.get_parser_daemon()
if argcomplete:
    argcomplete.autocomplete(parser)
options = parser.parse_args()
commandline.config_log(options)
extra_files = config.update_etc(options.configfile)

if options.coroutine:
    # Monkey patching must be done before importing
    from gevent import monkey
    monkey.patch_all()

from trytond.modules import get_module_info, get_modules
from trytond.pool import Pool
# Import trytond things after it is configured
from trytond.wsgi import app

with commandline.pidfile(options):
    Pool.start()
    threads = []
    for name in options.database_names:
        thread = threading.Thread(target=Pool(name).init)
        thread.start()
        threads.append(thread)
    for thread in threads:
        thread.join()
    hostname, port = split_netloc(config.get('web', 'listen'))
    certificate = config.get('ssl', 'certificate')
    try:
        if config.getboolean('ssl', 'certificate'):
            certificate = None
    except ValueError:
        pass
    privatekey = config.get('ssl', 'privatekey')
    try:
        if config.getboolean('ssl', 'privatekey'):
            privatekey = None
    except ValueError:
        pass
    if certificate or privatekey:
        from werkzeug.serving import load_ssl_context
        ssl_args = dict(
            ssl_context=load_ssl_context(certificate, privatekey))
    else:
        ssl_args = {}
    if options.dev and not options.coroutine:
        for module in get_modules():
            info = get_module_info(module)
            for ext in ['xml',
                    'fodt', 'odt', 'fodp', 'odp', 'fods', 'ods', 'fodg', 'odg',
                    'txt', 'html', 'xhtml']:
                path = os.path.join(info['directory'], '**', '*.' + ext)
                extra_files.extend(glob.glob(path, recursive=True))
    app.dev = options.dev

    if options.coroutine:
        from gevent.pywsgi import WSGIServer
        logger = logging.getLogger('gevent')
        WSGIServer((hostname, port), app,
            log=logger,
            error_log=logger,
            **ssl_args).serve_forever()
    else:
        from werkzeug.serving import run_simple
        run_simple(hostname, port, app,
            threaded=True,
            extra_files=extra_files,
            use_reloader=options.dev,
            **ssl_args)