-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
87 lines (62 loc) · 2.05 KB
/
main.py
File metadata and controls
87 lines (62 loc) · 2.05 KB
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import logging
import os
import re
import sys
import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
# use zipped gaeo
try:
import os
if os.path.exists('gaeo.zip'):
import sys
sys.path.insert(0, 'gaeo.zip')
except:
print 'use normal gaeo folder'
import gaeo
from gaeo.dispatch import router
def initRoutes():
r = router.Router()
# TODO: add routes here
r.connect('/:controller/:action/:id')
r.connect('/:controller/:action/:id.:format')
def initPlugins():
"""
Initialize the installed plugins
"""
plugins_root = os.path.join(os.path.dirname(__file__), 'plugins')
if os.path.exists(plugins_root):
plugins = os.listdir(plugins_root)
for plugin in plugins:
if not re.match('^__|^\.', plugin):
try:
exec 'from plugins import %s' % plugin
except ImportError:
logging.error('Unable to import %s' % plugin)
except SyntaxError:
logging.error('Unable to import name %s' % plugin)
def main():
# add the project's directory to the import path list.
sys.path.append(os.path.dirname(__file__))
sys.path.append(os.path.join(os.path.dirname(__file__),
'application'))
sys.path.append(os.path.join(os.path.dirname(__file__), 'libs'))
# get the gaeo's config (singleton)
config = gaeo.Config()
# setup the templates' location
config.application_dir = os.path.join(os.path.dirname(__file__),
'application')
config.messages_dir = os.path.join(config.application_dir,
'messages')
config.template_dir = os.path.join(config.application_dir,
'templates')
initRoutes()
# initialize the installed plugins
initPlugins()
app = webapp.WSGIApplication([(r'.*', gaeo.MainHandler)],
debug=True)
run_wsgi_app(app)
if __name__ == '__main__':
main()