-
Notifications
You must be signed in to change notification settings - Fork 3
/
debug.py
71 lines (58 loc) · 2.21 KB
/
debug.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
62
63
64
65
66
67
68
69
70
71
##############################################################################
#
# Copyright (c) 2008 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Debug a Zope Application
$Id$
"""
from __future__ import print_function
__docformat__ = 'restructuredtext'
from zope.app.publication.zopepublication import ZopePublication
import os
import sys
import zdaemon.zdoptions
import zope.app.appsetup.appsetup
import zope.app.appsetup.product
import zope.event
import zope.processlifetime
def load_options(args=None):
if args is None:
args = sys.argv[1:]
options = zdaemon.zdoptions.ZDOptions()
options.schemadir = os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'schema')
options.realize(args)
if options.configroot is None:
options.usage("please specify a configuration file")
options = options.configroot
if options.path:
sys.path[:0] = [os.path.abspath(p) for p in options.path]
return options
def loadApplication(args=None):
options = load_options(args)
zope.app.appsetup.product.setProductConfigurations(
options.product_config)
zope.app.appsetup.config(options.site_definition)
db = zope.app.appsetup.appsetup.multi_database(options.databases)[0][0]
zope.event.notify(zope.processlifetime.DatabaseOpened(db))
return db
def main(args=None):
db = loadApplication(args)
if "PYTHONSTARTUP" in os.environ:
startup = os.environ["PYTHONSTARTUP"]
with open(startup) as s:
exec(compile(s.read(), startup, 'exec'))
sys.modules['__main__'].root = db.open().root()[ZopePublication.root_name]
print('The application root is known as `root`.')
os.environ["PYTHONINSPECT"] = "true"
if __name__ == '__main__':
main()