-
Notifications
You must be signed in to change notification settings - Fork 26
/
run.py
90 lines (59 loc) · 2.33 KB
/
run.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
""" Run the application.
Usually, all you have to do in here is:-
1) Initialise the logging package as you see fit (or not at all ;^)!
2) Set the 'EGG_PATH' variable to be a list of the directories that contain
your application's eggs.
3) Edit the 'run' function to do whatever you need to do to start your
application.
"""
# Standard library imports.
import logging
# Create a log file.
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler(file('acme_motd.log', 'w')))
logger.setLevel(logging.DEBUG)
# A list of the directories that contain the application's eggs (any directory
# not specified as an absolute path is treated as being relative to the current
# working directory).
EGG_PATH = ['eggs']
def run():
""" The function that starts your application. """
# Enthought library imports.
#
# We do the imports here in case the Enthought eggs are loaded dyanmically
# via the 'EGG_PATH'.
from envisage.api import Application, EggPluginManager
# Create a plugin manager that ignores all eggs except the ones that we
# need for this example.
plugin_manager = EggPluginManager(
include = [
'envisage.core', 'acme.motd', 'acme.motd.software_quotes'
]
)
# Create an application that uses the egg plugin manager to find its
# plugins.
application = Application(id='acme.motd', plugin_manager=plugin_manager)
# Run it!
return application.run()
###############################################################################
# Usually, there is no need to edit anything below here!
###############################################################################
# Standard library imports.
from pkg_resources import Environment, working_set
# Logging.
logger = logging.getLogger(__name__)
def main():
""" Run the application. """
# Find all additional eggs.
environment = Environment(EGG_PATH)
distributions, errors = working_set.find_plugins(environment)
if len(errors) > 0:
raise SystemError('cannot add eggs %s' % errors)
logger.debug('added eggs %s' % distributions)
# Add them to the working set.
map(working_set.add, distributions)
# Create and run the application.
return run()
if __name__ == '__main__':
main()
#### EOF ######################################################################